axolotyy commited on
Commit
e20f18b
·
verified ·
1 Parent(s): f3b38b0

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +58 -19
index.html CHANGED
@@ -1,19 +1,58 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>