Yuxuan Zhang commited on
Commit
9d3dabd
·
1 Parent(s): 6908ed7
Files changed (1) hide show
  1. app.py +39 -8
app.py CHANGED
@@ -111,7 +111,7 @@ def delete_old_files():
111
  threading.Thread(target=delete_old_files, daemon=True).start()
112
 
113
 
114
- @spaces.GPU(duration=120) # [uncomment to use ZeroGPU]
115
  def infer(prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
116
  progress=gr.Progress(track_tqdm=True)):
117
  if randomize_seed:
@@ -173,6 +173,24 @@ with gr.Blocks() as demo:
173
  run_button = gr.Button("Run", scale=1)
174
  result = gr.Image(label="Result", show_label=False)
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  with gr.Accordion("Advanced Settings", open=False):
177
  seed = gr.Slider(
178
  label="Seed",
@@ -189,7 +207,7 @@ with gr.Blocks() as demo:
189
  label="Width",
190
  minimum=512,
191
  maximum=2048,
192
- step=16,
193
  value=1024,
194
  )
195
 
@@ -197,10 +215,11 @@ with gr.Blocks() as demo:
197
  label="Height",
198
  minimum=512,
199
  maximum=2048,
200
- step=16,
201
  value=1024,
202
  )
203
-
 
204
  with gr.Row():
205
  guidance_scale = gr.Slider(
206
  label="Guidance scale",
@@ -217,9 +236,8 @@ with gr.Blocks() as demo:
217
  step=1,
218
  value=50,
219
  )
220
-
221
  with gr.Column():
222
- gr.Markdown("### Examples (Enhance prompt finish.)")
223
  for i, ex in enumerate(examples):
224
  with gr.Row():
225
  ex_btn = gr.Button(
@@ -229,7 +247,7 @@ with gr.Blocks() as demo:
229
  scale=3
230
  )
231
  ex_img = gr.Image(
232
- value=f"img/img_{i + 1}.png",
233
  label="Effect",
234
  interactive=False,
235
  height=130,
@@ -237,10 +255,23 @@ with gr.Blocks() as demo:
237
  scale=1
238
  )
239
  ex_btn.click(fn=lambda ex=ex: ex, inputs=[], outputs=prompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  gr.on(
241
  triggers=[run_button.click, prompt.submit],
242
  fn=infer,
243
- inputs=[prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
244
  outputs=[result, seed]
245
  )
246
 
 
111
  threading.Thread(target=delete_old_files, daemon=True).start()
112
 
113
 
114
+ @spaces.GPU(duration=180) # [uncomment to use ZeroGPU]
115
  def infer(prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
116
  progress=gr.Progress(track_tqdm=True)):
117
  if randomize_seed:
 
173
  run_button = gr.Button("Run", scale=1)
174
  result = gr.Image(label="Result", show_label=False)
175
 
176
+ num_images = gr.Radio(
177
+ choices=[1, 2, 4],
178
+ label="Number of Images",
179
+ value=1
180
+ )
181
+ result = gr.Gallery(label="Results", show_label=True, columns=2, rows=2)
182
+
183
+ MAX_PIXELS = 2 ** 21
184
+
185
+ def update_max_height(width):
186
+ max_height = MAX_PIXELS // width
187
+ return gr.update(maximum=max_height)
188
+
189
+
190
+ def update_max_width(height):
191
+ max_width = MAX_PIXELS // height
192
+ return gr.update(maximum=max_width)
193
+
194
  with gr.Accordion("Advanced Settings", open=False):
195
  seed = gr.Slider(
196
  label="Seed",
 
207
  label="Width",
208
  minimum=512,
209
  maximum=2048,
210
+ step=32,
211
  value=1024,
212
  )
213
 
 
215
  label="Height",
216
  minimum=512,
217
  maximum=2048,
218
+ step=32,
219
  value=1024,
220
  )
221
+ width.change(update_max_height, inputs=[width], outputs=[height])
222
+ height.change(update_max_width, inputs=[height], outputs=[width])
223
  with gr.Row():
224
  guidance_scale = gr.Slider(
225
  label="Guidance scale",
 
236
  step=1,
237
  value=50,
238
  )
 
239
  with gr.Column():
240
+ gr.Markdown("### Examples (Enhance prompt finish)")
241
  for i, ex in enumerate(examples):
242
  with gr.Row():
243
  ex_btn = gr.Button(
 
247
  scale=3
248
  )
249
  ex_img = gr.Image(
250
+ value=f"../img/img_{i + 1}.png",
251
  label="Effect",
252
  interactive=False,
253
  height=130,
 
255
  scale=1
256
  )
257
  ex_btn.click(fn=lambda ex=ex: ex, inputs=[], outputs=prompt)
258
+
259
+ def update_gallery_layout(num_images):
260
+ if num_images == 1:
261
+ return gr.update(columns=1, rows=1)
262
+ elif num_images == 2:
263
+ return gr.update(columns=2, rows=1)
264
+ elif num_images == 4:
265
+ return gr.update(columns=2, rows=2)
266
+ return gr.update(columns=2, rows=2)
267
+
268
+
269
+ num_images.change(update_gallery_layout, inputs=[num_images], outputs=[result])
270
+
271
  gr.on(
272
  triggers=[run_button.click, prompt.submit],
273
  fn=infer,
274
+ inputs=[prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images],
275
  outputs=[result, seed]
276
  )
277