P01yH3dr0n commited on
Commit
4623262
1 Parent(s): 4dd892c

error fix and subsequently trigger

Browse files
Files changed (3) hide show
  1. app.py +11 -11
  2. director_tools.py +3 -3
  3. utils.py +4 -4
app.py CHANGED
@@ -176,14 +176,14 @@ def main_ui():
176
  cost_list = paras[5:8] + paras[10:12] + paras[17:19] + paras[21:23]
177
  for component in cost_list:
178
  component.change(update_btn_cost, inputs=cost_list, outputs=gen_btn)
179
- gen_btn.click(lambda: (gr.Button(visible=False), gr.Button(visible=True)), inputs=None, outputs=[gen_btn, stop_btn])
180
- gen = gen_btn.click(generate, paras, [image, info], concurrency_limit=1, concurrency_id="generate")
 
 
181
  others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
182
  others[3].click(lambda i: i, inputs=image, outputs=paras[17])
183
  others[4].click(lambda i: gr.ImageEditor(value=i), inputs=image, outputs=paras[21])
184
- ren = image.change(rename_save_img, inputs=[image, info, others[0]], outputs=image, trigger_mode="once")
185
- image.change(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[gen_btn, stop_btn])
186
- stop_btn.click(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[gen_btn, stop_btn], cancels=[gen, ren])
187
  return image, paras, others, send_dtool
188
 
189
  def util_ui():
@@ -214,20 +214,20 @@ def load_javascript():
214
  gr.routes.templates.TemplateResponse = template_response
215
 
216
  def send_and_jump(component, fn, inputs, outputs, tab, trigger):
217
- component.click(fn, inputs=inputs, outputs=outputs)
218
- component.click(fn=None,
219
  js="(x) => { if (x !== null && x != 0) document.getElementById('" + tab + "-button').click(); return null; }",
220
  inputs=trigger)
221
 
222
  def send_jump_select(component, fn, inputs, outputs, tab, accordin, trigger, secondary=None):
223
- component.click(fn, inputs=inputs, outputs=outputs)
224
  extra_js = ''
225
  if secondary is not None:
226
  extra_js = "document.getElementById('" + secondary + "-button').click();"
227
- component.click(fn=None,
 
228
  js="(x) => { if (x !== null && x != 0) document.getElementById('" + tab + "-button').click();" + extra_js + " return null; }",
229
- inputs=trigger)
230
- component.click(lambda x: gr.Accordion(open=True) if x else gr.Accordion(), inputs=trigger, outputs=accordin)
231
 
232
  def ui():
233
  load_javascript()
 
176
  cost_list = paras[5:8] + paras[10:12] + paras[17:19] + paras[21:23]
177
  for component in cost_list:
178
  component.change(update_btn_cost, inputs=cost_list, outputs=gen_btn)
179
+ gen = gen_btn.click(lambda: (gr.Button(visible=False), gr.Button(visible=True)), inputs=None, outputs=[gen_btn, stop_btn]).then(
180
+ generate, paras, [image, info], concurrency_limit=1, concurrency_id="generate").then(
181
+ rename_save_img, inputs=[image, info, others[0]], outputs=image, trigger_mode="once").then(
182
+ lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[gen_btn, stop_btn])
183
  others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
184
  others[3].click(lambda i: i, inputs=image, outputs=paras[17])
185
  others[4].click(lambda i: gr.ImageEditor(value=i), inputs=image, outputs=paras[21])
186
+ stop_btn.click(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[gen_btn, stop_btn], cancels=[gen])
 
 
187
  return image, paras, others, send_dtool
188
 
189
  def util_ui():
 
214
  gr.routes.templates.TemplateResponse = template_response
215
 
216
  def send_and_jump(component, fn, inputs, outputs, tab, trigger):
217
+ component.click(fn, inputs=inputs, outputs=outputs).success(
218
+ fn=None,
219
  js="(x) => { if (x !== null && x != 0) document.getElementById('" + tab + "-button').click(); return null; }",
220
  inputs=trigger)
221
 
222
  def send_jump_select(component, fn, inputs, outputs, tab, accordin, trigger, secondary=None):
 
223
  extra_js = ''
224
  if secondary is not None:
225
  extra_js = "document.getElementById('" + secondary + "-button').click();"
226
+ component.click(fn, inputs=inputs, outputs=outputs).success(
227
+ fn=None,
228
  js="(x) => { if (x !== null && x != 0) document.getElementById('" + tab + "-button').click();" + extra_js + " return null; }",
229
+ inputs=trigger).success(
230
+ lambda x: gr.Accordion(open=True) if x else gr.Accordion(), inputs=trigger, outputs=accordin)
231
 
