Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
1littlecoder
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -65,10 +65,14 @@ def text_to_speech(text):
|
|
65 |
audio_file.write(response.content)
|
66 |
return audio_path
|
67 |
else:
|
68 |
-
|
|
|
69 |
|
70 |
# Function to create video from image and audio
|
71 |
def generate_video(image_path, audio_path):
|
|
|
|
|
|
|
72 |
image_clip = ImageClip(image_path).set_duration(AudioFileClip(audio_path).duration)
|
73 |
audio_clip = AudioFileClip(audio_path)
|
74 |
video_clip = image_clip.set_audio(audio_clip)
|
@@ -92,6 +96,10 @@ with gr.Blocks(theme=theme) as demo:
|
|
92 |
def process_image(image):
|
93 |
roast_text = generate_roast(image)
|
94 |
audio_path = text_to_speech(roast_text)
|
|
|
|
|
|
|
|
|
95 |
video_path = generate_video(image, audio_path)
|
96 |
return roast_text, audio_path, video_path
|
97 |
|
|
|
65 |
audio_file.write(response.content)
|
66 |
return audio_path
|
67 |
else:
|
68 |
+
print(f"Error: {response.status_code} - {response.text}")
|
69 |
+
return None # Return None if there's an error
|
70 |
|
71 |
# Function to create video from image and audio
|
72 |
def generate_video(image_path, audio_path):
|
73 |
+
if audio_path is None:
|
74 |
+
return None # Skip video generation if there's no valid audio file
|
75 |
+
|
76 |
image_clip = ImageClip(image_path).set_duration(AudioFileClip(audio_path).duration)
|
77 |
audio_clip = AudioFileClip(audio_path)
|
78 |
video_clip = image_clip.set_audio(audio_clip)
|
|
|
96 |
def process_image(image):
|
97 |
roast_text = generate_roast(image)
|
98 |
audio_path = text_to_speech(roast_text)
|
99 |
+
|
100 |
+
if audio_path is None:
|
101 |
+
return "Error generating audio. Please try again.", None, None
|
102 |
+
|
103 |
video_path = generate_video(image, audio_path)
|
104 |
return roast_text, audio_path, video_path
|
105 |
|