Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,8 @@ import io
|
|
7 |
import openai
|
8 |
import os
|
9 |
import requests
|
10 |
-
import tempfile
|
11 |
|
12 |
-
# Set up page configuration
|
13 |
st.set_page_config(page_title="AI Voiceover", page_icon="🔮")
|
14 |
|
15 |
# Load environment variables
|
@@ -118,7 +117,6 @@ def merge_audio_video(video_filename, audio_filename, output_filename, overlay_a
|
|
118 |
return output_filename
|
119 |
|
120 |
def main():
|
121 |
-
# st.set_page_config(page_title="AI Voiceover", page_icon="🔮")
|
122 |
st.title("Pixio Video to Voiceover 🎥🔮")
|
123 |
|
124 |
if not check_password():
|
@@ -130,27 +128,10 @@ def main():
|
|
130 |
return
|
131 |
|
132 |
uploaded_file = st.file_uploader("Select a video file", type=["mp4", "avi"])
|
133 |
-
|
134 |
-
st.video(uploaded_file)
|
135 |
-
|
136 |
-
overlay_audio_file = st.file_uploader("Upload overlay audio (optional)", type=["mp3", "wav"])
|
137 |
-
|
138 |
-
# After uploading, write it to a temporary file
|
139 |
-
if overlay_audio_file is not None:
|
140 |
-
# Create a temporary file
|
141 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_file:
|
142 |
-
overlay_audio_path = temp_file.name
|
143 |
-
# Read content from the uploaded file
|
144 |
-
content = overlay_audio_file.read()
|
145 |
-
# Write content to the temporary file
|
146 |
-
temp_file.write(content)
|
147 |
-
|
148 |
-
# Now overlay_audio_path contains the path to the temporary file
|
149 |
-
# and can be safely used with MoviePy
|
150 |
|
151 |
voice_options = {'Echo (Male)': 'echo', 'Fable (Male)': 'fable', 'Onyx (Male)': 'onyx', 'Nova (Female)': 'nova', 'Shimmer (Female)': 'shimmer', 'Alloy (Female)': 'alloy'}
|
152 |
-
|
153 |
-
classify = voice_options[option]
|
154 |
|
155 |
duration_options = list(range(10, 121, 10)) # 10 to 120 seconds, in 10-second intervals
|
156 |
selected_duration = st.selectbox('Select the desired video duration (seconds)', duration_options)
|
@@ -186,8 +167,9 @@ if overlay_audio_file is not None:
|
|
186 |
if uploaded_file is not None and st.button("START PROCESSING"):
|
187 |
with st.spinner("Processing..."):
|
188 |
base64Frame, video_filename, video_duration = video_to_frames(uploaded_file, 1)
|
|
|
189 |
text = frames_to_story(base64Frame, prompt, openai_key)
|
190 |
-
audio_filename = text_to_audio(text, openai_key,
|
191 |
output_video_filename = os.path.splitext(video_filename)[0] + "_output.mp4"
|
192 |
final_video_filename = merge_audio_video(video_filename, audio_filename, output_video_filename, overlay_audio_file)
|
193 |
st.video(final_video_filename)
|
|
|
7 |
import openai
|
8 |
import os
|
9 |
import requests
|
|
|
10 |
|
11 |
+
# Set up page configuration
|
12 |
st.set_page_config(page_title="AI Voiceover", page_icon="🔮")
|
13 |
|
14 |
# Load environment variables
|
|
|
117 |
return output_filename
|
118 |
|
119 |
def main():
|
|
|
120 |
st.title("Pixio Video to Voiceover 🎥🔮")
|
121 |
|
122 |
if not check_password():
|
|
|
128 |
return
|
129 |
|
130 |
uploaded_file = st.file_uploader("Select a video file", type=["mp4", "avi"])
|
131 |
+
overlay_audio_file = st.file_uploader("Upload overlay audio (optional)", type=["mp3", "wav"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
voice_options = {'Echo (Male)': 'echo', 'Fable (Male)': 'fable', 'Onyx (Male)': 'onyx', 'Nova (Female)': 'nova', 'Shimmer (Female)': 'shimmer', 'Alloy (Female)': 'alloy'}
|
134 |
+
voice = st.selectbox('Choose the voice you want', list(voice_options.keys()))
|
|
|
135 |
|
136 |
duration_options = list(range(10, 121, 10)) # 10 to 120 seconds, in 10-second intervals
|
137 |
selected_duration = st.selectbox('Select the desired video duration (seconds)', duration_options)
|
|
|
167 |
if uploaded_file is not None and st.button("START PROCESSING"):
|
168 |
with st.spinner("Processing..."):
|
169 |
base64Frame, video_filename, video_duration = video_to_frames(uploaded_file, 1)
|
170 |
+
prompt = script_templates[selected_script_type].format(duration=selected_duration) # Customize this based on your needs
|
171 |
text = frames_to_story(base64Frame, prompt, openai_key)
|
172 |
+
audio_filename = text_to_audio(text, openai_key, voice_options[voice])
|
173 |
output_video_filename = os.path.splitext(video_filename)[0] + "_output.mp4"
|
174 |
final_video_filename = merge_audio_video(video_filename, audio_filename, output_video_filename, overlay_audio_file)
|
175 |
st.video(final_video_filename)
|