niulx commited on
Commit
dde1106
1 Parent(s): 5b0f8f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -95,16 +95,27 @@ def edit_mask_add(canvas, image, idx, mask_np_list):
95
  return mask_np_list_updated, image_edit
96
 
97
  def slider_release(index, image, mask_np_list_updated, mask_label_list):
98
-
99
  if index > len(mask_np_list_updated)-1:
100
- return image, "out of range"
101
  else:
102
  mask_np = mask_np_list_updated[index]
103
  mask_label = mask_label_list[index]
 
 
 
 
 
 
 
 
 
 
 
 
104
  segmentation = create_segmentation(mask_np_list_updated)
105
  new_image = transparent_paste_with_mask(image, segmentation, mask_np, transparency = TRANSPARENCY)
106
  gr.Info('Edit '+ mask_label)
107
- return new_image, mask_label
108
  def image_change():
109
  return gr.Slider(value = 0, minimum=0, maximum=1, step=1, visible=False),gr.Button("Step 3. Run Editing (Check log for progress.)",interactive = False)
110
 
@@ -186,10 +197,6 @@ with gr.Blocks() as demo:
186
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Edit Mask (Optional)</p>""")
187
  slider = gr.Slider(0, 20, step=1, label = 'mask id', visible=False)
188
  label = gr.Text(label='label')
189
- slider.release(slider_release,
190
- inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
191
- outputs= [canvas, label]
192
- )
193
 
194
 
195
 
@@ -260,10 +267,9 @@ with gr.Blocks() as demo:
260
 
261
  with gr.Column():
262
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Editing setting (SD)</p>""")
263
- tgt_prompt = gr.Textbox(value="White bag", label="Editing: Text prompt", interactive= True )
264
  with gr.Accordion(label="Advanced settings", open=False):
265
  slider2 = gr.Slider(0, 20, step=1, label = 'mask id', visible=False)
266
- #tgt_index = gr.Number(value="0", label="Editing: Object index", interactive= True )
267
  guidance_scale = gr.Textbox(value="5", label="Editing: CFG guidance scale", interactive= True )
268
  num_sampling_steps = gr.Number(value="20", label="Editing: Sampling steps", interactive= True )
269
  edge_thickness = gr.Number(value="10", label="Editing: Edge thickness", interactive= True )
@@ -333,7 +339,11 @@ with gr.Blocks() as demo:
333
  slider2
334
  ],
335
  outputs = [canvas_text_edit],queue=True)
336
-
 
 
 
 
337
  slider.change(
338
  lambda x: x,
339
  inputs=[slider],
 
95
  return mask_np_list_updated, image_edit
96
 
97
  def slider_release(index, image, mask_np_list_updated, mask_label_list):
 
98
  if index > len(mask_np_list_updated)-1:
99
+ return image, "out of range", ""
100
  else:
101
  mask_np = mask_np_list_updated[index]
102
  mask_label = mask_label_list[index]
103
+ index = mask_label.rfind('-')
104
+ mask_label = mask_label[:index]
105
+ if mask_label == 'handbag':
106
+ mask_prompt = "white handbag"
107
+ elif mask_label == 'person':
108
+ mask_prompt = "young man"
109
+ elif mask_label == 'wall-other-merged':
110
+ mask_prompt = "white wall"
111
+ elif mask_label == 'table-merged':
112
+ mask_prompt = "table"
113
+ else:
114
+ mask_prompt = mask_label
115
  segmentation = create_segmentation(mask_np_list_updated)
116
  new_image = transparent_paste_with_mask(image, segmentation, mask_np, transparency = TRANSPARENCY)
117
  gr.Info('Edit '+ mask_label)
118
+ return new_image, mask_label, mask_prompt
119
  def image_change():
120
  return gr.Slider(value = 0, minimum=0, maximum=1, step=1, visible=False),gr.Button("Step 3. Run Editing (Check log for progress.)",interactive = False)
121
 
 
197
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Edit Mask (Optional)</p>""")
198
  slider = gr.Slider(0, 20, step=1, label = 'mask id', visible=False)
199
  label = gr.Text(label='label')
 
 
 
 
200
 
201
 
202
 
 
267
 
268
  with gr.Column():
269
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Editing setting (SD)</p>""")
270
+ tgt_prompt = gr.Textbox(value="text prompt", label="Editing: Text prompt", interactive= True )
271
  with gr.Accordion(label="Advanced settings", open=False):
272
  slider2 = gr.Slider(0, 20, step=1, label = 'mask id', visible=False)
 
273
  guidance_scale = gr.Textbox(value="5", label="Editing: CFG guidance scale", interactive= True )
274
  num_sampling_steps = gr.Number(value="20", label="Editing: Sampling steps", interactive= True )
275
  edge_thickness = gr.Number(value="10", label="Editing: Edge thickness", interactive= True )
 
339
  slider2
340
  ],
341
  outputs = [canvas_text_edit],queue=True)
342
+
343
+ slider.release(slider_release,
344
+ inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
345
+ outputs= [canvas, label,tgt_prompt])
346
+
347
  slider.change(
348
  lambda x: x,
349
  inputs=[slider],