niulx commited on
Commit
0f8c3e9
1 Parent(s): 38cec45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -28
app.py CHANGED
@@ -36,27 +36,6 @@ def create_segmentation(mask_np_list):
36
  segmentation = Image.fromarray(np.uint8(segmentation*255))
37
  return segmentation
38
 
39
- def load_mask_ui(input_folder="example_tmp",load_edit = False):
40
- if not load_edit:
41
- mask_list, mask_label_list = load_mask(input_folder)
42
- else:
43
- mask_list, mask_label_list = load_mask_edit(input_folder)
44
-
45
- mask_np_list = []
46
- for m in mask_list:
47
- mask_np_list. append( m.cpu().numpy())
48
-
49
- return mask_np_list, mask_label_list
50
-
51
- def load_image_ui(load_edit, input_folder="example_tmp"):
52
-
53
- image, mask_np_list, mask_label_list = load_mask_ui(input_folder, load_edit = load_edit)
54
- #image = image.convert('RGB')
55
- segmentation = create_segmentation(mask_np_list)
56
- max_val = len(mask_np_list)-1
57
- sliderup = gr.Slider(value = 0, minimum=0, maximum=max_val, step=1, interactive=True)
58
- return image, segmentation, mask_np_list, mask_label_list, image, sliderup, sliderup
59
-
60
 
61
 
62
  def run_segmentation_wrapper(image):
@@ -65,7 +44,7 @@ def run_segmentation_wrapper(image):
65
  segmentation = create_segmentation(mask_np_list)
66
  print("!!", len(mask_np_list))
67
  max_val = len(mask_np_list)-1
68
- sliderup = gr.Slider(value = 0, minimum=0, maximum=max_val, step=1, interactive=True)
69
  return image, segmentation, mask_np_list, mask_label_list, image, sliderup, sliderup , 'Segmentation finish. Select mask id and move to the next step.'
70
 
71
 
@@ -123,6 +102,8 @@ def slider_release(index, image, mask_np_list_updated, mask_label_list):
123
  segmentation = create_segmentation(mask_np_list_updated)
124
  new_image = transparent_paste_with_mask(image, segmentation, mask_np, transparency = TRANSPARENCY)
125
  return new_image, mask_label
 
 
126
 
127
  def save_as_orig_mask(mask_np_list_updated, mask_label_list, input_folder="example_tmp"):
128
  print(mask_np_list_updated)
@@ -202,17 +183,14 @@ with gr.Blocks() as demo:
202
  mask_np_list_updated = mask_np_list
203
  with gr.Column():
204
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Edit Mask (Optional)</p>""")
205
- slider = gr.Slider(0, 20, step=1, label = 'mask id', interactive=False)
206
  label = gr.Text(label='label')
207
  slider.release(slider_release,
208
  inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
209
  outputs= [canvas, label]
210
  )
211
 
212
-
213
-
214
-
215
-
216
 
217
  with gr.Tab(label="2 Optimization"):
218
  with gr.Row():
@@ -303,7 +281,7 @@ with gr.Blocks() as demo:
303
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Editing setting (SD)</p>""")
304
 
305
  tgt_prompt = gr.Textbox(value="White bag", label="Editing: Text prompt", interactive= True )
306
- slider2 = gr.Slider(0, 20, step=1, label = 'mask id', interactive=False)
307
  #tgt_index = gr.Number(value="0", label="Editing: Object index", interactive= True )
308
  guidance_scale = gr.Textbox(value="6", label="Editing: CFG guidance scale", interactive= True )
309
  num_sampling_steps = gr.Number(value="50", label="Editing: Sampling steps", interactive= True )
 
36
  segmentation = Image.fromarray(np.uint8(segmentation*255))
37
  return segmentation
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
  def run_segmentation_wrapper(image):
 
44
  segmentation = create_segmentation(mask_np_list)
45
  print("!!", len(mask_np_list))
46
  max_val = len(mask_np_list)-1
47
+ sliderup = gr.Slider(value = 0, minimum=0, maximum=max_val, step=1, visible=True)
48
  return image, segmentation, mask_np_list, mask_label_list, image, sliderup, sliderup , 'Segmentation finish. Select mask id and move to the next step.'
49
 
50
 
 
102
  segmentation = create_segmentation(mask_np_list_updated)
103
  new_image = transparent_paste_with_mask(image, segmentation, mask_np, transparency = TRANSPARENCY)
104
  return new_image, mask_label
105
+ def image_change():
106
+ return gr.Slider(value = 0, minimum=0, maximum=1, step=1, visible=False)
107
 
108
  def save_as_orig_mask(mask_np_list_updated, mask_label_list, input_folder="example_tmp"):
109
  print(mask_np_list_updated)
 
183
  mask_np_list_updated = mask_np_list
184
  with gr.Column():
185
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Edit Mask (Optional)</p>""")
186
+ slider = gr.Slider(0, 20, step=1, label = 'mask id', visible=False)
187
  label = gr.Text(label='label')
188
  slider.release(slider_release,
189
  inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
190
  outputs= [canvas, label]
191
  )
192
 
193
+ canvas.upload(image_change, inputs=[], outputs=[slider])
 
 
 
194
 
195
  with gr.Tab(label="2 Optimization"):
196
  with gr.Row():
 
281
  gr.Markdown("""<p style="text-align: center; font-size: 20px">Editing setting (SD)</p>""")
282
 
283
  tgt_prompt = gr.Textbox(value="White bag", label="Editing: Text prompt", interactive= True )
284
+ slider2 = gr.Slider(0, 20, step=1, label = 'mask id', visible=False)
285
  #tgt_index = gr.Number(value="0", label="Editing: Object index", interactive= True )
286
  guidance_scale = gr.Textbox(value="6", label="Editing: CFG guidance scale", interactive= True )
287
  num_sampling_steps = gr.Number(value="50", label="Editing: Sampling steps", interactive= True )