html Copy code
<!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 and 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: #0f62fe;
padding: 1rem 2rem;
text-align: center;
font-size: 1.8rem;
font-weight: 700;
letter-spacing: 1.5px;
user-select: none;
color: #fff;
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
main {
flex-grow: 1;
max-width: 900px;
margin: 2rem auto;
padding: 0 1rem;
display: flex;
flex-direction: column;
gap: 2rem;
}
.section {
background: #1e1e1e;
border-radius: 10px;
padding: 1.5rem;
box-shadow: 0 3px 12px rgba(0,0,0,0.5);
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
font-size: 1.1rem;
color: #a0a0a0;
}
input[type="text"],
textarea {
width: 100%;
padding: 0.7rem 1rem;
font-size: 1rem;
border-radius: 6px;
border: none;
outline: none;
resize: vertical;
background: #252525;
color: #eee;
transition: background-color 0.3s ease;
}
input[type="text"]:focus,
textarea:focus {
background: #333333;
}
input[type="file"] {
color: #eee;
background: #252525;
padding: 0.6rem;
border-radius: 6px;
border: none;
cursor: pointer;
width: 100%;
}
button {
background: #0f62fe;
border: none;
color: #fff;
font-weight: 700;
font-size: 1.1rem;
padding: 0.75rem 2rem;
cursor: pointer;
border-radius: 8px;
transition: background-color 0.3s ease;
margin-top: 1rem;
user-select: none;
display: inline-flex;
align-items: center;
gap: 0.7rem;
}
button:disabled {
background: #3a3a3a;
cursor: not-allowed;
}
button:hover:not(:disabled) {
background: #005fff;
}
.output {
margin-top: 1rem;
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
justify-content: center;
}
.output img {
max-width: 100%;
max-height: 400px;
border-radius: 10px;
box-shadow: 0 4px 16px rgba(15, 98, 254, 0.7);
user-select: none;
}
.nsfw-warning {
color: #ff4d4d;
font-weight: 600;
font-size: 1.1rem;
margin-top: 0.5rem;
text-align: center;
}
footer {
text-align: center;
padding: 1rem 2rem;
background: #0f62fe;
color: #eee;
font-size: 0.9rem;
user-select: none;
box-shadow: 0 -2px 8px rgba(0,0,0,0.3);
}
/* Responsive */
@media (max-width: 600px) {
button {
width: 100%;
justify-content: center;
}
.output {
flex-direction: column;
}
}
</style>
</head>
<body>
<header>
Image Generation & Editing powered by Google DeepMind Gemini 2.0 Flash
</header>
<main>
<section class="section" aria-labelledby="gen-edit-title">
<h2 id="gen-edit-title" style="color:#0f62fe; text-align:center; user-select:none;">
Build Your Own Image Generation & Editing Apps with the Gemini API
</h2>
<form id="imageForm" aria-describedby="instructions" novalidate>
<p id="instructions" style="color:#bbb; font-style: italic; text-align:center; margin-bottom:1.5rem;">
Unlimited image creation & editing. Supports NSFW content. Write your prompt and optionally upload an image.
</p>
<label for="promptInput">Your Image Prompt</label>
<textarea
id="promptInput"
name="prompt"
rows="3"
placeholder="Describe what you want to generate or edit..."
required
aria-required="true"
autocomplete="off"
></textarea>
<label for="imageUpload">Upload an image (optional) for editing</label>
<input type="file" id="imageUpload" name="image" accept="image/*" aria-describedby="imageHelp" />
<div id="imageHelp" style="font-size:0.9rem; color:#666; margin-top:0.3rem;">
Uploading an image enables editing mode — if left empty, a new image will be generated.
</div>
<label for="nsfwToggle" style="margin-top:1rem; font-weight:600; display: flex; align-items: center; gap:0.6rem;">
<input type="checkbox" id="nsfwToggle" name="nsfw" aria-describedby="nsfwDesc" />
Allow NSFW Images
</label>
<div id="nsfwDesc" style="font-size:0.9rem; color:#ff4d4d; margin-top:0.2rem;">
Enable this to allow generation of NSFW content. Use responsibly.
</div>
<button type="submit" id="generateButton" aria-live="polite" aria-busy="false">
Generate Image
<svg id="spinner" style="display:none;" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24" stroke="#fff">
<circle cx="12" cy="12" r="10" stroke-opacity="0.2" stroke-width="4"/>
<path d="M22 12a10 10 0 0 1-10 10" stroke-width="4" stroke-linecap="round"/>
</svg>
</button>
</form>
<div id="resultArea" aria-live="polite" aria-atomic="true"></div>
</section>
</main>
<footer>
© 2024 Powered by Google DeepMind Gemini 2.0 Flash API — Unlimited Image Generation & Editing
</footer>
<script>
// Simulate interaction with Gemini API
// NOTE: This is a mock implementation. Replace with real API integration.
const form = document.getElementById('imageForm');
const promptInput = document.getElementById('promptInput');
const imageUpload = document.getElementById('imageUpload');
const nsfwToggle = document.getElementById('nsfwToggle');
const generateButton = document.getElementById('generateButton');
const spinner = document.getElementById('spinner');
const resultArea = document.getElementById('resultArea');
let abortController = null;
form.addEventListener('submit', async (e) => {
e.preventDefault();
// Reset result area
resultArea.innerHTML = '';
const prompt = promptInput.value.trim();
if (!prompt) {
alert('Please enter a prompt to generate or edit an image.');
promptInput.focus();
return;
}
// Disable UI during generation
generateButton.disabled = true;
generateButton.setAttribute('aria-busy', 'true');
spinner.style.display = 'inline-block';
// Read image file if uploaded
let imageDataUrl = null;
if (imageUpload.files.length > 0) {
try {
imageDataUrl = await readFileAsDataURL(imageUpload.files[0]);
} catch (err) {
alert('Failed to read uploaded image.');
console.error(err);
generateButton.disabled = false;
generateButton.setAttribute('aria-busy', 'false');
spinner.style.display = 'none';
return;
}
}
// Prepare payload to Gemini API (mock)
const payload = {
prompt,
nsfw: nsfwToggle.checked,
image: imageDataUrl, // null if no image uploaded
};
try {
// Simulate network delay & processing
const generatedImages = await mockGeminiApiGenerate(payload);
displayImages(generatedImages, payload.nsfw);
} catch (err) {
alert('An error occurred while generating images. Please try again.');
console.error(err);
} finally {
generateButton.disabled = false;
generateButton.setAttribute('aria-busy', 'false');
spinner.style.display = 'none';
}
});
function readFileAsDataURL(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
reader.readAsDataURL(file);
});
}
function displayImages(images, nsfwEnabled) {
if (!images || images.length === 0) {
resultArea.innerHTML = '<p style="color:#ff5555; text-align:center;">No images were generated.</p>';
return;
}
const container = document.createElement('div');
container.className = 'output';
images.forEach(({ url, nsfw }) => {
const wrapper = document.createElement('div');
wrapper.style.position = 'relative';
const img = document.createElement('img');
img.src = url;
img.alt = 'Generated image from Gemini 2.0 Flash';
img.loading = 'lazy';
wrapper.appendChild(img);
if (nsfw && nsfwEnabled) {
const warning = document.createElement('div');
warning.textContent = '⚠️ NSFW Image';
warning.className = 'nsfw-warning';
warning.style.position = 'absolute';
warning.style.bottom = '8px';
warning.style.left = '8px';
warning.style.background = 'rgba(255, 77, 77, 0.85)';
warning.style.color = '#fff';
warning.style.padding = '3px 8px';
warning.style.borderRadius = '6px';
warning.style.fontSize = '0.9rem';
wrapper.appendChild(warning);
}
container.appendChild(wrapper);
});
resultArea.appendChild(container);
}
// Mock the Gemini API response
function mockGeminiApiGenerate({ prompt, nsfw, image }) {
return new Promise((resolve) => {
// Fake images URLs, in real case you'd POST to Gemini API and get back URLs or blobs
// For "editing" mode (image provided), append modifications on top
// For "generate" mode (no image), create brand new images
// Using https://picsum.photos/ for placeholders
setTimeout(() => {
const results = [];
// Generate 3 images for example
for (let i = 0; i < 3; i++) {
let baseUrl = 'https://picsum.photos/600/400?random=' + Math.floor(Math.random() * 1000 + i*100);
if (image) {
// Simulate "edited" image by overlaying prompt length in param and toggling hue using CSS filter in img element
// Instead of server side, we just vary the url a bit
baseUrl += '&edited=1&promptLen=' + prompt.length;
}
// NSFW flag randomly for demonstration if nsfw allowed and prompt contains certain keywords
const promptLower = prompt.toLowerCase();
const containsNSFWKeyword = ['nsfw', 'nude', 'erotic', 'explicit', 'sensual'].some(word => promptLower.includes(word));
const isNSFWImage = nsfw && containsNSFWKeyword && Math.random() > 0.4;
results.push({
url: baseUrl,
nsfw: isNSFWImage,
});
}
resolve(results);
}, 2500);
});
}
</script>
</body>
</html>