Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,6 +47,8 @@ def calculate_resize_dimensions(width, height, max_width=1024):
|
|
| 47 |
aspect_ratio = height / width
|
| 48 |
new_width = max_width
|
| 49 |
new_height = int(max_width * aspect_ratio)
|
|
|
|
|
|
|
| 50 |
return new_width, new_height
|
| 51 |
|
| 52 |
def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True)):
|
|
@@ -98,28 +100,34 @@ def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True))
|
|
| 98 |
# Generate initial output video
|
| 99 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 100 |
temp_path = f"output_{timestamp}_temp.mp4"
|
| 101 |
-
|
| 102 |
|
| 103 |
-
#
|
| 104 |
export_to_video(video.frames[0], temp_path, fps=8)
|
| 105 |
|
| 106 |
-
#
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
-
return
|
| 123 |
|
| 124 |
# Set up Gradio UI
|
| 125 |
with gr.Blocks(analytics_enabled=False) as demo:
|
|
|
|
| 47 |
aspect_ratio = height / width
|
| 48 |
new_width = max_width
|
| 49 |
new_height = int(max_width * aspect_ratio)
|
| 50 |
+
# Make height even number for video encoding
|
| 51 |
+
new_height = new_height - (new_height % 2)
|
| 52 |
return new_width, new_height
|
| 53 |
|
| 54 |
def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 100 |
# Generate initial output video
|
| 101 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 102 |
temp_path = f"output_{timestamp}_temp.mp4"
|
| 103 |
+
final_path = f"output_{timestamp}.mp4"
|
| 104 |
|
| 105 |
+
# First export the original video
|
| 106 |
export_to_video(video.frames[0], temp_path, fps=8)
|
| 107 |
|
| 108 |
+
# Then resize it with moviepy
|
| 109 |
+
try:
|
| 110 |
+
video_clip = VideoFileClip(temp_path)
|
| 111 |
+
resized_clip = video_clip.resize(width=target_width, height=target_height)
|
| 112 |
+
resized_clip.write_videofile(
|
| 113 |
+
final_path,
|
| 114 |
+
codec='libx264',
|
| 115 |
+
fps=8,
|
| 116 |
+
preset='medium',
|
| 117 |
+
ffmpeg_params=['-crf', '23'],
|
| 118 |
+
verbose=False,
|
| 119 |
+
logger=None
|
| 120 |
+
)
|
| 121 |
+
finally:
|
| 122 |
+
# Make sure we clean up the clips
|
| 123 |
+
if 'video_clip' in locals():
|
| 124 |
+
video_clip.close()
|
| 125 |
+
if 'resized_clip' in locals():
|
| 126 |
+
resized_clip.close()
|
| 127 |
+
if os.path.exists(temp_path):
|
| 128 |
+
os.remove(temp_path)
|
| 129 |
|
| 130 |
+
return final_path
|
| 131 |
|
| 132 |
# Set up Gradio UI
|
| 133 |
with gr.Blocks(analytics_enabled=False) as demo:
|