Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
1littlecoder
commited on
Commit
•
d4daed1
1
Parent(s):
47bb9d1
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import os
|
|
2 |
import google.generativeai as genai
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
-
from moviepy.editor import ImageClip,
|
6 |
|
7 |
# Configure Google Gemini API
|
8 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
@@ -72,18 +72,27 @@ def text_to_speech(text):
|
|
72 |
except Exception as e:
|
73 |
return f"Error generating audio: {e}"
|
74 |
|
75 |
-
# Function to create video from image and
|
76 |
-
def
|
77 |
try:
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
#
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
except Exception as e:
|
88 |
return f"Error generating video: {e}"
|
89 |
|
@@ -91,13 +100,13 @@ def generate_video(image_path, audio_path):
|
|
91 |
def process_roast(image_path):
|
92 |
roast_text = generate_roast(image_path)
|
93 |
audio_path = text_to_speech(roast_text)
|
94 |
-
video_path =
|
95 |
return roast_text, audio_path, video_path
|
96 |
|
97 |
# Gradio Interface
|
98 |
with gr.Blocks(theme=theme) as demo:
|
99 |
gr.Markdown("# Image Roasting App with TTS and Video")
|
100 |
-
gr.Markdown("Upload an image, click 'Roast Image', and the AI will roast it, convert the roast to audio, and generate a video.")
|
101 |
|
102 |
with gr.Row():
|
103 |
image_input = gr.Image(type="filepath", label="Upload Image")
|
|
|
2 |
import google.generativeai as genai
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
+
from moviepy.editor import AudioFileClip, ImageClip, CompositeVideoClip
|
6 |
|
7 |
# Configure Google Gemini API
|
8 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
|
|
72 |
except Exception as e:
|
73 |
return f"Error generating audio: {e}"
|
74 |
|
75 |
+
# Function to create video from image, audio, and add logo overlay
|
76 |
+
def create_video(image, audio):
|
77 |
try:
|
78 |
+
# Load the audio file
|
79 |
+
audio_clip = AudioFileClip(audio)
|
80 |
|
81 |
+
# Load the main image and set its duration to match the audio
|
82 |
+
image_clip = ImageClip(image).set_duration(audio_clip.duration)
|
83 |
+
|
84 |
+
# Load the logo image, resize it, and position it in the top-right corner
|
85 |
+
logo = ImageClip("Logo.png").resize(height=50) # Adjust the height as needed
|
86 |
+
logo = logo.set_position(("right", "top")).set_duration(audio_clip.duration)
|
87 |
+
|
88 |
+
# Create a composite video with the main image and the logo overlay
|
89 |
+
video_clip = CompositeVideoClip([image_clip, logo]).set_audio(audio_clip)
|
90 |
+
|
91 |
+
# Save the video to a temporary file
|
92 |
+
output_path = "/tmp/output_video_with_logo.mp4"
|
93 |
+
video_clip.write_videofile(output_path, fps=30)
|
94 |
+
|
95 |
+
return output_path
|
96 |
except Exception as e:
|
97 |
return f"Error generating video: {e}"
|
98 |
|
|
|
100 |
def process_roast(image_path):
|
101 |
roast_text = generate_roast(image_path)
|
102 |
audio_path = text_to_speech(roast_text)
|
103 |
+
video_path = create_video(image_path, audio_path)
|
104 |
return roast_text, audio_path, video_path
|
105 |
|
106 |
# Gradio Interface
|
107 |
with gr.Blocks(theme=theme) as demo:
|
108 |
gr.Markdown("# Image Roasting App with TTS and Video")
|
109 |
+
gr.Markdown("Upload an image, click 'Roast Image', and the AI will roast it, convert the roast to audio, and generate a video with a logo overlay.")
|
110 |
|
111 |
with gr.Row():
|
112 |
image_input = gr.Image(type="filepath", label="Upload Image")
|