prithivMLmods commited on
Commit
bd2c7b2
1 Parent(s): ba1753e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +300 -113
app.py CHANGED
@@ -108,7 +108,6 @@ h1{text-align:center}
108
  footer {
109
  visibility: hidden
110
  }
111
-
112
  .wheel-and-hamster {
113
  --dur: 1s;
114
  position: relative;
@@ -116,14 +115,12 @@ footer {
116
  height: 12em;
117
  font-size: 14px;
118
  }
119
-
120
  .wheel,
121
  .hamster,
122
  .hamster div,
123
  .spoke {
124
  position: absolute;
125
  }
126
-
127
  .wheel,
128
  .spoke {
129
  border-radius: 50%;
@@ -132,12 +129,10 @@ footer {
132
  width: 100%;
133
  height: 100%;
134
  }
135
-
136
  .wheel {
137
  background: radial-gradient(100% 100% at center,hsla(0,0%,60%,0) 47.8%,hsl(0,0%,60%) 48%);
138
  z-index: 2;
139
  }
140
-
141
  .hamster {
142
  animation: hamster var(--dur) ease-in-out infinite;
143
  top: 50%;
@@ -148,7 +143,6 @@ footer {
148
  transform-origin: 50% 0;
149
  z-index: 1;
150
  }
151
-
152
  .hamster__head {
153
  animation: hamsterHead var(--dur) ease-in-out infinite;
154
  background: hsl(30,90%,55%);
@@ -161,7 +155,6 @@ footer {
161
  height: 2.5em;
162
  transform-origin: 100% 50%;
163
  }
164
-
165
  .hamster__ear {
166
  animation: hamsterEar var(--dur) ease-in-out infinite;
167
  background: hsl(0,90%,85%);
@@ -173,7 +166,6 @@ footer {
173
  height: 0.75em;
174
  transform-origin: 50% 75%;
175
  }
176
-
177
  .hamster__eye {
178
  animation: hamsterEye var(--dur) linear infinite;
179
  background-color: hsl(0,0%,0%);
@@ -183,7 +175,6 @@ footer {
183
  width: 0.5em;
184
  height: 0.5em;
185
  }
186
-
187
  .hamster__nose {
188
  background: hsl(0,90%,75%);
189
  border-radius: 35% 65% 85% 15% / 70% 50% 50% 30%;
@@ -192,7 +183,6 @@ footer {
192
  width: 0.2em;
193
  height: 0.25em;
194
  }
195
-
196
  .hamster__body {
197
  animation: hamsterBody var(--dur) ease-in-out infinite;
198
  background: hsl(30,90%,90%);
@@ -206,7 +196,6 @@ footer {
206
  transform-origin: 17% 50%;
207
  transform-style: preserve-3d;
208
  }
209
-
210
  .hamster__limb--fr,
211
  .hamster__limb--fl {
212
  clip-path: polygon(0 0,100% 0,70% 80%,60% 100%,0% 100%,40% 80%);
@@ -216,183 +205,381 @@ footer {
216
  height: 1.5em;
217
  transform-origin: 50% 0;
218
  }
219
-
220
  .hamster__limb--fr {
221
  animation: hamsterFRLimb var(--dur) linear infinite;
222
  background: linear-gradient(hsl(30,90%,80%) 80%,hsl(0,90%,75%) 80%);
223
  transform: rotate(15deg) translateZ(-1px);
224
  }
225
-
226
  .hamster__limb--fl {
227
  animation: hamsterFLLimb var(--dur) linear infinite;
228
  background: linear-gradient(hsl(30,90%,80%) 80%,hsl(0,90%,75%) 80%);
229
  transform: rotate(-60deg) translateZ(-1px);
230
  }
231
-
232
  .hamster__limb--br,
233
  .hamster__limb--bl {
234
- clip-path: polygon(0 0,100% 0,100% 30%,70% 80%,50% 100%,40% 80%,0% 30%);
235
- top: 1.25em;
236
  left: 2.8em;
237
- width: 1.5em;
238
  height: 2.5em;
239
- transform-origin: 33% 10%;
240
  }
241
-
242
  .hamster__limb--br {
243
  animation: hamsterBRLimb var(--dur) linear infinite;
244
  background: linear-gradient(hsl(0,90%,75%) 40%,hsl(30,90%,80%) 40%);
245
- transform: rotate(-15deg) translateZ(-1px);
246
  }
247
-
248
  .hamster__limb--bl {
249
  animation: hamsterBLLimb var(--dur) linear infinite;
250
  background: linear-gradient(hsl(0,90%,75%) 40%,hsl(30,90%,80%) 40%);
251
- transform: rotate(60deg) translateZ(-1px);
252
  }
253
-
254
  .hamster__tail {
255
  animation: hamsterTail var(--dur) linear infinite;
256
  background: hsl(0,90%,85%);
257
  border-radius: 0.25em 50% 50% 0.25em;
258
- box-shadow: 0.25em 0 hsl(30,90%,55%) inset;
259
- top: 1.5em;
260
- left: 5.5em;
261
- width: 0.5em;
 
262
  height: 0.75em;
263
  transform: rotate(30deg) translateZ(-1px);
264
- transform-origin: 0.25em 0.125em;
265
  }
266
-
267
  .spoke {
268
- background: radial-gradient(hsl(0,0%,70%) 25%,hsla(0,0%,60%,0) 26%) center/8px 8px;
269
- z-index: 0;
 
 
 
 
270
  }
271
-
272
- .spoke--1 {
273
- animation: spoke var(--dur) linear infinite;
274
  }
275
-
276
- .spoke--2 {
277
- animation: spoke var(--dur) linear infinite;
278
- transform: rotate(30deg);
279
  }
280
-
281
- .spoke--3 {
282
- animation: spoke var(--dur) linear infinite;
283
- transform: rotate(60deg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  }
285
 
286
  @keyframes hamster {
287
- 0%,100% { transform: rotate(4deg) translate(-0.8em,1.85em) }
288
- 50% { transform: rotate(0) translate(-0.8em,1.85em) }
 
289
  }
290
 
291
  @keyframes hamsterHead {
292
- 0%,100% { transform: rotate(0) }
293
- 50% { transform: rotate(-8deg) }
 
294
  }
295
 
296
- @keyframes hamsterEar {
297
- 0%,100% { transform: rotate(0) }
298
- 50% { transform: rotate(-3deg) }
 
299
  }
300
 
301
- @keyframes hamsterEye {
302
- 0%,90%,100% { transform: scaleY(1) }
303
- 95% { transform: scaleY(0) }
 
304
  }
305
 
306
  @keyframes hamsterBody {
307
- 0%,100% { transform: rotate(0) }
308
- 50% { transform: rotate(2deg) }
 
309
  }
310
 
311
  @keyframes hamsterFRLimb {
312
- 0%,100% { transform: rotate(15deg) translateZ(-1px) }
313
- 50% { transform: rotate(-30deg) translateZ(-1px) }
 
 
 
 
 
 
 
314
  }
315
 
316
  @keyframes hamsterFLLimb {
317
- 0%,100% { transform: rotate(-60deg) translateZ(-1px) }
318
- 50% { transform: rotate(-25deg) translateZ(-1px) }
 
 
 
 
 
 
 
319
  }
320
 
321
  @keyframes hamsterBRLimb {
322
- 0%,100% { transform: rotate(-15deg) translateZ(-1px) }
323
- 50% { transform: rotate(30deg) translateZ(-1px) }
 
 
 
 
 
 
 
324
  }
325
 
326
  @keyframes hamsterBLLimb {
327
- 0%,100% { transform: rotate(60deg) translateZ(-1px) }
328
- 50% { transform: rotate(25deg) translateZ(-1px) }
 
 
 
 
 
 
 
329
  }
330
 
331
  @keyframes hamsterTail {
332
- 0%,100% { transform: rotate(30deg) translateZ(-1px) }
333
- 50% { transform: rotate(10deg) translateZ(-1px) }
 
334
  }
335
 
336
- @keyframes spoke {
337
- 0% { transform: rotate(0) }
338
- 100% { transform: rotate(1turn) }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  }
340
  '''
341
 
342
  html = '''
343
- <div id="loading-animation" style="display: flex; justify-content: center; align-items: center; height: 100vh;">
344
- <div class="wheel-and-hamster">
345
- <div class="wheel"></div>
346
- <div class="hamster">
347
- <div class="hamster__body">
348
- <div class="hamster__head">
349
- <div class="hamster__ear"></div>
350
- <div class="hamster__eye"></div>
351
- <div class="hamster__nose"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  </div>
353
- <div class="hamster__limb hamster__limb--fr"></div>
354
- <div class="hamster__limb hamster__limb--fl"></div>
355
- <div class="hamster__limb hamster__limb--br"></div>
356
- <div class="hamster__limb hamster__limb--bl"></div>
357
- <div class="hamster__tail"></div>
358
  </div>
359
  </div>
360
- <div class="spoke spoke--1"></div>
361
- <div class="spoke spoke--2"></div>
362
- <div class="spoke spoke--3"></div>
363
  </div>
364
  </div>
365
  <script>
366
- window.onload = function() {
367
- document.getElementById("loading-animation").style.display = "none";
368
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  </script>
370
  '''
371
 
372
- with gr.Blocks(css=css) as demo:
373
- gr.HTML(html)
374
- gr.Markdown("# Flash Attention with SDXL")
375
- gr.Markdown("Generate images with Flash Attention and SDXL")
376
-
377
- with gr.Row():
378
- with gr.Column(scale=55):
379
- prompt = gr.Textbox(label="Prompt", show_label=False, max_lines=2, placeholder="Enter your prompt")
380
- negative_prompt = gr.Textbox(label="Negative Prompt", show_label=False, max_lines=2, placeholder="Enter negative prompt")
381
- with gr.Column(scale=45):
382
- generate_btn = gr.Button("Generate")
383
-
384
- with gr.Row():
385
- image_output = gr.Gallery(label="Generated Images", columns=2, height="auto")
386
- seed_output = gr.Number(label="Seed Used")
387
 
388
- gr.Examples(examples=examples, inputs=[prompt])
389
-
390
- inputs = [prompt, negative_prompt, gr.Checkbox(False, label="Use Negative Prompt"), gr.Slider(1, MAX_SEED, value=1, label="Seed"),
391
- gr.Slider(256, MAX_IMAGE_SIZE, value=1024, label="Width"), gr.Slider(256, MAX_IMAGE_SIZE, value=1024, label="Height"),
392
- gr.Slider(1, 20, value=7.5, label="Guidance Scale"), gr.Slider(1, 100, value=30, label="Number of Inference Steps"),
393
- gr.Checkbox(False, label="Randomize Seed"), gr.Checkbox(True, label="Use Resolution Binning"),
394
- gr.Slider(1, 10, value=1, label="Number of Images")]
395
-
396
- generate_btn.click(fn=generate, inputs=inputs, outputs=[image_output, seed_output])
397
-
398
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  footer {
109
  visibility: hidden
110
  }
 
111
  .wheel-and-hamster {
112
  --dur: 1s;
113
  position: relative;
 
115
  height: 12em;
116
  font-size: 14px;
117
  }
 
118
  .wheel,
119
  .hamster,
120
  .hamster div,
121
  .spoke {
122
  position: absolute;
123
  }
 
124
  .wheel,
125
  .spoke {
126
  border-radius: 50%;
 
129
  width: 100%;
130
  height: 100%;
131
  }
 
132
  .wheel {
133
  background: radial-gradient(100% 100% at center,hsla(0,0%,60%,0) 47.8%,hsl(0,0%,60%) 48%);
134
  z-index: 2;
135
  }
 
136
  .hamster {
137
  animation: hamster var(--dur) ease-in-out infinite;
138
  top: 50%;
 
143
  transform-origin: 50% 0;
144
  z-index: 1;
145
  }
 
146
  .hamster__head {
147
  animation: hamsterHead var(--dur) ease-in-out infinite;
148
  background: hsl(30,90%,55%);
 
155
  height: 2.5em;
156
  transform-origin: 100% 50%;
157
  }
 
158
  .hamster__ear {
159
  animation: hamsterEar var(--dur) ease-in-out infinite;
160
  background: hsl(0,90%,85%);
 
166
  height: 0.75em;
167
  transform-origin: 50% 75%;
168
  }
 
169
  .hamster__eye {
170
  animation: hamsterEye var(--dur) linear infinite;
171
  background-color: hsl(0,0%,0%);
 
175
  width: 0.5em;
176
  height: 0.5em;
177
  }
 
178
  .hamster__nose {
179
  background: hsl(0,90%,75%);
180
  border-radius: 35% 65% 85% 15% / 70% 50% 50% 30%;
 
183
  width: 0.2em;
184
  height: 0.25em;
185
  }
 
186
  .hamster__body {
187
  animation: hamsterBody var(--dur) ease-in-out infinite;
188
  background: hsl(30,90%,90%);
 
196
  transform-origin: 17% 50%;
197
  transform-style: preserve-3d;
198
  }
 
199
  .hamster__limb--fr,
200
  .hamster__limb--fl {
201
  clip-path: polygon(0 0,100% 0,70% 80%,60% 100%,0% 100%,40% 80%);
 
205
  height: 1.5em;
206
  transform-origin: 50% 0;
207
  }
 
208
  .hamster__limb--fr {
209
  animation: hamsterFRLimb var(--dur) linear infinite;
210
  background: linear-gradient(hsl(30,90%,80%) 80%,hsl(0,90%,75%) 80%);
211
  transform: rotate(15deg) translateZ(-1px);
212
  }
 
213
  .hamster__limb--fl {
214
  animation: hamsterFLLimb var(--dur) linear infinite;
215
  background: linear-gradient(hsl(30,90%,80%) 80%,hsl(0,90%,75%) 80%);
216
  transform: rotate(-60deg) translateZ(-1px);
217
  }
 
218
  .hamster__limb--br,
219
  .hamster__limb--bl {
220
+ clip-path: polygon(0 0,100% 0,100% 30%,70% 80%,60% 100%,40% 100%,30% 80%);
221
+ top: 2.3em;
222
  left: 2.8em;
223
+ width: 1.25em;
224
  height: 2.5em;
225
+ transform-origin: 50% 10%;
226
  }
 
227
  .hamster__limb--br {
228
  animation: hamsterBRLimb var(--dur) linear infinite;
229
  background: linear-gradient(hsl(0,90%,75%) 40%,hsl(30,90%,80%) 40%);
230
+ transform: rotate(45deg) translateZ(-1px);
231
  }
 
232
  .hamster__limb--bl {
233
  animation: hamsterBLLimb var(--dur) linear infinite;
234
  background: linear-gradient(hsl(0,90%,75%) 40%,hsl(30,90%,80%) 40%);
235
+ transform: rotate(-30deg) translateZ(-1px);
236
  }
 
237
  .hamster__tail {
238
  animation: hamsterTail var(--dur) linear infinite;
239
  background: hsl(0,90%,85%);
240
  border-radius: 0.25em 50% 50% 0.25em;
241
+ box-shadow: 0.1em 0.5em 0 hsl(30,90%,55%) inset,
242
+ 0.1em -0.25em 0 hsl(30,90%,90%) inset;
243
+ top: 3em;
244
+ left: 6em;
245
+ width: 0.75em;
246
  height: 0.75em;
247
  transform: rotate(30deg) translateZ(-1px);
 
248
  }
 
249
  .spoke {
250
+ --s: 0.2;
251
+ background: hsl(0,0%,100%);
252
+ box-shadow: 0 0 0 0.2em hsl(0,0%,0%);
253
+ left: calc(50% - var(--s)/2);
254
+ width: var(--s);
255
+ height: var(--s);
256
  }
257
+ .spoke:nth-child(1) {
258
+ --rotation: 15deg;
259
+ transform: rotate(var(--rotation));
260
  }
261
+ .spoke:nth-child(2) {
262
+ --rotation: 45deg;
263
+ transform: rotate(var(--rotation));
 
264
  }
265
+ .spoke:nth-child(3) {
266
+ --rotation: 75deg;
267
+ transform: rotate(var(--rotation));
268
+ }
269
+ .spoke:nth-child(4) {
270
+ --rotation: 105deg;
271
+ transform: rotate(var(--rotation));
272
+ }
273
+ .spoke:nth-child(5) {
274
+ --rotation: 135deg;
275
+ transform: rotate(var(--rotation));
276
+ }
277
+ .spoke:nth-child(6) {
278
+ --rotation: 165deg;
279
+ transform: rotate(var(--rotation));
280
+ }
281
+ .spoke:nth-child(7) {
282
+ --rotation: 195deg;
283
+ transform: rotate(var(--rotation));
284
+ }
285
+ .spoke:nth-child(8) {
286
+ --rotation: 225deg;
287
+ transform: rotate(var(--rotation));
288
+ }
289
+ .spoke:nth-child(9) {
290
+ --rotation: 255deg;
291
+ transform: rotate(var(--rotation));
292
+ }
293
+ .spoke:nth-child(10) {
294
+ --rotation: 285deg;
295
+ transform: rotate(var(--rotation));
296
+ }
297
+ .spoke:nth-child(11) {
298
+ --rotation: 315deg;
299
+ transform: rotate(var(--rotation));
300
+ }
301
+ .spoke:nth-child(12) {
302
+ --rotation: 345deg;
303
+ transform: rotate(var(--rotation));
304
  }
305
 
306
  @keyframes hamster {
307
+ 50% {
308
+ transform: rotate(-4deg) translate(-0.8em,1.85em);
309
+ }
310
  }
311
 
312
  @keyframes hamsterHead {
313
+ 50% {
314
+ transform: rotate(-8deg);
315
+ }
316
  }
317
 
318
+ @keyframes hamsterEye {
319
+ 50% {
320
+ transform: translateY(0.1em);
321
+ }
322
  }
323
 
324
+ @keyframes hamsterEar {
325
+ 50% {
326
+ transform: rotate(8deg);
327
+ }
328
  }
329
 
330
  @keyframes hamsterBody {
331
+ 50% {
332
+ transform: rotate(2deg);
333
+ }
334
  }
335
 
336
  @keyframes hamsterFRLimb {
337
+ 8%,70% {
338
+ transform: rotate(15deg) translateZ(-1px);
339
+ }
340
+ 33% {
341
+ transform: rotate(-60deg) translateZ(-1px);
342
+ }
343
+ 83% {
344
+ transform: rotate(45deg) translateZ(-1px);
345
+ }
346
  }
347
 
348
  @keyframes hamsterFLLimb {
349
+ 8%,70% {
350
+ transform: rotate(-60deg) translateZ(-1px);
351
+ }
352
+ 33% {
353
+ transform: rotate(15deg) translateZ(-1px);
354
+ }
355
+ 83% {
356
+ transform: rotate(-45deg) translateZ(-1px);
357
+ }
358
  }
359
 
360
  @keyframes hamsterBRLimb {
361
+ 0%,50% {
362
+ transform: rotate(45deg) translateZ(-1px);
363
+ }
364
+ 25% {
365
+ transform: rotate(-30deg) translateZ(-1px);
366
+ }
367
+ 75% {
368
+ transform: rotate(60deg) translateZ(-1px);
369
+ }
370
  }
371
 
372
  @keyframes hamsterBLLimb {
373
+ 0%,50% {
374
+ transform: rotate(-30deg) translateZ(-1px);
375
+ }
376
+ 25% {
377
+ transform: rotate(45deg) translateZ(-1px);
378
+ }
379
+ 75% {
380
+ transform: rotate(-45deg) translateZ(-1px);
381
+ }
382
  }
383
 
384
  @keyframes hamsterTail {
385
+ 50% {
386
+ transform: rotate(-30deg) translateZ(-1px);
387
+ }
388
  }
389
 
390
+ #wrapper {
391
+ position: relative;
392
+ height: 100vh;
393
+ display: flex;
394
+ justify-content: center;
395
+ align-items: center;
396
+ }
397
+ .loading-container {
398
+ position: relative;
399
+ display: flex;
400
+ justify-content: center;
401
+ align-items: center;
402
+ width: 100%;
403
+ height: 100%;
404
+ top: 50%;
405
+ transform: translateY(-50%);
406
+ }
407
+ .hidden {
408
+ display: none;
409
  }
410
  '''
411
 
412
  html = '''
413
+ <div id="wrapper">
414
+ <div class="loading-container">
415
+ <div class="wheel-and-hamster">
416
+ <div class="wheel">
417
+ <div class="spoke"></div>
418
+ <div class="spoke"></div>
419
+ <div class="spoke"></div>
420
+ <div class="spoke"></div>
421
+ <div class="spoke"></div>
422
+ <div class="spoke"></div>
423
+ <div class="spoke"></div>
424
+ <div class="spoke"></div>
425
+ <div class="spoke"></div>
426
+ <div class="spoke"></div>
427
+ <div class="spoke"></div>
428
+ <div class="spoke"></div>
429
+ </div>
430
+ <div class="hamster">
431
+ <div class="hamster__body">
432
+ <div class="hamster__head">
433
+ <div class="hamster__ear"></div>
434
+ <div class="hamster__eye"></div>
435
+ <div class="hamster__nose"></div>
436
+ </div>
437
+ <div class="hamster__limb hamster__limb--fr"></div>
438
+ <div class="hamster__limb hamster__limb--fl"></div>
439
+ <div class="hamster__limb hamster__limb--br"></div>
440
+ <div class="hamster__limb hamster__limb--bl"></div>
441
+ <div class="hamster__tail"></div>
442
  </div>
 
 
 
 
 
443
  </div>
444
  </div>
 
 
 
445
  </div>
446
  </div>
447
  <script>
448
+ // Wait for the Gradio app to load
449
+ document.addEventListener("DOMContentLoaded", function() {
450
+ const observer = new MutationObserver(function(mutationsList, observer) {
451
+ for (const mutation of mutationsList) {
452
+ if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
453
+ // Check if Gradio has loaded by looking for a specific element
454
+ const gradioApp = document.querySelector("#root");
455
+ if (gradioApp) {
456
+ // Hide the loading animation and observer
457
+ document.querySelector(".loading-container").classList.add("hidden");
458
+ observer.disconnect();
459
+ }
460
+ }
461
+ }
462
+ });
463
+
464
+ // Start observing the body for changes
465
+ observer.observe(document.body, { childList: true, subtree: true });
466
+ });
467
  </script>
468
  '''
469
 
470
+ block = gr.Blocks(css=css)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
 
472
+ with block as demo:
473
+ gr.HTML(html)
474
+ with gr.Column(elem_id="main-app"):
475
+ gr.Markdown(
476
+ """
477
+ # Generate images with Stable Diffusion XL
478
+ """
479
+ )
480
+ with gr.Row():
481
+ with gr.Column():
482
+ text = gr.Textbox(
483
+ label="Prompt",
484
+ placeholder="Enter your prompt",
485
+ lines=1,
486
+ )
487
+ negative_text = gr.Textbox(
488
+ label="Negative Prompt",
489
+ placeholder="Enter negative prompt",
490
+ lines=1,
491
+ )
492
+ negative_prompt_chk = gr.Checkbox(
493
+ label="Use Negative Prompt",
494
+ value=True
495
+ )
496
+ seed = gr.Number(
497
+ label="Seed",
498
+ value=1,
499
+ precision=0
500
+ )
501
+ randomize_seed = gr.Checkbox(
502
+ label="Randomize Seed",
503
+ value=False
504
+ )
505
+ width = gr.Slider(
506
+ label="Width",
507
+ value=1024,
508
+ minimum=64,
509
+ maximum=MAX_IMAGE_SIZE,
510
+ step=8
511
+ )
512
+ height = gr.Slider(
513
+ label="Height",
514
+ value=1024,
515
+ minimum=64,
516
+ maximum=MAX_IMAGE_SIZE,
517
+ step=8
518
+ )
519
+ guidance_scale = gr.Slider(
520
+ label="Guidance Scale",
521
+ value=3,
522
+ minimum=0,
523
+ maximum=50,
524
+ step=0.5
525
+ )
526
+ num_inference_steps = gr.Slider(
527
+ label="Number of Inference Steps",
528
+ value=30,
529
+ minimum=1,
530
+ maximum=100,
531
+ step=1
532
+ )
533
+ use_resolution_binning = gr.Checkbox(
534
+ label="Use Resolution Binning",
535
+ value=True
536
+ )
537
+ num_images = gr.Number(
538
+ label="Number of Images to Generate",
539
+ value=1,
540
+ minimum=1,
541
+ maximum=10,
542
+ step=1
543
+ )
544
+ generate_button = gr.Button(label="Generate Images")
545
+ with gr.Column():
546
+ gr.Label(label="Examples:")
547
+ for example in examples:
548
+ gr.Label(label=f"- {example}")
549
+
550
+ generated_images = gr.Image(
551
+ label="Generated Images",
552
+ type="PIL", # Display the PIL image
553
+ source=None
554
+ )
555
+
556
+ def generate_images_interface():
557
+ args = {
558
+ "prompt": text.value,
559
+ "negative_prompt": negative_text.value if negative_prompt_chk.value else "",
560
+ "use_negative_prompt": negative_prompt_chk.value,
561
+ "seed": seed.value,
562
+ "width": int(width.value),
563
+ "height": int(height.value),
564
+ "guidance_scale": float(guidance_scale.value),
565
+ "num_inference_steps": int(num_inference_steps.value),
566
+ "randomize_seed": randomize_seed.value,
567
+ "use_resolution_binning": use_resolution_binning.value,
568
+ "num_images": int(num_images.value),
569
+ "progress": gr.Progress()
570
+ }
571
+ image_paths, _ = generate(**args)
572
+ images = [Image.open(image_path) for image_path in image_paths]
573
+ return images
574
+
575
+ def on_generate_click():
576
+ generated_images.set_value(generate_images_interface())
577
+
578
+ gr.Interface(
579
+ fn=on_generate_click,
580
+ live=True,
581
+ title="Diffusion Generator",
582
+ description="Generate images using Stable Diffusion XL.",
583
+ layout="vertical",
584
+ blocking=True
585
+ ).launch()