File size: 5,817 Bytes
bd11b2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <title>Image Generation UI</title>
         <style>

             body {

                 font-family: Arial, sans-serif;

                 text-align: center;

                 margin: 0;

                 padding: 20px;

                 background-color: #f0f0f0;

             }

             .container {

                 max-width: 800px;

                 margin: 0 auto;

             }

             img.logo {

                 max-width: 150px;

                 margin-bottom: 20px;

             }

             select, input, button {

                 margin: 10px;

                 padding: 8px;

                 font-size: 16px;

                 border-radius: 4px;

                 border: 1px solid #ccc;

             }

             button {

                 background-color: #4CAF50;

                 color: white;

                 cursor: pointer;

             }

             button:hover {

                 background-color: #45a049;

             }

             #prompt {

                 width: 300px;

             }

             #output {

                 margin-top: 20px;

                 display: flex;

                 flex-wrap: wrap;

                 justify-content: center;

                 gap: 10px;

             }

             .output-image {

                 max-width: 200px;

                 border: 1px solid #ddd;

                 border-radius: 4px;

             }

             .error {

                 color: red;

                 margin-top: 10px;

             }

             .loading {

                 display: none;

                 margin-top: 10px;

                 font-style: italic;

             }

         </style>
     </head>
     <body>
         <div class="container">
             <img src="/assets/logo.png" alt="Logo" class="logo">
             <h1>Image Generation UI</h1>
             <div>
                 <label for="model-select">Select Model:</label>
                 <select id="model-select">
                     <option value="ssd-1b">SSD-1B</option>
                     <option value="sd-v1-5">Stable Diffusion v1-5</option>
                 </select>
             </div>
             <div>
                 <label for="ratio-select">Image Ratio:</label>
                 <select id="ratio-select">
                     <option value="1:1">1:1</option>
                     <option value="3:4">3:4</option>
                     <option value="16:9">16:9</option>
                 </select>
             </div>
             <div>
                 <label for="num-images">Number of Images (1-4):</label>
                 <input type="number" id="num-images" min="1" max="4" value="1">
             </div>
             <div>
                 <label for="prompt">Prompt:</label>
                 <input type="text" id="prompt" placeholder="Enter your prompt">
             </div>
             <div>
                 <label for="guidance-scale">Guidance Scale:</label>
                 <input type="number" id="guidance-scale" min="1" max="20" step="0.5" value="7.5">
             </div>
             <button onclick="generateImages()">Generate Images</button>
             <div id="loading" class="loading">Generating images, please wait...</div>
             <div id="error" class="error"></div>
             <div id="output"></div>
         </div>
         <script>

             async function generateImages() {

                 const model = document.getElementById('model-select').value;

                 const ratio = document.getElementById('ratio-select').value;

                 const numImages = document.getElementById('num-images').value;

                 const prompt = document.getElementById('prompt').value;

                 const guidanceScale = document.getElementById('guidance-scale').value;

                 const outputDiv = document.getElementById('output');

                 const errorDiv = document.getElementById('error');

                 const loadingDiv = document.getElementById('loading');



                 outputDiv.innerHTML = '';

                 errorDiv.innerText = '';

                 loadingDiv.style.display = 'block';



                 try {

                     const response = await fetch('/generate', {

                         method: 'POST',

                         headers: { 'Content-Type': 'application/json' },

                         body: JSON.stringify({

                             model,

                             prompt,

                             ratio,

                             num_images: numImages,

                             guidance_scale: guidanceScale

                         })

                     });



                     loadingDiv.style.display = 'none';

                     const data = await response.json();



                     if (response.ok) {

                         data.images.forEach(imgSrc => {

                             const img = document.createElement('img');

                             img.src = imgSrc;

                             img.className = 'output-image';

                             outputDiv.appendChild(img);

                         });

                     } else {

                         errorDiv.innerText = data.error || 'Failed to generate images';

                     }

                 } catch (error) {

                     loadingDiv.style.display = 'none';

                     errorDiv.innerText = 'Error: ' + error.message;

                 }

             }

         </script>
     </body>
     </html>