P01yH3dr0n commited on
Commit
ca93863
1 Parent(s): a75ae23

cancel button test

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -109,12 +109,13 @@ def control_ui():
109
  with gr.Column():
110
  save = gr.Checkbox(value=True, label='云端保存图片')
111
  gen_btn = gr.Button(value="生成", variant="primary")
 
112
  rand_seed.click(fn=lambda: -1, inputs=None, outputs=seed)
113
  width.change(lambda w, h: h if w*h<=1024*1024 else (1024*1024//w//64)*64, [width, height], height)
114
  height.change(lambda w, h: w if w*h<=1024*1024 else (1024*1024//h//64)*64, [width, height], width)
115
  i2i.select(lambda: 'i2i', inputs=None, outputs=selection)
116
  inp.select(lambda: 'inp', inputs=None, outputs=selection)
117
- return gen_btn, [prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_images, info_extracts, ref_strs, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection], [save, rand_seed, reuse_seed, reuse_img_i2i, reuse_img_inp]
118
 
119
  def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_images, info_extracts, ref_strs, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection):
120
  global today_count
@@ -159,14 +160,17 @@ def main_ui():
159
  with gr.Blocks() as page:
160
  with gr.Row(variant="panel"):
161
  with gr.Column():
162
- gen_btn, paras, others = control_ui()
163
  with gr.Column():
164
  image, info = preview_ui()
165
- gen_btn.click(generate, paras, [image, info], concurrency_limit=1)
 
166
  others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
167
  others[3].click(lambda i: i, inputs=image, outputs=paras[17])
168
  others[4].click(lambda i: gr.ImageEditor(value=i), inputs=image, outputs=paras[21])
169
- image.change(rename_save_img, inputs=[image, info, others[0]], outputs=image, trigger_mode="once")
 
 
170
  return page, paras[:14]
171
 
172
  def util_ui():
 
109
  with gr.Column():
110
  save = gr.Checkbox(value=True, label='云端保存图片')
111
  gen_btn = gr.Button(value="生成", variant="primary")
112
+ stop_btn = gr.Button(value="取消", variant="stop", visible=False)
113
  rand_seed.click(fn=lambda: -1, inputs=None, outputs=seed)
114
  width.change(lambda w, h: h if w*h<=1024*1024 else (1024*1024//w//64)*64, [width, height], height)
115
  height.change(lambda w, h: w if w*h<=1024*1024 else (1024*1024//h//64)*64, [width, height], width)
116
  i2i.select(lambda: 'i2i', inputs=None, outputs=selection)
117
  inp.select(lambda: 'inp', inputs=None, outputs=selection)
118
+ return gen_btn, stop_btn, [prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_images, info_extracts, ref_strs, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection], [save, rand_seed, reuse_seed, reuse_img_i2i, reuse_img_inp]
119
 
120
  def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_images, info_extracts, ref_strs, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection):
121
  global today_count
 
160
  with gr.Blocks() as page:
161
  with gr.Row(variant="panel"):
162
  with gr.Column():
163
+ gen_btn, stop_btn, paras, others = control_ui()
164
  with gr.Column():
165
  image, info = preview_ui()
166
+ gen_btn.click(lambda: (gr.Button(visible=False), gr.Button(visible=True)), inputs=None, outputs=[gen_btn, stop_btn])
167
+ gen = gen_btn.click(generate, paras, [image, info], concurrency_limit=1)
168
  others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
169
  others[3].click(lambda i: i, inputs=image, outputs=paras[17])
170
  others[4].click(lambda i: gr.ImageEditor(value=i), inputs=image, outputs=paras[21])
171
+ ren = image.change(rename_save_img, inputs=[image, info, others[0]], outputs=image, trigger_mode="once")
172
+ image.change(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[gen_btn, stop_btn])
173
+ stop_btn.click(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[gen_btn, stop_btn], cancels=[gen, ren])
174
  return page, paras[:14]
175
 
176
  def util_ui():