9afe6bce7b
- Extract styles.css from inline <style> in flux-index.html - Add image size selector with 9 preset aspect ratios (standard + XL) - Add clear (✕) button in prompt input field - Pass width/height to Flux pipeline API endpoint
137 lines
4.5 KiB
HTML
137 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Flux Image Generator</title>
|
|
<link rel="stylesheet" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<h1>Flux Image Generator</h1>
|
|
<p class="subtitle">Powered by flux-schnell</p>
|
|
|
|
<div class="config">
|
|
<label for="api-url">API URL:</label>
|
|
<input id="api-url" value="http://192.168.2.154:5005/v1/images/generations" />
|
|
</div>
|
|
|
|
<div class="config">
|
|
<label for="size-select">Size:</label>
|
|
<select id="size-select">
|
|
<option value="1024x1024">1024x1024 (1:1)</option>
|
|
<option value="1920x1088">1920x1088 (16:9)</option>
|
|
<option value="1088x1920">1088x1920 (9:16)</option>
|
|
<option value="1376x1024">1376x1024 (4:3)</option>
|
|
<option value="1024x1376">1024x1376 (3:4)</option>
|
|
<option value="1536x1024">1536x1024 (3:2)</option>
|
|
<option value="1024x1536">1024x1536 (2:3)</option>
|
|
<option value="2048x2048">2048x2048 (1:1 XL)</option>
|
|
<option value="2048x1152">2048x1152 (16:9 XL)</option>
|
|
<option value="1152x2048">1152x2048 (9:16 XL)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="input-area">
|
|
<div class="prompt-wrapper">
|
|
<input id="prompt" type="text" placeholder="Describe the image you want to create..." autofocus />
|
|
<button id="clear-btn" class="clear-btn" title="Clear">✕</button>
|
|
</div>
|
|
<button id="generate-btn">Generate</button>
|
|
</div>
|
|
|
|
<p class="status" id="status"></p>
|
|
|
|
<div class="result-area">
|
|
<div id="image-container">
|
|
<img id="result-image" alt="Generated image" />
|
|
<a id="download-btn" download="flux-image.png">⬇ Download PNG</a>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const promptInput = document.getElementById('prompt');
|
|
const clearBtn = document.getElementById('clear-btn');
|
|
const sizeSelect = document.getElementById('size-select');
|
|
const generateBtn = document.getElementById('generate-btn');
|
|
const apiInput = document.getElementById('api-url');
|
|
const statusEl = document.getElementById('status');
|
|
const imageContainer = document.getElementById('image-container');
|
|
const resultImage = document.getElementById('result-image');
|
|
const downloadBtn = document.getElementById('download-btn');
|
|
|
|
function setStatus(msg, isError = false) {
|
|
statusEl.innerHTML = msg;
|
|
statusEl.className = 'status' + (isError ? ' error' : '');
|
|
}
|
|
|
|
async function generate() {
|
|
const prompt = promptInput.value.trim();
|
|
if (!prompt) {
|
|
setStatus('Please enter a prompt.', true);
|
|
return;
|
|
}
|
|
|
|
const apiUrl = apiInput.value.trim();
|
|
if (!apiUrl) {
|
|
setStatus('Please enter an API URL.', true);
|
|
return;
|
|
}
|
|
|
|
generateBtn.disabled = true;
|
|
generateBtn.textContent = 'Generating...';
|
|
setStatus('<span class="spinner"></span> Generating image...');
|
|
imageContainer.classList.remove('visible');
|
|
|
|
try {
|
|
const [width, height] = sizeSelect.value.split('x').map(Number);
|
|
const response = await fetch(apiUrl, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ prompt, model: 'flux-schnell', width, height })
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
const base64 = data.data?.[0]?.b64_json;
|
|
|
|
if (!base64 || base64 === 'null') {
|
|
throw new Error(data.detail || 'No image data returned.');
|
|
}
|
|
|
|
const blob = await fetch(`data:image/png;base64,${base64}`).then(r => r.blob());
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
resultImage.src = url;
|
|
downloadBtn.href = url;
|
|
|
|
const ts = new Date().toISOString().replace(/[:.]/g, '-');
|
|
downloadBtn.download = `flux-image-${ts}.png`;
|
|
|
|
imageContainer.classList.add('visible');
|
|
setStatus('');
|
|
} catch (err) {
|
|
setStatus(`Error: ${err.message}`, true);
|
|
} finally {
|
|
generateBtn.disabled = false;
|
|
generateBtn.textContent = 'Generate';
|
|
}
|
|
}
|
|
|
|
generateBtn.addEventListener('click', generate);
|
|
promptInput.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Enter') generate();
|
|
});
|
|
clearBtn.addEventListener('click', () => {
|
|
promptInput.value = '';
|
|
promptInput.focus();
|
|
});
|
|
promptInput.addEventListener('focus', () => {
|
|
promptInput.select();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|