Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from transformers import T5EncoderModel, T5Tokenizer
|
|
| 9 |
from datetime import datetime
|
| 10 |
import random
|
| 11 |
from moviepy.editor import VideoFileClip
|
|
|
|
| 12 |
|
| 13 |
from huggingface_hub import hf_hub_download
|
| 14 |
|
|
@@ -59,9 +60,11 @@ def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True))
|
|
| 59 |
# Load and get original image dimensions
|
| 60 |
image = load_image(image_path)
|
| 61 |
original_width, original_height = image.size
|
|
|
|
| 62 |
|
| 63 |
# Calculate target dimensions maintaining aspect ratio
|
| 64 |
target_width, target_height = calculate_resize_dimensions(original_width, original_height)
|
|
|
|
| 65 |
|
| 66 |
lora_path = "checkpoints/"
|
| 67 |
weight_name = "orbit_left_lora_weights.safetensors" if orbit_type == "Left" else "orbit_up_lora_weights.safetensors"
|
|
@@ -105,25 +108,21 @@ def infer(image_path, prompt, orbit_type, progress=gr.Progress(track_tqdm=True))
|
|
| 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 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 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 |
|
|
|
|
| 9 |
from datetime import datetime
|
| 10 |
import random
|
| 11 |
from moviepy.editor import VideoFileClip
|
| 12 |
+
import ffmpeg
|
| 13 |
|
| 14 |
from huggingface_hub import hf_hub_download
|
| 15 |
|
|
|
|
| 60 |
# Load and get original image dimensions
|
| 61 |
image = load_image(image_path)
|
| 62 |
original_width, original_height = image.size
|
| 63 |
+
print(f"IMAGE INPUT SIZE: {original_width} x {original_height}")
|
| 64 |
|
| 65 |
# Calculate target dimensions maintaining aspect ratio
|
| 66 |
target_width, target_height = calculate_resize_dimensions(original_width, original_height)
|
| 67 |
+
print(f"TARGET SIZE: {target_width} x {target_height}")
|
| 68 |
|
| 69 |
lora_path = "checkpoints/"
|
| 70 |
weight_name = "orbit_left_lora_weights.safetensors" if orbit_type == "Left" else "orbit_up_lora_weights.safetensors"
|
|
|
|
| 108 |
# First export the original video
|
| 109 |
export_to_video(video.frames[0], temp_path, fps=8)
|
| 110 |
|
|
|
|
| 111 |
try:
|
| 112 |
+
# Use ffmpeg-python
|
| 113 |
+
stream = ffmpeg.input(temp_path)
|
| 114 |
+
stream = ffmpeg.filter(stream, 'scale', target_width, target_height)
|
| 115 |
+
stream = ffmpeg.output(stream, final_path,
|
| 116 |
+
vcodec='libx264',
|
| 117 |
+
preset='medium',
|
| 118 |
+
crf=23,
|
| 119 |
+
acodec='copy')
|
| 120 |
+
ffmpeg.run(stream, overwrite_output=True, capture_stdout=True, capture_stderr=True)
|
| 121 |
+
except ffmpeg.Error as e:
|
| 122 |
+
print('stdout:', e.stdout.decode('utf8'))
|
| 123 |
+
print('stderr:', e.stderr.decode('utf8'))
|
| 124 |
+
raise e
|
| 125 |
finally:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
if os.path.exists(temp_path):
|
| 127 |
os.remove(temp_path)
|
| 128 |
|