Spaces:
Paused
Paused
Commit
·
7917826
1
Parent(s):
e5b16fd
up
Browse files- README.md +7 -5
- app.py +78 -13
- video_processor.py +4 -4
README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.37.0
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: ReCamMaster
|
| 3 |
+
emoji: 🎥
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.37.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
header: mini
|
| 11 |
+
short_description: Reshoot existing videos using AI
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import shutil
|
|
| 6 |
import imageio
|
| 7 |
import logging
|
| 8 |
from pathlib import Path
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Import from our modules
|
| 11 |
from model_loader import ModelLoader, MODELS_ROOT_DIR
|
|
@@ -19,6 +21,16 @@ logger = logging.getLogger(__name__)
|
|
| 19 |
model_loader = ModelLoader()
|
| 20 |
video_processor = None
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def init_video_processor():
|
| 23 |
"""Initialize video processor"""
|
| 24 |
global video_processor
|
|
@@ -59,18 +71,22 @@ def generate_recammaster_video(
|
|
| 59 |
camera_type,
|
| 60 |
num_frames,
|
| 61 |
resolution,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
progress=gr.Progress()
|
| 63 |
):
|
| 64 |
"""Main function to generate video with ReCamMaster"""
|
| 65 |
|
| 66 |
if not model_loader.is_loaded:
|
| 67 |
-
return None, "Error: Models not loaded! Please load models first."
|
| 68 |
|
| 69 |
if not init_video_processor():
|
| 70 |
-
return None, "Error: Failed to initialize video processor."
|
| 71 |
|
| 72 |
if video_file is None:
|
| 73 |
-
return None, "Please upload a video file."
|
| 74 |
|
| 75 |
try:
|
| 76 |
# Create temporary directory for processing
|
|
@@ -84,6 +100,10 @@ def generate_recammaster_video(
|
|
| 84 |
# Parse resolution
|
| 85 |
width, height = map(int, resolution.split('x'))
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
# Extract frames
|
| 88 |
progress(0.2, desc="Extracting video frames...")
|
| 89 |
extracted_frames, fps = extract_frames_from_video(
|
|
@@ -101,7 +121,10 @@ def generate_recammaster_video(
|
|
| 101 |
camera_type,
|
| 102 |
num_frames=num_frames,
|
| 103 |
height=height,
|
| 104 |
-
width=width
|
|
|
|
|
|
|
|
|
|
| 105 |
)
|
| 106 |
|
| 107 |
# Save output video
|
|
@@ -117,23 +140,27 @@ def generate_recammaster_video(
|
|
| 117 |
progress(1.0, desc="Done!")
|
| 118 |
|
| 119 |
transformation_name = CAMERA_TRANSFORMATIONS.get(str(camera_type), "Unknown")
|
| 120 |
-
status_msg = f"Successfully generated video with '{transformation_name}' camera movement!"
|
| 121 |
|
| 122 |
-
return final_output_path, status_msg
|
| 123 |
|
| 124 |
except Exception as e:
|
| 125 |
logger.error(f"Error generating video: {str(e)}")
|
| 126 |
-
return None, f"Error: {str(e)}"
|
| 127 |
|
| 128 |
# Create Gradio interface
|
| 129 |
with gr.Blocks(title="ReCamMaster") as demo:
|
| 130 |
|
|
|
|
|
|
|
| 131 |
gr.Markdown(f"""
|
| 132 |
# ReCamMaster 🎥
|
| 133 |
|
| 134 |
This is a demo of [ReCamMaster](https://jianhongbai.github.io/ReCamMaster/), an amazing model that allows you to reshoot any video!
|
| 135 |
|
| 136 |
Due to the long generation times (~ 10 min) this space [should be duplicated](https://huggingface.co/spaces/jbilcke-hf/ReCamMaster?duplicate=true) to your own account for the best experience (please select at least a Nvidia L40S).
|
|
|
|
|
|
|
| 137 |
""")
|
| 138 |
|
| 139 |
with gr.Row():
|
|
@@ -162,17 +189,55 @@ with gr.Blocks(title="ReCamMaster") as demo:
|
|
| 162 |
gr.Markdown("### Step 3: Video Settings")
|
| 163 |
num_frames = gr.Slider(
|
| 164 |
minimum=17,
|
| 165 |
-
maximum=
|
| 166 |
-
value=
|
| 167 |
step=16,
|
| 168 |
label="Number of Frames",
|
| 169 |
-
info="Must be 16n+1 (17, 33, 49, 65, 81)"
|
| 170 |
)
|
| 171 |
resolution = gr.Dropdown(
|
| 172 |
choices=["832x480", "480x480", "480x832", "576x320", "320x576"],
|
| 173 |
value="832x480",
|
| 174 |
label="Resolution",
|
| 175 |
-
info="Output video resolution"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
)
|
| 177 |
|
| 178 |
# Generate button
|
|
@@ -186,8 +251,8 @@ with gr.Blocks(title="ReCamMaster") as demo:
|
|
| 186 |
# Event handlers
|
| 187 |
generate_btn.click(
|
| 188 |
fn=generate_recammaster_video,
|
| 189 |
-
inputs=[video_input, text_prompt, camera_type, num_frames, resolution],
|
| 190 |
-
outputs=[output_video, status_output]
|
| 191 |
)
|
| 192 |
|
| 193 |
if __name__ == "__main__":
|
|
|
|
| 6 |
import imageio
|
| 7 |
import logging
|
| 8 |
from pathlib import Path
|
| 9 |
+
import numpy as np
|
| 10 |
+
import random
|
| 11 |
|
| 12 |
# Import from our modules
|
| 13 |
from model_loader import ModelLoader, MODELS_ROOT_DIR
|
|
|
|
| 21 |
model_loader = ModelLoader()
|
| 22 |
video_processor = None
|
| 23 |
|
| 24 |
+
# Constants
|
| 25 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 26 |
+
|
| 27 |
+
# Check if running in demo mode
|
| 28 |
+
IS_DEMO = os.environ.get("IS_DEMO", "").lower() in ["true", "1", "yes", "on"]
|
| 29 |
+
|
| 30 |
+
# Set limits based on demo mode
|
| 31 |
+
MAX_INFERENCE_STEPS = 25 if IS_DEMO else 50
|
| 32 |
+
MAX_FRAMES = 49 if IS_DEMO else 81
|
| 33 |
+
|
| 34 |
def init_video_processor():
|
| 35 |
"""Initialize video processor"""
|
| 36 |
global video_processor
|
|
|
|
| 71 |
camera_type,
|
| 72 |
num_frames,
|
| 73 |
resolution,
|
| 74 |
+
seed,
|
| 75 |
+
randomize_seed,
|
| 76 |
+
num_inference_steps,
|
| 77 |
+
cfg_scale,
|
| 78 |
progress=gr.Progress()
|
| 79 |
):
|
| 80 |
"""Main function to generate video with ReCamMaster"""
|
| 81 |
|
| 82 |
if not model_loader.is_loaded:
|
| 83 |
+
return None, "Error: Models not loaded! Please load models first.", seed
|
| 84 |
|
| 85 |
if not init_video_processor():
|
| 86 |
+
return None, "Error: Failed to initialize video processor.", seed
|
| 87 |
|
| 88 |
if video_file is None:
|
| 89 |
+
return None, "Please upload a video file.", seed
|
| 90 |
|
| 91 |
try:
|
| 92 |
# Create temporary directory for processing
|
|
|
|
| 100 |
# Parse resolution
|
| 101 |
width, height = map(int, resolution.split('x'))
|
| 102 |
|
| 103 |
+
# Handle seed
|
| 104 |
+
current_seed = random.randint(0, MAX_SEED) if randomize_seed else int(seed)
|
| 105 |
+
logger.info(f"Using seed: {current_seed}")
|
| 106 |
+
|
| 107 |
# Extract frames
|
| 108 |
progress(0.2, desc="Extracting video frames...")
|
| 109 |
extracted_frames, fps = extract_frames_from_video(
|
|
|
|
| 121 |
camera_type,
|
| 122 |
num_frames=num_frames,
|
| 123 |
height=height,
|
| 124 |
+
width=width,
|
| 125 |
+
seed=current_seed,
|
| 126 |
+
num_inference_steps=num_inference_steps,
|
| 127 |
+
cfg_scale=cfg_scale
|
| 128 |
)
|
| 129 |
|
| 130 |
# Save output video
|
|
|
|
| 140 |
progress(1.0, desc="Done!")
|
| 141 |
|
| 142 |
transformation_name = CAMERA_TRANSFORMATIONS.get(str(camera_type), "Unknown")
|
| 143 |
+
status_msg = f"Successfully generated video with '{transformation_name}' camera movement! (Seed: {current_seed})"
|
| 144 |
|
| 145 |
+
return final_output_path, status_msg, current_seed
|
| 146 |
|
| 147 |
except Exception as e:
|
| 148 |
logger.error(f"Error generating video: {str(e)}")
|
| 149 |
+
return None, f"Error: {str(e)}", seed
|
| 150 |
|
| 151 |
# Create Gradio interface
|
| 152 |
with gr.Blocks(title="ReCamMaster") as demo:
|
| 153 |
|
| 154 |
+
demo_notice = "⚠️ **Demo Mode**: Limited to 49 frames and 25 inference steps for faster processing." if IS_DEMO else ""
|
| 155 |
+
|
| 156 |
gr.Markdown(f"""
|
| 157 |
# ReCamMaster 🎥
|
| 158 |
|
| 159 |
This is a demo of [ReCamMaster](https://jianhongbai.github.io/ReCamMaster/), an amazing model that allows you to reshoot any video!
|
| 160 |
|
| 161 |
Due to the long generation times (~ 10 min) this space [should be duplicated](https://huggingface.co/spaces/jbilcke-hf/ReCamMaster?duplicate=true) to your own account for the best experience (please select at least a Nvidia L40S).
|
| 162 |
+
|
| 163 |
+
{demo_notice}
|
| 164 |
""")
|
| 165 |
|
| 166 |
with gr.Row():
|
|
|
|
| 189 |
gr.Markdown("### Step 3: Video Settings")
|
| 190 |
num_frames = gr.Slider(
|
| 191 |
minimum=17,
|
| 192 |
+
maximum=MAX_FRAMES,
|
| 193 |
+
value=MAX_FRAMES,
|
| 194 |
step=16,
|
| 195 |
label="Number of Frames",
|
| 196 |
+
info=f"Must be 16n+1 (17, 33, 49{', 65, 81' if not IS_DEMO else ''})"
|
| 197 |
)
|
| 198 |
resolution = gr.Dropdown(
|
| 199 |
choices=["832x480", "480x480", "480x832", "576x320", "320x576"],
|
| 200 |
value="832x480",
|
| 201 |
label="Resolution",
|
| 202 |
+
info="Output video resolution",
|
| 203 |
+
|
| 204 |
+
# let's disable the resolution picker,
|
| 205 |
+
# right now the rest of the code doesn't support changing it, so..
|
| 206 |
+
visible=False
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
# Advanced settings
|
| 210 |
+
with gr.Group():
|
| 211 |
+
gr.Markdown("### Step 4: Advanced Settings")
|
| 212 |
+
with gr.Row():
|
| 213 |
+
seed = gr.Slider(
|
| 214 |
+
label="Seed",
|
| 215 |
+
minimum=0,
|
| 216 |
+
maximum=MAX_SEED,
|
| 217 |
+
step=1,
|
| 218 |
+
value=0,
|
| 219 |
+
interactive=True
|
| 220 |
+
)
|
| 221 |
+
randomize_seed = gr.Checkbox(
|
| 222 |
+
label="Randomize seed",
|
| 223 |
+
value=True,
|
| 224 |
+
interactive=True
|
| 225 |
+
)
|
| 226 |
+
num_inference_steps = gr.Slider(
|
| 227 |
+
minimum=10,
|
| 228 |
+
maximum=MAX_INFERENCE_STEPS,
|
| 229 |
+
value=min(30, MAX_INFERENCE_STEPS),
|
| 230 |
+
step=1,
|
| 231 |
+
label="Inference Steps",
|
| 232 |
+
info=f"More steps = higher quality but slower{' (Demo mode: limited to 25)' if IS_DEMO else ''}"
|
| 233 |
+
)
|
| 234 |
+
cfg_scale = gr.Slider(
|
| 235 |
+
minimum=0.0,
|
| 236 |
+
maximum=8.0,
|
| 237 |
+
value=5.0,
|
| 238 |
+
step=0.5,
|
| 239 |
+
label="CFG Scale",
|
| 240 |
+
info="Controls adherence to prompt"
|
| 241 |
)
|
| 242 |
|
| 243 |
# Generate button
|
|
|
|
| 251 |
# Event handlers
|
| 252 |
generate_btn.click(
|
| 253 |
fn=generate_recammaster_video,
|
| 254 |
+
inputs=[video_input, text_prompt, camera_type, num_frames, resolution, seed, randomize_seed, num_inference_steps, cfg_scale],
|
| 255 |
+
outputs=[output_video, status_output, seed]
|
| 256 |
)
|
| 257 |
|
| 258 |
if __name__ == "__main__":
|
video_processor.py
CHANGED
|
@@ -94,7 +94,7 @@ class VideoProcessor:
|
|
| 94 |
|
| 95 |
return camera_tensor
|
| 96 |
|
| 97 |
-
def process_video(self, video_path, text_prompt, cam_type, num_frames=81, height=480, width=832):
|
| 98 |
"""Process video through ReCamMaster model"""
|
| 99 |
|
| 100 |
# Load video frames
|
|
@@ -112,9 +112,9 @@ class VideoProcessor:
|
|
| 112 |
height=height,
|
| 113 |
width=width,
|
| 114 |
num_frames=num_frames,
|
| 115 |
-
cfg_scale=
|
| 116 |
-
num_inference_steps=
|
| 117 |
-
seed=
|
| 118 |
tiled=True
|
| 119 |
)
|
| 120 |
|
|
|
|
| 94 |
|
| 95 |
return camera_tensor
|
| 96 |
|
| 97 |
+
def process_video(self, video_path, text_prompt, cam_type, num_frames=81, height=480, width=832, seed=0, num_inference_steps=50, cfg_scale=5.0):
|
| 98 |
"""Process video through ReCamMaster model"""
|
| 99 |
|
| 100 |
# Load video frames
|
|
|
|
| 112 |
height=height,
|
| 113 |
width=width,
|
| 114 |
num_frames=num_frames,
|
| 115 |
+
cfg_scale=cfg_scale,
|
| 116 |
+
num_inference_steps=num_inference_steps,
|
| 117 |
+
seed=seed,
|
| 118 |
tiled=True
|
| 119 |
)
|
| 120 |
|