Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ def resize_image_with_aspect_ratio(img, target_size=(1280, 720), padding_color=(
|
|
| 31 |
# Video generation function with transition
|
| 32 |
def process_and_generate_video(audio_file, images):
|
| 33 |
try:
|
| 34 |
-
# Log
|
| 35 |
print(f"Audio file received: {audio_file.name}")
|
| 36 |
print(f"Images received: {[img.name for img in images]}")
|
| 37 |
|
|
@@ -59,6 +59,7 @@ def process_and_generate_video(audio_file, images):
|
|
| 59 |
|
| 60 |
# Process each image and create video clip
|
| 61 |
for img_path in image_paths:
|
|
|
|
| 62 |
img = Image.open(img_path)
|
| 63 |
img = resize_image_with_aspect_ratio(img, target_size=(1280, 720))
|
| 64 |
|
|
@@ -80,13 +81,21 @@ def process_and_generate_video(audio_file, images):
|
|
| 80 |
|
| 81 |
# Set output file path in a temporary location
|
| 82 |
output_path = '/tmp/generated_video.mp4' # Temporary path for output
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
# Write video to file
|
| 85 |
video.write_videofile(output_path, codec='libx264', audio_codec='aac')
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
except Exception as e:
|
| 91 |
print(f"Error during video generation: {str(e)}")
|
| 92 |
return f"Error generating video: {str(e)}"
|
|
|
|
| 31 |
# Video generation function with transition
|
| 32 |
def process_and_generate_video(audio_file, images):
|
| 33 |
try:
|
| 34 |
+
# Log the files received
|
| 35 |
print(f"Audio file received: {audio_file.name}")
|
| 36 |
print(f"Images received: {[img.name for img in images]}")
|
| 37 |
|
|
|
|
| 59 |
|
| 60 |
# Process each image and create video clip
|
| 61 |
for img_path in image_paths:
|
| 62 |
+
print(f"Processing image: {img_path}") # Debug print
|
| 63 |
img = Image.open(img_path)
|
| 64 |
img = resize_image_with_aspect_ratio(img, target_size=(1280, 720))
|
| 65 |
|
|
|
|
| 81 |
|
| 82 |
# Set output file path in a temporary location
|
| 83 |
output_path = '/tmp/generated_video.mp4' # Temporary path for output
|
| 84 |
+
|
| 85 |
+
# Check if the video is generated before writing it to file
|
| 86 |
+
print(f"Writing video to {output_path}...")
|
| 87 |
+
|
| 88 |
# Write video to file
|
| 89 |
video.write_videofile(output_path, codec='libx264', audio_codec='aac')
|
| 90 |
+
|
| 91 |
+
# Check if the video file exists
|
| 92 |
+
if os.path.exists(output_path):
|
| 93 |
+
print(f"Video generated successfully at {output_path}")
|
| 94 |
+
return output_path # Return the file path for Gradio output
|
| 95 |
+
else:
|
| 96 |
+
print(f"Error: Video not generated at {output_path}")
|
| 97 |
+
return "Error: Video not generated."
|
| 98 |
+
|
| 99 |
except Exception as e:
|
| 100 |
print(f"Error during video generation: {str(e)}")
|
| 101 |
return f"Error generating video: {str(e)}"
|