tsi-org commited on
Commit
8af0ad8
·
verified ·
1 Parent(s): 06855bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -28,6 +28,14 @@ def check_password():
28
  st.error("Incorrect password")
29
  return False
30
 
 
 
 
 
 
 
 
 
31
  def video_to_frames(video_file, frame_sampling_rate=1):
32
  with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmpfile:
33
  tmpfile.write(video_file.read())
@@ -201,15 +209,14 @@ def main():
201
 
202
  if uploaded_file is not None and st.button("START PROCESSING"):
203
  with st.spinner("Processing..."):
204
- # Assuming save_temporary_audio_file and other necessary functions are defined
205
- # Ensure overlay_audio_file is saved to a temporary file if present
206
  overlay_audio_path = None
207
  if overlay_audio_file is not None:
 
208
  overlay_audio_path = save_temporary_audio_file(overlay_audio_file)
209
 
210
  # Process the uploaded video file
211
- base64Frame, video_filename, video_duration = video_to_frames(uploaded_file, 1)
212
- prompt = script_templates.get(selected_script_type, "Default prompt if script type not found").format(selected_duration=selected_duration)
213
  text = frames_to_story(base64Frame, prompt, openai_key)
214
  audio_filename = text_to_audio(text, openai_key, voice_options[voice])
215
  output_video_filename = os.path.splitext(video_filename)[0] + "_output.mp4"
@@ -223,7 +230,7 @@ def main():
223
  os.remove(audio_filename)
224
  if overlay_audio_path:
225
  os.remove(overlay_audio_path)
226
- # Consider how to handle final_video_filename as it might be needed for the user to download/view
227
 
228
  if __name__ == "__main__":
229
  main()
 
28
  st.error("Incorrect password")
29
  return False
30
 
31
+
32
+ def save_temporary_audio_file(uploaded_file):
33
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav", mode='wb') as tmpfile: # Ensure mode is set to 'wb' for binary write
34
+ # Directly write the uploaded file content to the temporary file
35
+ tmpfile.write(uploaded_file.read()) # Use .read() to read bytes from the uploaded file
36
+ return tmpfile.name
37
+
38
+
39
  def video_to_frames(video_file, frame_sampling_rate=1):
40
  with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmpfile:
41
  tmpfile.write(video_file.read())
 
209
 
210
  if uploaded_file is not None and st.button("START PROCESSING"):
211
  with st.spinner("Processing..."):
 
 
212
  overlay_audio_path = None
213
  if overlay_audio_file is not None:
214
+ # Save the uploaded overlay audio file to a temporary file
215
  overlay_audio_path = save_temporary_audio_file(overlay_audio_file)
216
 
217
  # Process the uploaded video file
218
+ base64Frame, video_filename, video_duration = video_to_frames(uploaded_file, frame_sampling_rate=1)
219
+ prompt = script_templates[selected_script_type].format(selected_duration=selected_duration) # Fixed to directly access script_templates
220
  text = frames_to_story(base64Frame, prompt, openai_key)
221
  audio_filename = text_to_audio(text, openai_key, voice_options[voice])
222
  output_video_filename = os.path.splitext(video_filename)[0] + "_output.mp4"
 
230
  os.remove(audio_filename)
231
  if overlay_audio_path:
232
  os.remove(overlay_audio_path)
233
+ # Consider adding functionality for the user to download/view the final video
234
 
235
  if __name__ == "__main__":
236
  main()