Mpavan45 commited on
Commit
4b63f9b
·
verified ·
1 Parent(s): fbfa389

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -91,21 +91,20 @@ from chromadb.utils import embedding_functions
91
  from chromadb import Client
92
  from chromadb.config import Settings
93
 
94
- def extract_audio(file):
95
  """Extracts audio from video or handles audio file directly."""
96
  audio_path = "temp_audio.wav"
97
 
98
- # Use FFmpeg to extract audio from the uploaded buffer
99
- if file.name.endswith(('.mp4', '.mkv')):
100
- with open("temp_video.mp4", "wb") as f:
101
- f.write(file.getvalue())
102
-
103
- # Extract audio using the temp file
104
- ffmpeg.input("temp_video.mp4").output(audio_path).run(overwrite_output=True)
 
105
  else:
106
- # Handle audio files directly
107
- with open(audio_path, "wb") as f:
108
- f.write(file.getvalue())
109
 
110
  return audio_path
111
 
 
91
  from chromadb import Client
92
  from chromadb.config import Settings
93
 
94
+ def extract_audio(uploaded_file):
95
  """Extracts audio from video or handles audio file directly."""
96
  audio_path = "temp_audio.wav"
97
 
98
+ # Write uploaded file to a temporary file
99
+ temp_file = f"temp_{uploaded_file.name}"
100
+ with open(temp_file, "wb") as f:
101
+ f.write(uploaded_file.getvalue())
102
+
103
+ # Extract audio from video files or use directly for audio files
104
+ if uploaded_file.name.endswith(('.mp4', '.mkv')):
105
+ ffmpeg.input(temp_file).output(audio_path).run(overwrite_output=True)
106
  else:
107
+ audio_path = temp_file
 
 
108
 
109
  return audio_path
110