Spaces:
Runtime error
Runtime error
AndrewRWilliams
commited on
Commit
•
965b802
1
Parent(s):
3381f06
Add support for subtitles
Browse files
app.py
CHANGED
@@ -1,18 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
import whisper
|
|
|
3 |
|
4 |
model = whisper.load_model("base")
|
5 |
|
6 |
def transcribe(file):
|
7 |
result = model.transcribe(file)
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
iface = gr.Interface(
|
15 |
-
title = 'Whisper transcription from file',
|
16 |
fn=transcribe,
|
17 |
inputs=[
|
18 |
gr.inputs.Audio(source="upload", type="filepath", label="Upload Audio")
|
|
|
1 |
import gradio as gr
|
2 |
import whisper
|
3 |
+
from whisper.utils import write_srt
|
4 |
|
5 |
model = whisper.load_model("base")
|
6 |
|
7 |
def transcribe(file):
|
8 |
result = model.transcribe(file)
|
9 |
+
|
10 |
+
#transcript
|
11 |
+
with open(str(file) + "-transcript.txt", "w") as f:
|
12 |
+
f.write(result['text'])
|
13 |
+
|
14 |
+
#subtitles
|
15 |
+
with open(str(file) + "-subs.srt", "w") as srt:
|
16 |
+
write_srt(result["segments"], file=srt)
|
17 |
+
|
18 |
+
download = []
|
19 |
+
download.append(str(file) + "-subs.srt");
|
20 |
+
download.append(str(file) + "-transcript.txt");
|
21 |
+
|
22 |
+
return download
|
23 |
|
24 |
iface = gr.Interface(
|
25 |
+
title = 'Whisper transcription and subtitles from file',
|
26 |
fn=transcribe,
|
27 |
inputs=[
|
28 |
gr.inputs.Audio(source="upload", type="filepath", label="Upload Audio")
|