Spaces:
Runtime error
Runtime error
Edward Nagy
commited on
Refactor transcribe function to handle both video
Browse files
app.py
CHANGED
@@ -10,35 +10,37 @@ import os
|
|
10 |
def transcribe_audio(audio_file):
|
11 |
text = "Test text"
|
12 |
# text = pipe(audio_file)["text"]
|
13 |
-
os.remove(audio_file) # Remove temporary audio file
|
14 |
return text
|
15 |
|
16 |
|
17 |
-
def
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
video_filename = "temp_video.mp4"
|
24 |
-
with open(video_filename, "wb") as f:
|
25 |
-
response = requests.get(video_url)
|
26 |
-
f.write(response.content)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
iface = gr.Interface(
|
|
|
10 |
def transcribe_audio(audio_file):
|
11 |
text = "Test text"
|
12 |
# text = pipe(audio_file)["text"]
|
|
|
13 |
return text
|
14 |
|
15 |
|
16 |
+
def transcribe_video(video_url):
|
17 |
+
# Download the video from the URL
|
18 |
+
video_filename = "temp_video.mp4"
|
19 |
+
with open(video_filename, "wb") as f:
|
20 |
+
response = requests.get(video_url)
|
21 |
+
f.write(response.content)
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Load the video using moviepy
|
24 |
+
video = VideoFileClip(video_filename)
|
25 |
+
audio = video.audio
|
26 |
|
27 |
+
audio_file = "temp_audio.wav"
|
28 |
+
audio.write_audiofile(audio_file, codec="pcm_s16le")
|
29 |
|
30 |
+
text = transcribe_audio(audio_file)
|
31 |
|
32 |
+
# Remove temporary files
|
33 |
+
os.remove(video_filename)
|
34 |
+
os.remove(audio_file)
|
35 |
|
36 |
+
return text
|
37 |
+
|
38 |
+
|
39 |
+
def transcribe(video_url="", audio=None):
|
40 |
+
if audio:
|
41 |
+
return transcribe_audio(audio)
|
42 |
+
elif video_url:
|
43 |
+
return transcribe_video(video_url)
|
44 |
|
45 |
|
46 |
iface = gr.Interface(
|