Spaces:
Sleeping
Sleeping
Commit
·
61f52ca
1
Parent(s):
1bfa778
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,12 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
import librosa
|
4 |
|
5 |
-
# Initialize the model
|
6 |
asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
7 |
|
8 |
-
def transcribe(
|
9 |
-
# librosa expects a file path, but gradio passes a tuple (file name, file object)
|
10 |
-
# If the audio comes from a microphone, it's in the second position of the tuple
|
11 |
-
if isinstance(audio_data, tuple):
|
12 |
-
audio_data = audio_data[1]
|
13 |
-
|
14 |
# Load the audio file with librosa
|
15 |
-
data, samplerate = librosa.load(
|
16 |
# Pass the audio data to the model for transcription
|
17 |
transcription = asr_model(data, sampling_rate=samplerate)
|
18 |
return transcription["text"]
|
@@ -20,8 +15,9 @@ def transcribe(audio_data):
|
|
20 |
# Create the Gradio interface
|
21 |
iface = gr.Interface(
|
22 |
fn=transcribe,
|
23 |
-
inputs=gr.Audio(type="
|
24 |
outputs="text"
|
25 |
)
|
26 |
|
|
|
27 |
iface.launch()
|
|
|
2 |
from transformers import pipeline
|
3 |
import librosa
|
4 |
|
5 |
+
# Initialize the ASR model
|
6 |
asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
7 |
|
8 |
+
def transcribe(file_path):
|
|
|
|
|
|
|
|
|
|
|
9 |
# Load the audio file with librosa
|
10 |
+
data, samplerate = librosa.load(file_path, sr=None)
|
11 |
# Pass the audio data to the model for transcription
|
12 |
transcription = asr_model(data, sampling_rate=samplerate)
|
13 |
return transcription["text"]
|
|
|
15 |
# Create the Gradio interface
|
16 |
iface = gr.Interface(
|
17 |
fn=transcribe,
|
18 |
+
inputs=gr.Audio(type="filepath", label="Record or Upload Audio"),
|
19 |
outputs="text"
|
20 |
)
|
21 |
|
22 |
+
# Launch the interface
|
23 |
iface.launch()
|