Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,71 +68,66 @@ def process_video(
|
|
| 68 |
manual_height,
|
| 69 |
manual_width,
|
| 70 |
guidance_scale,
|
| 71 |
-
progress=gr.Progress()
|
| 72 |
):
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
original_width
|
| 82 |
-
|
| 83 |
-
# Calculate dimensions
|
| 84 |
-
if auto_resize:
|
| 85 |
-
width, height = calculate_resolution(original_width, original_height)
|
| 86 |
-
gr.Info(f"Auto-resized from {original_width}x{original_height} to {width}x{height} (preserving aspect ratio)")
|
| 87 |
-
else:
|
| 88 |
-
width, height = manual_width, manual_height
|
| 89 |
-
if abs((original_width/original_height) - (width/height)) > 0.1:
|
| 90 |
-
gr.Warning(f"Output aspect ratio ({width}x{height}) differs significantly from input ({original_width}x{original_height}). Video may appear stretched.")
|
| 91 |
else:
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
#
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
# Create Gradio interface
|
| 138 |
with gr.Blocks(title="Lucy Edit - Video Editing with Text") as demo:
|
|
|
|
| 68 |
manual_height,
|
| 69 |
manual_width,
|
| 70 |
guidance_scale,
|
| 71 |
+
progress=gr.Progress(track_tqdm=True)
|
| 72 |
):
|
| 73 |
+
# Load and preprocess video
|
| 74 |
+
progress(0.2, desc="Loading video...")
|
| 75 |
+
|
| 76 |
+
# Get video dimensions
|
| 77 |
+
temp_video = load_video(video_path)
|
| 78 |
+
print(len(temp_video))
|
| 79 |
+
if temp_video and len(temp_video) > 0:
|
| 80 |
+
original_width, original_height = temp_video[0].size
|
| 81 |
|
| 82 |
+
# Calculate dimensions
|
| 83 |
+
if auto_resize:
|
| 84 |
+
width, height = calculate_resolution(original_width, original_height)
|
| 85 |
+
gr.Info(f"Auto-resized from {original_width}x{original_height} to {width}x{height} (preserving aspect ratio)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
else:
|
| 87 |
+
width, height = manual_width, manual_height
|
| 88 |
+
if abs((original_width/original_height) - (width/height)) > 0.1:
|
| 89 |
+
gr.Warning(f"Output aspect ratio ({width}x{height}) differs significantly from input ({original_width}x{original_height}). Video may appear stretched.")
|
| 90 |
+
else:
|
| 91 |
+
raise gr.Error("Could not load video or video is empty")
|
| 92 |
+
|
| 93 |
+
# Convert video function
|
| 94 |
+
def convert_video(video: List[Image.Image]) -> List[Image.Image]:
|
| 95 |
+
# Ensure we don't exceed the video length
|
| 96 |
+
frames_to_load = min(len(video), num_frames)
|
| 97 |
+
video_frames = video[:frames_to_load]
|
| 98 |
+
# Resize frames
|
| 99 |
+
video_frames = [frame.resize((width, height)) for frame in video_frames]
|
| 100 |
+
return video_frames
|
| 101 |
+
|
| 102 |
+
# Load video from file path
|
| 103 |
+
video = load_video(video_path, convert_method=convert_video)
|
| 104 |
+
|
| 105 |
+
# Ensure we have the right number of frames
|
| 106 |
+
if len(video) < num_frames:
|
| 107 |
+
gr.Warning(f"Video has only {len(video)} frames, using all available frames.")
|
| 108 |
+
num_frames = len(video)
|
| 109 |
+
|
| 110 |
+
# Generate edited video
|
| 111 |
+
progress(0.5, desc="Generating edited video...")
|
| 112 |
+
output = pipe(
|
| 113 |
+
prompt=prompt,
|
| 114 |
+
video=video,
|
| 115 |
+
negative_prompt=negative_prompt,
|
| 116 |
+
height=height,
|
| 117 |
+
width=width,
|
| 118 |
+
num_frames=num_frames,
|
| 119 |
+
guidance_scale=guidance_scale,
|
| 120 |
+
).frames[0]
|
| 121 |
+
|
| 122 |
+
# Export to temporary file
|
| 123 |
+
progress(0.9, desc="Exporting video...")
|
| 124 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as tmp_file:
|
| 125 |
+
output_path = tmp_file.name
|
| 126 |
+
|
| 127 |
+
export_to_video(output, output_path, fps=24)
|
| 128 |
+
|
| 129 |
+
progress(1.0, desc="Complete!")
|
| 130 |
+
return output_path
|
| 131 |
|
| 132 |
# Create Gradio interface
|
| 133 |
with gr.Blocks(title="Lucy Edit - Video Editing with Text") as demo:
|