multimodalart HF staff commited on
Commit
c79060a
1 Parent(s): d5e120b

Make it cleaner and error if not square

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -13,6 +13,7 @@ from src.config.crop_config import CropConfig
13
  from src.config.argument_config import ArgumentConfig
14
  from src.config.inference_config import InferenceConfig
15
  import spaces
 
16
 
17
  # import gdown
18
  # folder_url = f"https://drive.google.com/drive/folders/1UtKgzKjFAOmZkhNK-OYT0caJ_w2XAnib"
@@ -43,6 +44,18 @@ def gpu_wrapped_execute_video(*args, **kwargs):
43
  def gpu_wrapped_execute_image(*args, **kwargs):
44
  return gradio_pipeline.execute_image(*args, **kwargs)
45
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  # assets
47
  title_md = "assets/gradio_title.md"
48
  example_portrait_dir = "assets/examples/source"
@@ -94,9 +107,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
94
  inputs=[video_input],
95
  cache_examples=False,
96
  )
97
- gr.Markdown(load_description("assets/gradio_description_animation.md"))
98
  with gr.Row():
99
- with gr.Accordion(open=False, label="Animation Options"):
 
100
  with gr.Row():
101
  flag_relative_input = gr.Checkbox(value=True, label="relative motion")
102
  flag_do_crop_input = gr.Checkbox(value=True, label="do crop")
@@ -182,6 +195,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
182
  inputs=image_input,
183
  outputs=[eye_retargeting_slider, lip_retargeting_slider, retargeting_input_image]
184
  )
 
 
 
 
 
185
 
186
  demo.launch(
187
  server_port=args.server_port,
 
13
  from src.config.argument_config import ArgumentConfig
14
  from src.config.inference_config import InferenceConfig
15
  import spaces
16
+ import cv2
17
 
18
  # import gdown
19
  # folder_url = f"https://drive.google.com/drive/folders/1UtKgzKjFAOmZkhNK-OYT0caJ_w2XAnib"
 
44
  def gpu_wrapped_execute_image(*args, **kwargs):
45
  return gradio_pipeline.execute_image(*args, **kwargs)
46
 
47
+ def is_square_video(video_path):
48
+ video = cv2.VideoCapture(video_path)
49
+
50
+ width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
51
+ height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
52
+
53
+ video.release()
54
+ if width != height:
55
+ raise gr.Error("Error: the video does not have a square aspect ratio. We currently only support square videos")
56
+
57
+ return gr.update(visible=True)
58
+
59
  # assets
60
  title_md = "assets/gradio_title.md"
61
  example_portrait_dir = "assets/examples/source"
 
107
  inputs=[video_input],
108
  cache_examples=False,
109
  )
 
110
  with gr.Row():
111
+ with gr.Accordion(open=False, label="Animation Instructions and Options"):
112
+ gr.Markdown(load_description("assets/gradio_description_animation.md"))
113
  with gr.Row():
114
  flag_relative_input = gr.Checkbox(value=True, label="relative motion")
115
  flag_do_crop_input = gr.Checkbox(value=True, label="do crop")
 
195
  inputs=image_input,
196
  outputs=[eye_retargeting_slider, lip_retargeting_slider, retargeting_input_image]
197
  )
198
+ video_input.upload(
199
+ fn=is_square_video,
200
+ inputs=video_input,
201
+ outputs=video_input
202
+ )
203
 
204
  demo.launch(
205
  server_port=args.server_port,