Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from faster_whisper import WhisperModel
|
3 |
+
import json
|
4 |
+
|
5 |
+
def transcribe_audio(audiofile):
|
6 |
+
model_size = "medium"
|
7 |
+
model = WhisperModel(model_size)
|
8 |
+
|
9 |
+
segments, info = model.transcribe(audiofile, word_timestamps=True)
|
10 |
+
segments = list(segments) # The transcription will actually run here.
|
11 |
+
|
12 |
+
wordlevel_info = []
|
13 |
+
for segment in segments:
|
14 |
+
for word in segment.words:
|
15 |
+
wordlevel_info.append({'word':word.word,'start':word.start,'end':word.end})
|
16 |
+
|
17 |
+
# Save wordlevel_info to data.json
|
18 |
+
with open('data.json', 'w') as f:
|
19 |
+
json.dump(wordlevel_info, f)
|
20 |
+
|
21 |
+
return "Transcription complete. Check data.json for results."
|
22 |
+
|
23 |
+
# Define the Gradio interface
|
24 |
+
audiofile_input = gr.inputs.Audio(label="Upload your audio file")
|
25 |
+
output_text = gr.outputs.Textbox(label="Transcription")
|
26 |
+
|
27 |
+
# Create Gradio interface
|
28 |
+
gr.Interface(transcribe_audio, inputs=audiofile_input, outputs=output_text).launch()
|