Uthar commited on
Commit
26428ec
1 Parent(s): 1310984

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -160,12 +160,26 @@ with gr.Blocks(theme='NoCrypt/miku@>=1.2.2', fill_width=True, css=CSS) as demo:
160
  with gr.Column(scale=2):
161
  gallery2 = gr.Gallery(label="Output", show_download_button=True, elem_classes="gallery", interactive=False, show_share_button=True, format="png", preview=True, object_fit="cover", columns=2, rows=2)
162
 
163
- for i, o in enumerate(output2):
164
- num_images.change(lambda i, n: gr.update(visible=(i < n)), [i, num_images], o, queue=False)
165
- gen_event2 = gr.on(triggers=[gen_button2.click, txt_input2.submit],
166
- fn=lambda i, n, m, t1, t2, n1, n2, n3, n4, n5: gen_fn(m, t1, t2, n1, n2, n3, n4, n5) if (i < n) else None,
167
- inputs=[i, num_images, model_choice2, txt_input2, neg_input2, height, width, steps, cfg, seed], outputs=[o])
168
- o.change(add_gallery, [o, model_choice2, gallery2], [gallery2])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  gr.Markdown("")
171
  demo.launch(show_api=False, max_threads=400)
 
160
  with gr.Column(scale=2):
161
  gallery2 = gr.Gallery(label="Output", show_download_button=True, elem_classes="gallery", interactive=False, show_share_button=True, format="png", preview=True, object_fit="cover", columns=2, rows=2)
162
 
163
+ for i, o in enumerate(output2):
164
+ # Change visibility based on num_images
165
+ num_images.change(
166
+ lambda num_images, i=i: gr.update(visible=(i < num_images)), # `i` corresponds to the index of the image
167
+ [num_images], # Only num_images needs to be an input
168
+ o, # Outputs the updated visibility of the image `o`
169
+ queue=False
170
+ )
171
+
172
+ # Image generation function
173
+ gen_event2 = gr.on(
174
+ triggers=[gen_button2.click, txt_input2.submit],
175
+ fn=gen_fn,
176
+ inputs=[i, num_images, model_choice2, txt_input2, neg_input2, height, width, steps, cfg, seed],
177
+ outputs=[o]
178
+ )
179
+
180
+ # Update gallery when a new image is generated
181
+ o.change(add_gallery, [o, model_choice2, gallery2], [gallery2])
182
+
183
 
184
  gr.Markdown("")
185
  demo.launch(show_api=False, max_threads=400)