Spaces:
Runtime error
Runtime error
Update app.py
Browse filesstep2 and step3 together
app.py
CHANGED
@@ -119,7 +119,7 @@ def slider_release(index, image, mask_np_list_updated, mask_label_list):
|
|
119 |
gr.Info('Edit '+ mask_label)
|
120 |
return new_image, mask_label, mask_prompt
|
121 |
def image_change():
|
122 |
-
return gr.Slider(value = 0, minimum=0, maximum=1, step=1, visible=False)
|
123 |
|
124 |
def save_as_orig_mask(mask_np_list_updated, mask_label_list, input_folder="example_tmp"):
|
125 |
print(mask_np_list_updated)
|
@@ -188,7 +188,7 @@ with gr.Blocks() as demo:
|
|
188 |
with gr.Row():
|
189 |
gr.Markdown("""# D-Edit""")
|
190 |
|
191 |
-
|
192 |
with gr.Row():
|
193 |
with gr.Column():
|
194 |
canvas = gr.Image(value = None, type="numpy", label="Show Mask", show_label=True, height=LENGTH, width=LENGTH, interactive=True)
|
@@ -211,7 +211,6 @@ with gr.Blocks() as demo:
|
|
211 |
|
212 |
|
213 |
|
214 |
-
#with gr.Tab(label="2 Optimization"):
|
215 |
|
216 |
result_info = gr.Text(label="Response")
|
217 |
|
@@ -229,7 +228,6 @@ with gr.Blocks() as demo:
|
|
229 |
train_batch_size = gr.Number(value="20", label="Batch size", interactive= True )
|
230 |
gradient_accumulation_steps=gr.Number(value="2", label="Gradient accumulation", interactive= True )
|
231 |
|
232 |
-
add_button = gr.Button("Step 2. Run optimization")
|
233 |
def run_optimization_wrapper (
|
234 |
mask_np_list,
|
235 |
mask_label_list,
|
@@ -259,11 +257,11 @@ with gr.Blocks() as demo:
|
|
259 |
)
|
260 |
run_optimization()
|
261 |
gr.Info("Optimization Finished! Move to the next step.")
|
262 |
-
return "Optimization finished! Move to the next step."
|
263 |
except Exception as e:
|
264 |
print(e)
|
265 |
gr.Error("e")
|
266 |
-
return "Error: use a smaller batch size or try latter."
|
267 |
|
268 |
|
269 |
|
@@ -283,7 +281,7 @@ with gr.Blocks() as demo:
|
|
283 |
edge_thickness = gr.Number(value="10", label="Editing: Edge thickness", interactive= True )
|
284 |
strength = gr.Textbox(value="0.5", label="Editing: Mask strength", interactive= True )
|
285 |
|
286 |
-
|
287 |
def run_edit_text_wrapper(
|
288 |
mask_np_list,
|
289 |
mask_label_list,
|
@@ -319,36 +317,41 @@ with gr.Blocks() as demo:
|
|
319 |
|
320 |
|
321 |
|
|
|
|
|
|
|
|
|
322 |
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
|
|
352 |
|
353 |
slider.release(slider_release,
|
354 |
inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
|
|
|
119 |
gr.Info('Edit '+ mask_label)
|
120 |
return new_image, mask_label, mask_prompt
|
121 |
def image_change():
|
122 |
+
return gr.Slider(value = 0, minimum=0, maximum=1, step=1, visible=False)
|
123 |
|
124 |
def save_as_orig_mask(mask_np_list_updated, mask_label_list, input_folder="example_tmp"):
|
125 |
print(mask_np_list_updated)
|
|
|
188 |
with gr.Row():
|
189 |
gr.Markdown("""# D-Edit""")
|
190 |
|
191 |
+
if 1:
|
192 |
with gr.Row():
|
193 |
with gr.Column():
|
194 |
canvas = gr.Image(value = None, type="numpy", label="Show Mask", show_label=True, height=LENGTH, width=LENGTH, interactive=True)
|
|
|
211 |
|
212 |
|
213 |
|
|
|
214 |
|
215 |
result_info = gr.Text(label="Response")
|
216 |
|
|
|
228 |
train_batch_size = gr.Number(value="20", label="Batch size", interactive= True )
|
229 |
gradient_accumulation_steps=gr.Number(value="2", label="Gradient accumulation", interactive= True )
|
230 |
|
|
|
231 |
def run_optimization_wrapper (
|
232 |
mask_np_list,
|
233 |
mask_label_list,
|
|
|
257 |
)
|
258 |
run_optimization()
|
259 |
gr.Info("Optimization Finished! Move to the next step.")
|
260 |
+
return "Optimization finished! Move to the next step."#,gr.Button("Step 3. Run Editing",interactive = True)
|
261 |
except Exception as e:
|
262 |
print(e)
|
263 |
gr.Error("e")
|
264 |
+
return "Error: use a smaller batch size or try latter."#,gr.Button("Step 3. Run Editing",interactive = False)
|
265 |
|
266 |
|
267 |
|
|
|
281 |
edge_thickness = gr.Number(value="10", label="Editing: Edge thickness", interactive= True )
|
282 |
strength = gr.Textbox(value="0.5", label="Editing: Mask strength", interactive= True )
|
283 |
|
284 |
+
add_button = gr.Button("Step 2. Run Editing",interactive = False)
|
285 |
def run_edit_text_wrapper(
|
286 |
mask_np_list,
|
287 |
mask_label_list,
|
|
|
317 |
|
318 |
|
319 |
|
320 |
+
def run_total_wrapper(mask_np_list, mask_label_list, image_loaded, opt_flag, num_tokens, embedding_learning_rate, max_emb_train_steps, diffusion_model_learning_rate, max_diffusion_train_steps, train_batch_size, gradient_accumulation_steps, num_tokens_global, guidance_scale, num_sampling_steps, strength, edge_thickness, tgt_prompt, slider2):
|
321 |
+
result_info = run_optimization_wrapper(mask_np_list, mask_label_list, image_loaded, opt_flag, num_tokens, embedding_learning_rate, max_emb_train_steps, diffusion_model_learning_rate, max_diffusion_train_steps, train_batch_size, gradient_accumulation_steps)
|
322 |
+
canvas_text_edit = run_edit_text_wrapper(mask_np_list, mask_label_list, image_loaded, num_tokens_global, guidance_scale, num_sampling_steps, strength, edge_thickness, tgt_prompt, slider2)
|
323 |
+
return result_info, canvas_text_edit
|
324 |
|
325 |
+
|
326 |
+
add_button.click(
|
327 |
+
run_total_wrapper,
|
328 |
+
inputs=[
|
329 |
+
mask_np_list,
|
330 |
+
mask_label_list,
|
331 |
+
image_loaded,
|
332 |
+
opt_flag,
|
333 |
+
num_tokens,
|
334 |
+
embedding_learning_rate,
|
335 |
+
max_emb_train_steps,
|
336 |
+
diffusion_model_learning_rate,
|
337 |
+
max_diffusion_train_steps,
|
338 |
+
train_batch_size,
|
339 |
+
gradient_accumulation_steps,
|
340 |
+
num_tokens_global,
|
341 |
+
guidance_scale,
|
342 |
+
num_sampling_steps,
|
343 |
+
strength,
|
344 |
+
edge_thickness,
|
345 |
+
tgt_prompt,
|
346 |
+
slider2
|
347 |
+
],
|
348 |
+
outputs=[result_info, canvas_text_edit],
|
349 |
+
)
|
350 |
+
|
351 |
+
|
352 |
+
|
353 |
+
|
354 |
+
canvas.upload(image_change, inputs=[], outputs=[slider])
|
355 |
|
356 |
slider.release(slider_release,
|
357 |
inputs = [slider, image_loaded, mask_np_list_updated, mask_label_list],
|