Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +73 -86
index.html
CHANGED
@@ -1,86 +1,73 @@
|
|
1 |
-
<!doctype html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="utf-8" />
|
5 |
-
<title>
|
6 |
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
7 |
-
<style>
|
8 |
-
body{font-family:system-ui
|
9 |
-
.
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
</
|
23 |
-
<
|
24 |
-
|
25 |
-
<
|
26 |
-
<
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
const
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
out.appendChild(div)
|
75 |
-
})
|
76 |
-
$('status').textContent = `Done. ${data.images.length} image(s), size ${data.shape?.join('x')||''}`
|
77 |
-
} catch (e) {
|
78 |
-
console.error(e)
|
79 |
-
$('status').textContent = 'Error: ' + e.message
|
80 |
-
} finally {
|
81 |
-
$('go').disabled = false
|
82 |
-
}
|
83 |
-
})
|
84 |
-
</script>
|
85 |
-
</body>
|
86 |
-
</html>
|
|
|
1 |
+
<!doctype html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<title>LDM / Stable Diffusion (CPU)</title>
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
7 |
+
<style>
|
8 |
+
body { font-family: system-ui, sans-serif; margin: 24px; }
|
9 |
+
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
|
10 |
+
input[type="text"] { width: 520px; max-width: 100%; padding: 8px; }
|
11 |
+
input[type="number"] { width: 100px; padding: 6px; }
|
12 |
+
button { padding: 10px 14px; cursor: pointer; }
|
13 |
+
#out { margin-top: 18px; max-width: 100%; border-radius: 8px; }
|
14 |
+
small { color: #666; }
|
15 |
+
</style>
|
16 |
+
</head>
|
17 |
+
<body>
|
18 |
+
<h1>LDM / Stable Diffusion (CPU)</h1>
|
19 |
+
<div class="row">
|
20 |
+
<input id="prompt" type="text" placeholder="Describe the image…" value="a scenic mountain lake at sunrise, mist, ultra-detailed" />
|
21 |
+
<button id="go">Generate</button>
|
22 |
+
</div>
|
23 |
+
<div class="row" style="margin-top:8px">
|
24 |
+
<label>Steps <input id="steps" type="number" min="1" max="100" value="30"></label>
|
25 |
+
<label>Guidance <input id="guidance" type="number" step="0.1" value="7.5"></label>
|
26 |
+
<label>Seed <input id="seed" type="number" placeholder="(optional)"></label>
|
27 |
+
<button id="direct">Open as PNG</button>
|
28 |
+
</div>
|
29 |
+
<p><small>Tip: “Open as PNG” hits <code>/generate.png</code> which returns an actual image.</small></p>
|
30 |
+
<img id="out" alt="result will appear here" />
|
31 |
+
|
32 |
+
<script>
|
33 |
+
const el = (id) => document.getElementById(id);
|
34 |
+
const go = el('go');
|
35 |
+
const direct = el('direct');
|
36 |
+
const out = el('out');
|
37 |
+
|
38 |
+
go.onclick = async () => {
|
39 |
+
go.disabled = true; go.textContent = 'Generating…';
|
40 |
+
out.removeAttribute('src');
|
41 |
+
const body = {
|
42 |
+
prompt: el('prompt').value,
|
43 |
+
num_inference_steps: Number(el('steps').value),
|
44 |
+
guidance_scale: Number(el('guidance').value),
|
45 |
+
};
|
46 |
+
const seed = el('seed').value.trim();
|
47 |
+
if (seed) body.seed = Number(seed);
|
48 |
+
|
49 |
+
const res = await fetch('/generate', {
|
50 |
+
method: 'POST',
|
51 |
+
headers: { 'Content-Type': 'application/json' },
|
52 |
+
body: JSON.stringify(body)
|
53 |
+
});
|
54 |
+
const data = await res.json();
|
55 |
+
// Show the image, not the string:
|
56 |
+
out.src = 'data:image/png;base64,' + data.image_base64;
|
57 |
+
go.disabled = false; go.textContent = 'Generate';
|
58 |
+
};
|
59 |
+
|
60 |
+
direct.onclick = () => {
|
61 |
+
const p = new URLSearchParams({
|
62 |
+
prompt: el('prompt').value,
|
63 |
+
num_inference_steps: String(el('steps').value),
|
64 |
+
guidance_scale: String(el('guidance').value)
|
65 |
+
});
|
66 |
+
const seed = el('seed').value.trim();
|
67 |
+
if (seed) p.set('seed', seed);
|
68 |
+
// Opens a real PNG in a new tab
|
69 |
+
window.open('/generate.png?' + p.toString(), '_blank');
|
70 |
+
};
|
71 |
+
</script>
|
72 |
+
</body>
|
73 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|