Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -175,18 +175,29 @@ class VideoClassifier:
|
|
| 175 |
video_name = mp4_file.split("/")[-1]
|
| 176 |
wav_file = "results/audiotrack.wav"
|
| 177 |
video_clip = VideoFileClip(mp4_file)
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
audioclip.close()
|
| 181 |
video_clip.close()
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
return transcription.text
|
| 191 |
|
| 192 |
def generate_text(self, inputs, parameters=None):
|
|
|
|
| 175 |
video_name = mp4_file.split("/")[-1]
|
| 176 |
wav_file = "results/audiotrack.wav"
|
| 177 |
video_clip = VideoFileClip(mp4_file)
|
| 178 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio:
|
| 179 |
+
video_clip.audio.write_audiofile(temp_audio.name, codec='pcm_s16le', nbytes=2, fps=16000)
|
|
|
|
| 180 |
video_clip.close()
|
| 181 |
+
|
| 182 |
+
with open(temp_audio.name, 'rb') as audio_file:
|
| 183 |
+
transcription = client.audio.transcriptions.create(
|
| 184 |
+
model="whisper-1",
|
| 185 |
+
file=audio_file
|
| 186 |
+
)
|
| 187 |
+
print(transcription.text)
|
| 188 |
+
os.remove(temp_audio.name)
|
| 189 |
+
# audioclip = video_clip.audio
|
| 190 |
+
# wav_file = audioclip.write_audiofile(wav_file)
|
| 191 |
+
# audioclip.close()
|
| 192 |
+
# video_clip.close()
|
| 193 |
+
# audiotrack = "results/audiotrack.wav"
|
| 194 |
+
# # client = OpenAI(api_key="sk-proj-KY1qI7zTpsUiJhMUHuNdT3BlbkFJLOjVnTUSpYJi87yUtSEI")
|
| 195 |
+
# # audiotrack= open("audiotrack.wav", "rb")
|
| 196 |
+
# transcription = self.client.audio.transcriptions.create(
|
| 197 |
+
# model="whisper-1",
|
| 198 |
+
# file=audioclip
|
| 199 |
+
# )
|
| 200 |
+
# print(transcription.text)
|
| 201 |
return transcription.text
|
| 202 |
|
| 203 |
def generate_text(self, inputs, parameters=None):
|