state bug fix
Browse files
app.py
CHANGED
@@ -218,13 +218,13 @@ class WebApp():
|
|
218 |
print(f"Error catched: {e}")
|
219 |
gr.Markdown(f"**Error catched: {e}**")
|
220 |
|
221 |
-
def run_ditail_alt(self,
|
222 |
gr_args = self.args_base.copy()
|
223 |
print(self.args_input.keys())
|
224 |
for k, v in zip(list(self.args_input.keys()), values):
|
225 |
gr_args[k] = v
|
226 |
# quick fix for example
|
227 |
-
gr_args['lora'] = 'none' if not isinstance(gr_args['lora'], str) else
|
228 |
print('selected lora: ', gr_args['lora'])
|
229 |
# map inversion model to url
|
230 |
gr_args['pos_prompt'] = ', '.join(LORA_TRIGGER_WORD.get(gr_args['lora'], [])+[gr_args['pos_prompt']])
|
@@ -236,19 +236,19 @@ class WebApp():
|
|
236 |
ditail = DitailDemo(gr_args)
|
237 |
|
238 |
metadata_to_show = ['inv_model', 'spl_model', 'lora', 'lora_scale', 'inv_steps', 'spl_steps', 'pos_prompt', 'alpha', 'neg_prompt', 'beta', 'omega']
|
239 |
-
|
240 |
for key in metadata_to_show:
|
241 |
-
|
242 |
|
243 |
img = ditail.run_ditail()
|
244 |
|
245 |
# reset ditail
|
246 |
ditail = None
|
247 |
|
248 |
-
return
|
249 |
|
250 |
def run_example(self, img, prompt, inv_model, spl_model, lora):
|
251 |
-
return self.run_ditail_alt(
|
252 |
|
253 |
def show_credits(self):
|
254 |
# gr.Markdown(
|
@@ -289,12 +289,9 @@ class WebApp():
|
|
289 |
# expected_output_image = gr.Image(label="expected output image", visible=False)
|
290 |
metadata = gr.JSON(label='metadata')
|
291 |
|
292 |
-
# init a gradio state
|
293 |
-
self.gr_state = gr.State()
|
294 |
-
|
295 |
submit_btn.click(self.run_ditail_alt,
|
296 |
-
inputs=
|
297 |
-
outputs=[
|
298 |
scroll_to_output=True,
|
299 |
)
|
300 |
|
@@ -304,7 +301,7 @@ class WebApp():
|
|
304 |
examples=[[os.path.join(os.path.dirname(__file__), "example", "Lenna.png"), 'a woman called Lenna wearing a feathered hat', list(BASE_MODEL.keys())[1], list(BASE_MODEL.keys())[2], 'none']],
|
305 |
inputs=[self.args_input['img'], self.args_input['pos_prompt'], self.args_input['inv_model'], self.args_input['spl_model'], gr.Textbox(label='LoRA', visible=False), ],
|
306 |
fn = self.run_example,
|
307 |
-
outputs=[
|
308 |
run_on_click=True,
|
309 |
cache_examples=cache_examples,
|
310 |
)
|
|
|
218 |
print(f"Error catched: {e}")
|
219 |
gr.Markdown(f"**Error catched: {e}**")
|
220 |
|
221 |
+
def run_ditail_alt(self, *values):
|
222 |
gr_args = self.args_base.copy()
|
223 |
print(self.args_input.keys())
|
224 |
for k, v in zip(list(self.args_input.keys()), values):
|
225 |
gr_args[k] = v
|
226 |
# quick fix for example
|
227 |
+
gr_args['lora'] = 'none' if not isinstance(gr_args['lora'], str) else gr_args['lora']
|
228 |
print('selected lora: ', gr_args['lora'])
|
229 |
# map inversion model to url
|
230 |
gr_args['pos_prompt'] = ', '.join(LORA_TRIGGER_WORD.get(gr_args['lora'], [])+[gr_args['pos_prompt']])
|
|
|
236 |
ditail = DitailDemo(gr_args)
|
237 |
|
238 |
metadata_to_show = ['inv_model', 'spl_model', 'lora', 'lora_scale', 'inv_steps', 'spl_steps', 'pos_prompt', 'alpha', 'neg_prompt', 'beta', 'omega']
|
239 |
+
args_to_show = {}
|
240 |
for key in metadata_to_show:
|
241 |
+
args_to_show[key] = gr_args[key]
|
242 |
|
243 |
img = ditail.run_ditail()
|
244 |
|
245 |
# reset ditail
|
246 |
ditail = None
|
247 |
|
248 |
+
return img, args_to_show
|
249 |
|
250 |
def run_example(self, img, prompt, inv_model, spl_model, lora):
|
251 |
+
return self.run_ditail_alt(img, prompt, spl_model, gr.State(lora), inv_model)
|
252 |
|
253 |
def show_credits(self):
|
254 |
# gr.Markdown(
|
|
|
289 |
# expected_output_image = gr.Image(label="expected output image", visible=False)
|
290 |
metadata = gr.JSON(label='metadata')
|
291 |
|
|
|
|
|
|
|
292 |
submit_btn.click(self.run_ditail_alt,
|
293 |
+
inputs=list(self.args_input.values()),
|
294 |
+
outputs=[output_image, metadata],
|
295 |
scroll_to_output=True,
|
296 |
)
|
297 |
|
|
|
301 |
examples=[[os.path.join(os.path.dirname(__file__), "example", "Lenna.png"), 'a woman called Lenna wearing a feathered hat', list(BASE_MODEL.keys())[1], list(BASE_MODEL.keys())[2], 'none']],
|
302 |
inputs=[self.args_input['img'], self.args_input['pos_prompt'], self.args_input['inv_model'], self.args_input['spl_model'], gr.Textbox(label='LoRA', visible=False), ],
|
303 |
fn = self.run_example,
|
304 |
+
outputs=[output_image, metadata],
|
305 |
run_on_click=True,
|
306 |
cache_examples=cache_examples,
|
307 |
)
|