tsi-org commited on
Commit
d3093e7
1 Parent(s): d3bc7c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -24
app.py CHANGED
@@ -175,7 +175,9 @@ def main():
175
  # uploaded_video_file = st.file_uploader("Select a video file", type=["mp4", "avi"])
176
  # uploaded_audio_file = st.file_uploader("Upload overlay audio (optional)", type=["mp3", "wav"])
177
 
178
-
 
 
179
  voice_options = {'Echo (Male)': 'echo', 'Fable (Male)': 'fable', 'Onyx (Male)': 'onyx', 'Nova (Female)': 'nova', 'Shimmer (Female)': 'shimmer', 'Alloy (Female)': 'alloy'}
180
  voice = st.selectbox('Choose the voice you want', list(voice_options.keys()))
181
 
@@ -218,34 +220,44 @@ def main():
218
  prompt = st.text_area("Edit the voiceover script prompt as needed:", value=initial_prompt.format(selected_duration=selected_duration), height=300)
219
 
220
 
221
- if uploaded_video_file is not None and st.button("START PROCESSING"):
222
- with st.spinner("Processing..."):
223
- overlay_audio_path = None
224
- if uploaded_audio_file is not None:
225
- uploaded_audio_file.seek(0)
226
- overlay_audio_path = save_temporary_audio_file(uploaded_audio_file)
227
 
228
- uploaded_video_file.seek(0)
229
- base64Frame, video_filename, video_duration = video_to_frames(uploaded_video_file, frame_sampling_rate=1)
 
230
 
231
- prompt = prompt_template
232
- text = frames_to_story(base64Frame, prompt, openai_key)
233
 
234
- audio_filename = text_to_audio(text, openai_key, voice_options[voice])
235
- output_video_filename = os.path.splitext(video_filename)[0] + "_output.mp4"
236
- final_video_filename = merge_audio_video(video_filename, audio_filename, output_video_filename, overlay_audio_path)
237
 
238
- st.subheader("Generated Script")
239
- st.write(text)
240
 
241
- if final_video_filename:
242
- st.subheader("Final Video with Voiceover")
243
- st.video(final_video_filename)
244
-
245
- os.remove(video_filename)
246
- os.remove(audio_filename)
247
- if overlay_audio_path:
248
- os.remove(overlay_audio_path)
 
 
 
 
 
 
 
 
 
 
 
 
249
 
250
  if __name__ == "__main__":
251
  main()
 
175
  # uploaded_video_file = st.file_uploader("Select a video file", type=["mp4", "avi"])
176
  # uploaded_audio_file = st.file_uploader("Upload overlay audio (optional)", type=["mp3", "wav"])
177
 
178
+ # Add a slider for overlay audio volume adjustment
179
+ overlay_audio_volume = st.slider('Adjust Overlay Audio Volume (%)', min_value=0, max_value=30, value=20)
180
+
181
  voice_options = {'Echo (Male)': 'echo', 'Fable (Male)': 'fable', 'Onyx (Male)': 'onyx', 'Nova (Female)': 'nova', 'Shimmer (Female)': 'shimmer', 'Alloy (Female)': 'alloy'}
182
  voice = st.selectbox('Choose the voice you want', list(voice_options.keys()))
183
 
 
220
  prompt = st.text_area("Edit the voiceover script prompt as needed:", value=initial_prompt.format(selected_duration=selected_duration), height=300)
221
 
222
 
223
+ if uploaded_video_file is not None and st.button("START PROCESSING"):
224
+ with st.spinner("Processing..."):
225
+ overlay_audio_path = None
226
+ overlay_audio_volume = st.slider('Adjust Overlay Audio Volume (%)', min_value=0, max_value=30, value=20) # Slider for volume adjustment
 
 
227
 
228
+ if uploaded_audio_file is not None:
229
+ uploaded_audio_file.seek(0)
230
+ overlay_audio_path = save_temporary_audio_file(uploaded_audio_file)
231
 
232
+ uploaded_video_file.seek(0)
233
+ base64Frame, video_filename, video_duration = video_to_frames(uploaded_video_file, frame_sampling_rate=1)
234
 
235
+ prompt = prompt_template
236
+ text = frames_to_story(base64Frame, prompt, openai_key)
 
237
 
238
+ audio_filename = text_to_audio(text, openai_key, voice_options[voice])
239
+ output_video_filename = os.path.splitext(video_filename)[0] + "_output.mp4"
240
 
241
+ # Adjusting the overlay audio volume using the slider value
242
+ if overlay_audio_path:
243
+ overlay_audio_clip = AudioFileClip(overlay_audio_path)
244
+ # Adjust volume based on slider value
245
+ overlay_audio_clip = overlay_audio_clip.volumex(overlay_audio_volume / 100.0)
246
+ final_video_filename = merge_audio_video(video_filename, audio_filename, output_video_filename, overlay_audio_clip)
247
+ else:
248
+ final_video_filename = merge_audio_video(video_filename, audio_filename, output_video_filename)
249
+
250
+ st.subheader("Generated Script")
251
+ st.write(text)
252
+
253
+ if final_video_filename:
254
+ st.subheader("Final Video with Voiceover")
255
+ st.video(final_video_filename)
256
+
257
+ os.remove(video_filename)
258
+ os.remove(audio_filename)
259
+ if overlay_audio_path:
260
+ os.remove(overlay_audio_path)
261
 
262
  if __name__ == "__main__":
263
  main()