sachinkidzure commited on
Commit
97adb33
·
verified ·
1 Parent(s): 5182029

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -129,6 +129,21 @@ with gr.Blocks() as demo:
129
  with gr.Column():
130
  result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True)
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  inputs = [original_image, input_mask, prompt, negative_prompt, blended, invert_mask, control_strength, seed, randomize_seed, guidance_scale, num_inference_steps]
133
  run_button.click(fn=process, inputs=inputs, outputs=[result_gallery])
134
 
 
129
  with gr.Column():
130
  result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True)
131
 
132
+ # once user upload an image, the original image is stored in `original_image`
133
+ def store_img(img):
134
+ # image upload is too slow
135
+ if min(img.shape[0], img.shape[1]) > 1024:
136
+ img = resize_image(img, 1024)
137
+ if max(img.shape[0], img.shape[1])*1.0/min(img.shape[0], img.shape[1])>2.0:
138
+ raise gr.Error('image aspect ratio cannot be larger than 2.0')
139
+ return img, img, [], None # when new image is uploaded, `selected_points` should be empty
140
+
141
+ original_image.upload(
142
+ store_img,
143
+ [original_image],
144
+ [input_image, original_image, selected_points]
145
+ )
146
+
147
  inputs = [original_image, input_mask, prompt, negative_prompt, blended, invert_mask, control_strength, seed, randomize_seed, guidance_scale, num_inference_steps]
148
  run_button.click(fn=process, inputs=inputs, outputs=[result_gallery])
149