Spaces:
Sleeping
Sleeping
Linoy Tsaban
commited on
Commit
•
a6a2299
1
Parent(s):
672784d
Update app.py
Browse filescrop & resize input image on .upload
app.py
CHANGED
@@ -192,7 +192,16 @@ def randomize_seed_fn(seed, randomize_seed):
|
|
192 |
torch.manual_seed(seed)
|
193 |
return seed
|
194 |
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
|
198 |
def get_example():
|
@@ -716,7 +725,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
716 |
outputs = [do_inversion],
|
717 |
queue = False)
|
718 |
# Automatically start inverting upon input_image change
|
719 |
-
input_image.upload(
|
720 |
fn = reset_do_inversion,
|
721 |
outputs = [do_inversion],
|
722 |
queue = False).then(fn = caption_image,
|
|
|
192 |
torch.manual_seed(seed)
|
193 |
return seed
|
194 |
|
195 |
+
def crop_image(image):
|
196 |
+
h, w, c = image.shape
|
197 |
+
if h < w:
|
198 |
+
offset = (w - h) // 2
|
199 |
+
image = image[:, offset:offset + h]
|
200 |
+
elif w < h:
|
201 |
+
offset = (h - w) // 2
|
202 |
+
image = image[offset:offset + w]
|
203 |
+
image = np.array(Image.fromarray(image).resize((512, 512)))
|
204 |
+
return image
|
205 |
|
206 |
|
207 |
def get_example():
|
|
|
725 |
outputs = [do_inversion],
|
726 |
queue = False)
|
727 |
# Automatically start inverting upon input_image change
|
728 |
+
input_image.upload(fn = crop_image, inputs = [input_image], outputs = [input_image],queue=False).then(
|
729 |
fn = reset_do_inversion,
|
730 |
outputs = [do_inversion],
|
731 |
queue = False).then(fn = caption_image,
|