Spaces:
Running
on
Zero
Running
on
Zero
fix bugs
Browse files
app.py
CHANGED
@@ -52,15 +52,28 @@ class AnimateController:
|
|
52 |
img_path = os.path.join(self.savedir, "input_image.png")
|
53 |
pil_image.save(img_path)
|
54 |
self.image_resolution = pil_image.size
|
55 |
-
|
|
|
56 |
if center_crop:
|
57 |
-
|
58 |
-
aspect_ratio =
|
59 |
-
if aspect_ratio >
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
@spaces.GPU
|
66 |
def animate(
|
@@ -180,7 +193,7 @@ class AnimateController:
|
|
180 |
f.write(json_str)
|
181 |
f.write("\n\n")
|
182 |
|
183 |
-
return gr.Video
|
184 |
|
185 |
|
186 |
controller = AnimateController()
|
@@ -198,7 +211,7 @@ def ui():
|
|
198 |
with gr.Column(variant="panel"):
|
199 |
gr.Markdown(
|
200 |
"""
|
201 |
-
- Input image can be specified using the "Input Image
|
202 |
- Input image can be resized and/or center cropped to a given resolution by adjusting the "Width" and "Height" sliders. It is recommended to use the same resolution as the training resolution (256x256).
|
203 |
- After setting the input image path or changed the width/height of the input image, press the "Preview" button to visualize the resized input image.
|
204 |
"""
|
@@ -230,7 +243,7 @@ def ui():
|
|
230 |
|
231 |
seed_textbox = gr.Textbox(label="Seed", value=-1)
|
232 |
seed_button = gr.Button(value="\U0001F3B2", elem_classes="toolbutton")
|
233 |
-
seed_button.click(fn=lambda: gr.Textbox
|
234 |
|
235 |
|
236 |
|
@@ -238,7 +251,7 @@ def ui():
|
|
238 |
|
239 |
with gr.Column():
|
240 |
with gr.Row():
|
241 |
-
input_image_path = gr.Textbox(label="Input Image
|
242 |
preview_button = gr.Button(value="Preview")
|
243 |
|
244 |
with gr.Row():
|
@@ -273,7 +286,7 @@ def ui():
|
|
273 |
pil_image = pil_image.crop((left, top, right, bottom))
|
274 |
|
275 |
pil_image = pil_image.resize((width_slider, height_slider))
|
276 |
-
return gr.Image
|
277 |
|
278 |
preview_button.click(fn=update_and_resize_image, inputs=[input_image_path, height_slider, width_slider, center_crop], outputs=[input_image])
|
279 |
input_image_path.submit(fn=update_and_resize_image, inputs=[input_image_path, height_slider, width_slider, center_crop], outputs=[input_image])
|
|
|
52 |
img_path = os.path.join(self.savedir, "input_image.png")
|
53 |
pil_image.save(img_path)
|
54 |
self.image_resolution = pil_image.size
|
55 |
+
|
56 |
+
original_width, original_height = pil_image.size
|
57 |
if center_crop:
|
58 |
+
crop_aspect_ratio = width_slider / height_slider
|
59 |
+
aspect_ratio = original_width / original_height
|
60 |
+
if aspect_ratio > crop_aspect_ratio:
|
61 |
+
new_width = int(crop_aspect_ratio * original_height)
|
62 |
+
left = (original_width - new_width) / 2
|
63 |
+
top = 0
|
64 |
+
right = left + new_width
|
65 |
+
bottom = original_height
|
66 |
+
pil_image = pil_image.crop((left, top, right, bottom))
|
67 |
+
elif aspect_ratio < crop_aspect_ratio:
|
68 |
+
new_height = int(original_width / crop_aspect_ratio)
|
69 |
+
top = (original_height - new_height) / 2
|
70 |
+
left = 0
|
71 |
+
right = original_width
|
72 |
+
bottom = top + new_height
|
73 |
+
pil_image = pil_image.crop((left, top, right, bottom))
|
74 |
+
|
75 |
+
pil_image = pil_image.resize((width_slider, height_slider))
|
76 |
+
return gr.Textbox(value=img_path), gr.Image(value=np.array(pil_image))
|
77 |
|
78 |
@spaces.GPU
|
79 |
def animate(
|
|
|
193 |
f.write(json_str)
|
194 |
f.write("\n\n")
|
195 |
|
196 |
+
return gr.Video(value=save_sample_path)
|
197 |
|
198 |
|
199 |
controller = AnimateController()
|
|
|
211 |
with gr.Column(variant="panel"):
|
212 |
gr.Markdown(
|
213 |
"""
|
214 |
+
- Input image can be specified using the "Input Image URL" text box or uploaded by clicking or dragging the image to the "Input Image" box. The uploaded image will be temporarily stored in the "samples/Gradio" folder under the project root folder.
|
215 |
- Input image can be resized and/or center cropped to a given resolution by adjusting the "Width" and "Height" sliders. It is recommended to use the same resolution as the training resolution (256x256).
|
216 |
- After setting the input image path or changed the width/height of the input image, press the "Preview" button to visualize the resized input image.
|
217 |
"""
|
|
|
243 |
|
244 |
seed_textbox = gr.Textbox(label="Seed", value=-1)
|
245 |
seed_button = gr.Button(value="\U0001F3B2", elem_classes="toolbutton")
|
246 |
+
seed_button.click(fn=lambda: gr.Textbox(value=random.randint(1, 1e8)), inputs=[], outputs=[seed_textbox])
|
247 |
|
248 |
|
249 |
|
|
|
251 |
|
252 |
with gr.Column():
|
253 |
with gr.Row():
|
254 |
+
input_image_path = gr.Textbox(label="Input Image URL", lines=1, scale=10, info="Press Enter or the Preview button to confirm the input image.")
|
255 |
preview_button = gr.Button(value="Preview")
|
256 |
|
257 |
with gr.Row():
|
|
|
286 |
pil_image = pil_image.crop((left, top, right, bottom))
|
287 |
|
288 |
pil_image = pil_image.resize((width_slider, height_slider))
|
289 |
+
return gr.Image(value=np.array(pil_image))
|
290 |
|
291 |
preview_button.click(fn=update_and_resize_image, inputs=[input_image_path, height_slider, width_slider, center_crop], outputs=[input_image])
|
292 |
input_image_path.submit(fn=update_and_resize_image, inputs=[input_image_path, height_slider, width_slider, center_crop], outputs=[input_image])
|