232
  def ui():
233
  load_javascript()
director_tools.py CHANGED
@@ -89,10 +89,10 @@ def director_ui():
89
  tool_btn = gr.Button(value="生成", variant="primary", visible=False)
90
  dtool_stop = gr.Button(value="取消", variant="stop", visible=False)
91
  input_image.change(lambda i: gr.Button(visible=False) if i is None else gr.Button(visible=True), inputs=input_image, outputs=tool_btn)
92
- tool_btn.click(lambda: (gr.Button(visible=False), gr.Button(visible=True), gr.Gallery(selected_index=None), -1), inputs=None, outputs=[tool_btn, dtool_stop, output_image, selected_index])
93
- dtool_gen = tool_btn.click(augment_image, inputs=[input_image, width, height, req_type, selection, factor, defry, prompt], outputs=output_image, concurrency_id="generate")
 
94
  dtool_stop.click(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[tool_btn, dtool_stop], cancels=[dtool_gen])
95
- output_image.change(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[tool_btn, dtool_stop])
96
  reset.click(getWH, inputs=[input_image, width, height, factor], outputs=[width, height, hint])
97
  width.change(update_btn_cost, inputs=[width, height, req_type, selection, hint], outputs=tool_btn)
98
  height.change(update_btn_cost, inputs=[width, height, req_type, selection, hint], outputs=tool_btn)
 
89
  tool_btn = gr.Button(value="生成", variant="primary", visible=False)
90
  dtool_stop = gr.Button(value="取消", variant="stop", visible=False)
91
  input_image.change(lambda i: gr.Button(visible=False) if i is None else gr.Button(visible=True), inputs=input_image, outputs=tool_btn)
92
+ dtool_gen = tool_btn.click(lambda: (gr.Button(visible=False), gr.Button(visible=True), gr.Gallery(selected_index=None), -1), inputs=None, outputs=[tool_btn, dtool_stop, output_image, selected_index]).then(
93
+ augment_image, inputs=[input_image, width, height, req_type, selection, factor, defry, prompt], outputs=output_image, concurrency_id="generate").then(
94
+ lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[tool_btn, dtool_stop])
95
  dtool_stop.click(lambda: (gr.Button(visible=True), gr.Button(visible=False)), inputs=None, outputs=[tool_btn, dtool_stop], cancels=[dtool_gen])
 
96
  reset.click(getWH, inputs=[input_image, width, height, factor], outputs=[width, height, hint])
97
  width.change(update_btn_cost, inputs=[width, height, req_type, selection, hint], outputs=tool_btn)
98
  height.change(update_btn_cost, inputs=[width, height, req_type, selection, hint], outputs=tool_btn)
utils.py CHANGED
@@ -133,10 +133,10 @@ def generate_novelai_image(
133
  return file.read(), payload
134
  else:
135
  messages = json.loads(response.content)
136
- raise gr.Error(messages["statusCode"] + ": " + messages["message"])
137
  else:
138
  messages = json.loads(response.content)
139
- raise gr.Error(messages["statusCode"] + ": " + messages["message"])
140
 
141
  def image_from_bytes(data):
142
  img_file = io.BytesIO(data)
@@ -179,7 +179,7 @@ def augment_image(image, width, height, req_type, selection, factor=1, defry=0,
179
  return images
180
  else:
181
  messages = json.loads(response.content)
182
- raise gr.Error(messages["statusCode"] + ": " + messages["message"])
183
  else:
184
  messages = json.loads(response.content)
185
- raise gr.Error(messages["statusCode"] + ": " + messages["message"])
 
133
  return file.read(), payload
134
  else:
135
  messages = json.loads(response.content)
136
+ raise gr.Error(str(messages["statusCode"]) + ": " + messages["message"])
137
  else:
138
  messages = json.loads(response.content)
139
+ raise gr.Error(str(messages["statusCode"]) + ": " + messages["message"])
140
 
141
  def image_from_bytes(data):
142
  img_file = io.BytesIO(data)
 
179
  return images
180
  else:
181
  messages = json.loads(response.content)
182
+ raise gr.Error(str(messages["statusCode"]) + ": " + messages["message"])
183
  else:
184
  messages = json.loads(response.content)
185
+ raise gr.Error(str(messages["statusCode"]) + ": " + messages["message"])