Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -66,11 +66,23 @@ def resize_image(input_image, resolution):
|
|
66 |
img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
|
67 |
return img
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
def process(original_image, input_mask, prompt, negative_prompt, blended, invert_mask, control_strength, seed, randomize_seed, guidance_scale, num_inference_steps):
|
70 |
if original_image is None:
|
71 |
raise gr.Error('Please upload the input image')
|
72 |
if input_mask is None:
|
73 |
raise gr.Error("Please upload a white-black Mask image")
|
|
|
|
|
|
|
74 |
|
75 |
H, W = original_image.shape[:2]
|
76 |
original_mask = cv2.resize(input_mask, (W, H))
|
@@ -129,21 +141,6 @@ with gr.Blocks() as demo:
|
|
129 |
|
130 |
with gr.Column():
|
131 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True)
|
132 |
-
|
133 |
-
# once user upload an image, the original image is stored in `original_image`
|
134 |
-
def store_img(img):
|
135 |
-
# image upload is too slow
|
136 |
-
if min(img.shape[0], img.shape[1]) > 1024:
|
137 |
-
img = resize_image(img, 1024)
|
138 |
-
if max(img.shape[0], img.shape[1])*1.0/min(img.shape[0], img.shape[1])>2.0:
|
139 |
-
raise gr.Error('image aspect ratio cannot be larger than 2.0')
|
140 |
-
return img, None # when new image is uploaded, `selected_points` should be empty
|
141 |
-
|
142 |
-
original_image.upload(
|
143 |
-
store_img,
|
144 |
-
[original_image],
|
145 |
-
[original_image]
|
146 |
-
)
|
147 |
|
148 |
inputs = [original_image, input_mask, prompt, negative_prompt, blended, invert_mask, control_strength, seed, randomize_seed, guidance_scale, num_inference_steps]
|
149 |
run_button.click(fn=process, inputs=inputs, outputs=[result_gallery])
|
|
|
66 |
img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)
|
67 |
return img
|
68 |
|
69 |
+
# once user upload an image, the original image is stored in `original_image`
|
70 |
+
def store_img(img):
|
71 |
+
# image upload is too slow
|
72 |
+
if min(img.shape[0], img.shape[1]) > 1024:
|
73 |
+
img = resize_image(img, 1024)
|
74 |
+
if max(img.shape[0], img.shape[1])*1.0/min(img.shape[0], img.shape[1])>2.0:
|
75 |
+
raise gr.Error('image aspect ratio cannot be larger than 2.0')
|
76 |
+
return img
|
77 |
+
|
78 |
def process(original_image, input_mask, prompt, negative_prompt, blended, invert_mask, control_strength, seed, randomize_seed, guidance_scale, num_inference_steps):
|
79 |
if original_image is None:
|
80 |
raise gr.Error('Please upload the input image')
|
81 |
if input_mask is None:
|
82 |
raise gr.Error("Please upload a white-black Mask image")
|
83 |
+
#resizing input image and mask of the object
|
84 |
+
original_image = store_img(original_image)
|
85 |
+
input_mask = store_img(input_mask)
|
86 |
|
87 |
H, W = original_image.shape[:2]
|
88 |
original_mask = cv2.resize(input_mask, (W, H))
|
|
|
141 |
|
142 |
with gr.Column():
|
143 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
inputs = [original_image, input_mask, prompt, negative_prompt, blended, invert_mask, control_strength, seed, randomize_seed, guidance_scale, num_inference_steps]
|
146 |
run_button.click(fn=process, inputs=inputs, outputs=[result_gallery])
|