<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Image Generation & Editing powered by Google DeepMind Gemini 2.0 Flash</title>
<style>
/* Reset & base */
* {
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
background: #121212;
color: #eee;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background: #1a1a1a;
padding: 1rem 2rem;
text-align: center;
border-bottom: 1px solid #333;
}
header h1 {
margin: 0;
font-weight: 700;
color: #4fc3f7;
letter-spacing: 1px;
}
main {
flex: 1;
padding: 2rem;
max-width: 900px;
margin: 0 auto;
width: 100%;
}
form {
background: #222;
padding: 1.5rem 2rem;
border-radius: 8px;
box-shadow: 0 0 10px #0bc5f8a0;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
color: #80d8ff;
}
textarea,
input[type="text"],
select {
width: 100%;
padding: 0.75rem 1rem;
font-size: 1rem;
border-radius: 5px;
border: none;
margin-bottom: 1rem;
outline: none;
resize: vertical;
background: #333;
color: #eee;
font-family: inherit;
transition: background-color 0.3s;
}
textarea:focus,
input[type="text"]:focus,
select:focus {
background-color: #444;
}
button {
background: #4fc3f7;
color: #121212;
border: none;
padding: 0.75rem 2rem;
font-size: 1.1rem;
font-weight: 700;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.2s ease-in-out;
}
button:hover:not(:disabled) {
background: #039be5;
}
button:disabled {
background: #555;
cursor: not-allowed;
}
section#results {
margin-top: 2rem;
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
justify-content: center;
}
section#results img {
max-width: 300px;
max-height: 300px;
border-radius: 12px;
box-shadow: 0 0 15px #0bc5f8a0;
object-fit: contain;
background: #000;
}
footer {
text-align: center;
padding: 1rem 2rem;
background: #1a1a1a;
font-size: 0.9rem;
color: #666;
user-select: none;
}
.info {
margin-bottom: 1rem;
color: #bbb;
font-size: 0.95rem;
max-width: 600px;
margin-left: auto;
margin-right: auto;
line-height: 1.4;
}
.nsfw-warning {
color: #ff6e40;
font-weight: 700;
margin-bottom: 1rem;
text-align: center;
font-size: 1rem;
}
</style>
</head>
<body>
<header>
<h1>Google DeepMind Gemini 2.0 Flash<br />Image Generation & Editing</h1>
</header>
<main>
<div class="info">
<p>
Build your own unlimited image generation apps with the Gemini API!
Generate and edit images by simply writing your prompt. Supports NSFW images.
</p>
</div>
<form id="imageForm" autocomplete="off" spellcheck="false">
<label for="prompt">Enter your image prompt:</label>
<textarea id="prompt" rows="4" placeholder="Describe the image you want to generate or edit..." required></textarea>
<label for="mode">Select mode:</label>
<select id="mode" required>
<option value="generate" selected>Generate Image</option>
<option value="edit">Edit Image</option>
</select>
<div id="editOptions" style="display:none; margin-bottom:1rem;">
<label for="imageURL">Image URL to edit:</label>
<input type="text" id="imageURL" placeholder="Paste the image URL here for editing" />
</div>
<label>
<input type="checkbox" id="allowNSFW" />
Allow generation of NSFW images
</label>
<button type="submit" id="submitBtn">Generate</button>
</form>
<section id="results" aria-live="polite" aria-atomic="true" aria-label="Generated images"></section>
</main>
<footer>
© 2024 Google DeepMind Gemini 2.0 Flash Powered Image Generator
</footer>
<script>
const form = document.getElementById('imageForm');
const modeSelect = document.getElementById('mode');
const editOptions = document.getElementById('editOptions');
const resultsSection = document.getElementById('results');
const submitBtn = document.getElementById('submitBtn');
const promptInput = document.getElementById('prompt');
const imageURLInput = document.getElementById('imageURL');
const allowNSFWInput = document.getElementById('allowNSFW');
// Show/hide image URL input based on mode
modeSelect.addEventListener('change', () => {
if (modeSelect.value === 'edit') {
editOptions.style.display = 'block';
imageURLInput.required = true;
submitBtn.textContent = 'Edit Image';
} else {
editOptions.style.display = 'none';
imageURLInput.required = false;
submitBtn.textContent = 'Generate';
}
});
/**
* Mock function simulating request to Gemini API.
* As no real public API details exist, this simulates image generation/editing.
* The real implementation would POST to Gemini API endpoint with prompt etc.
*
* @param {Object} options
* @param {string} options.prompt - The text prompt describing the image.
* @param {string} options.mode - "generate" or "edit".
* @param {string} [options.imageURL] - URL of image to edit (if mode=edit).
* @param {boolean} options.allowNSFW - if NSFW images are allowed.
* @returns {Promise<string[]>} - A promise resolving to array of image URLs.
*/
async function callGeminiAPI({ prompt, mode, imageURL, allowNSFW }) {
// This is a mock implementation.
// In a real scenario, you would:
// - Use fetch() to call Gemini API endpoint,
// - Include authentication headers and the JSON payload,
// - Handle errors and parse response for image URLs.
// To simulate generation time:
await new Promise(resolve => setTimeout(resolve, 2000));
// For demonstration, return placeholder images with overlayed prompt text.
// We'll use a public image placeholder service combined with prompt text.
// Sanitize prompt for URL (simple encoding)
const encodedPrompt = encodeURIComponent(prompt);
// Generate 3 images for demo
const dummyImages = [];
for (let i = 1; i <= 3; i++) {
// Differentiate generate/edit with distinct backgrounds
const bgColor = mode === 'generate' ? '0077cc' : 'cc7700';
const text = mode === 'generate' ? `Gen: ${prompt}` : `Edit: ${prompt}`;
const nsfwTag = allowNSFW ? ' (NSFW Allowed)' : '';
// Using dummyimage.com service to create placeholder images with text
const url = `https://dummyimage.com/600x400/${bgColor}/fff.png&text=${encodeURIComponent(text + nsfwTag + ` [${i}]`)}`;
dummyImages.push(url);
}
// Return the dummy URLs as if they were generated images
return dummyImages;
}
function clearResults() {
resultsSection.innerHTML = '';
}
function displayImages(imageUrls) {
clearResults();
imageUrls.forEach(url => {
const img = document.createElement('img');
img.src = url;
img.alt = 'Generated image based on your prompt';
img.loading = 'lazy';
resultsSection.appendChild(img);
});
}
form.addEventListener('submit', async e => {
e.preventDefault();
submitBtn.disabled = true;
submitBtn.textContent = modeSelect.value === 'edit' ? 'Editing...' : 'Generating...';
const prompt = promptInput.value.trim();
const mode = modeSelect.value;
const imageURL = imageURLInput.value.trim();
const allowNSFW = allowNSFWInput.checked;
// Basic validation
if (prompt.length === 0) {
alert('Please enter a prompt describing the image.');
submitBtn.disabled = false;
submitBtn.textContent = mode === 'edit' ? 'Edit Image' : 'Generate';
return;
}
if (mode === 'edit' && imageURL.length === 0) {
alert('Please provide the image URL to edit.');
submitBtn.disabled = false;
submitBtn.textContent = 'Edit Image';
return;
}
try {
const images = await callGeminiAPI({ prompt, mode, imageURL, allowNSFW });
if (!images || images.length === 0) {
resultsSection.textContent = 'No images generated.';
} else {
displayImages(images);
}
} catch (error) {
console.error('Error generating images:', error);
resultsSection.textContent = 'An error occurred while generating images.';
} finally {
submitBtn.disabled = false;
submitBtn.textContent = mode === 'edit' ? 'Edit Image' : 'Generate';
}
});
</script>
</body>
</html>