Update index.html
Browse files- index.html +58 -19
index.html
CHANGED
@@ -1,19 +1,58 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Image Generator</title>
|
7 |
+
<script>
|
8 |
+
async function generateImage(e) {
|
9 |
+
e.preventDefault();
|
10 |
+
|
11 |
+
// Get the value of the prompt from the form input
|
12 |
+
const prompt = document.getElementById('prompt-input').value;
|
13 |
+
|
14 |
+
try {
|
15 |
+
// Make a POST request to the API endpoint
|
16 |
+
const response = await fetch('https://2c70-35-198-254-120.ngrok-free.app/generate-image/', {
|
17 |
+
method: 'POST',
|
18 |
+
headers: {
|
19 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
20 |
+
},
|
21 |
+
// Send the prompt as form data
|
22 |
+
body: `prompt=${encodeURIComponent(prompt)}`
|
23 |
+
});
|
24 |
+
|
25 |
+
// Parse the JSON response
|
26 |
+
const data = await response.json();
|
27 |
+
|
28 |
+
if (response.ok) {
|
29 |
+
// Get the image base64 data from the response
|
30 |
+
const imageBase64 = data.image_base64;
|
31 |
+
|
32 |
+
// Display the image by setting the src attribute of an img element
|
33 |
+
document.getElementById('generated-image').src = `data:image/png;base64,${imageBase64}`;
|
34 |
+
} else {
|
35 |
+
console.error('Error from API:', data);
|
36 |
+
alert('Failed to generate image.');
|
37 |
+
}
|
38 |
+
} catch (error) {
|
39 |
+
console.error('Network or other error:', error);
|
40 |
+
alert('Failed to generate image.');
|
41 |
+
}
|
42 |
+
}
|
43 |
+
</script>
|
44 |
+
</head>
|
45 |
+
<body>
|
46 |
+
<h1>Image Generator</h1>
|
47 |
+
|
48 |
+
<!-- Create a form for the user to enter a prompt -->
|
49 |
+
<form onsubmit="generateImage(event)">
|
50 |
+
<label for="prompt-input">Enter a prompt to generate an image:</label>
|
51 |
+
<input type="text" id="prompt-input" required>
|
52 |
+
<button type="submit">Generate</button>
|
53 |
+
</form>
|
54 |
+
|
55 |
+
<!-- This img element will display the generated image -->
|
56 |
+
<img id="generated-image" alt="Generated Image" style="max-width: 100%;">
|
57 |
+
|
58 |
+
</body>
|