Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,8 +33,9 @@ def get_video_dimension(filepath):
|
|
| 33 |
video = cv2.VideoCapture(filepath)
|
| 34 |
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 35 |
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
|
|
| 36 |
video.release()
|
| 37 |
-
return width, height
|
| 38 |
|
| 39 |
def resize_video(input_path, output_path, width):
|
| 40 |
# Load the video clip
|
|
@@ -59,9 +60,9 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 59 |
|
| 60 |
# Call the function to resize the video
|
| 61 |
video_path = resize_video(input_vid, resized_vid, width=512)
|
| 62 |
-
width, height = get_video_dimension(video_path)
|
| 63 |
|
| 64 |
-
print(f"{width} x {height}")
|
| 65 |
|
| 66 |
output_path = 'output/'
|
| 67 |
os.makedirs(output_path, exist_ok=True)
|
|
@@ -75,9 +76,9 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 75 |
os.remove(video_path_output)
|
| 76 |
|
| 77 |
if video_length > 12:
|
| 78 |
-
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{video_path}' --output_path '{output_path}' --width {width} --height {height} --video_length {video_length} --is_long_video"
|
| 79 |
else:
|
| 80 |
-
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{video_path}' --output_path '{output_path}' --width {width} --height {height} --video_length {video_length}"
|
| 81 |
subprocess.run(command, shell=True)
|
| 82 |
|
| 83 |
# Construct the video path
|
|
@@ -87,13 +88,18 @@ def run_inference(prompt, video_path, condition, video_length):
|
|
| 87 |
|
| 88 |
return "done", video_path_output
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
prompt = gr.Textbox(label="prompt")
|
| 94 |
video_path = gr.Video(source="upload", type="filepath")
|
| 95 |
-
condition = gr.
|
| 96 |
-
video_length = gr.Slider(label="
|
| 97 |
#seed = gr.Number(label="seed", value=42)
|
| 98 |
submit_btn = gr.Button("Submit")
|
| 99 |
video_res = gr.Video(label="result")
|
|
|
|
| 33 |
video = cv2.VideoCapture(filepath)
|
| 34 |
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 35 |
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 36 |
+
fps = int(video.get(cv2.CAP_PROP_FPS))
|
| 37 |
video.release()
|
| 38 |
+
return width, height, fps
|
| 39 |
|
| 40 |
def resize_video(input_path, output_path, width):
|
| 41 |
# Load the video clip
|
|
|
|
| 60 |
|
| 61 |
# Call the function to resize the video
|
| 62 |
video_path = resize_video(input_vid, resized_vid, width=512)
|
| 63 |
+
width, height, fps = get_video_dimension(video_path)
|
| 64 |
|
| 65 |
+
print(f"{width} x {height} | {fps}")
|
| 66 |
|
| 67 |
output_path = 'output/'
|
| 68 |
os.makedirs(output_path, exist_ok=True)
|
|
|
|
| 76 |
os.remove(video_path_output)
|
| 77 |
|
| 78 |
if video_length > 12:
|
| 79 |
+
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{video_path}' --output_path '{output_path}' --width {width} --height {height} --fps {fps} --video_length {video_length} --is_long_video"
|
| 80 |
else:
|
| 81 |
+
command = f"python inference.py --prompt '{prompt}' --condition '{condition}' --video_path '{video_path}' --output_path '{output_path}' --width {width} --height {height} --fps {fps} --video_length {video_length}"
|
| 82 |
subprocess.run(command, shell=True)
|
| 83 |
|
| 84 |
# Construct the video path
|
|
|
|
| 88 |
|
| 89 |
return "done", video_path_output
|
| 90 |
|
| 91 |
+
css="""
|
| 92 |
+
#col-container {max-width: 510px; margin-left: auto; margin-right: auto;}
|
| 93 |
+
"""
|
| 94 |
+
with gr.Blocks(css=css) as demo:
|
| 95 |
+
with gr.Column(col-container):
|
| 96 |
+
gr.Markdown("""
|
| 97 |
+
<h1 style="text-align: center;">ControlVideo</h1>
|
| 98 |
+
""")
|
| 99 |
prompt = gr.Textbox(label="prompt")
|
| 100 |
video_path = gr.Video(source="upload", type="filepath")
|
| 101 |
+
condition = gr.Dropdown(label="Condition", choices=["depth", "canny", "pose"], value="depth")
|
| 102 |
+
video_length = gr.Slider(label="Video length", info="How many frames do you want to process ?", minimum=1, maximum=12, step=1, value=2)
|
| 103 |
#seed = gr.Number(label="seed", value=42)
|
| 104 |
submit_btn = gr.Button("Submit")
|
| 105 |
video_res = gr.Video(label="result")
|