Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,22 +5,20 @@ import whisper
|
|
5 |
model = whisper.load_model("large")
|
6 |
|
7 |
def transcribe(audio_file):
|
8 |
-
#
|
9 |
-
|
10 |
-
|
|
|
11 |
audio = whisper.pad_or_trim(audio)
|
12 |
-
# Generate a mel spectrogram
|
13 |
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
14 |
-
# Options for decoding the spectrogram
|
15 |
options = whisper.DecodingOptions()
|
16 |
-
# Perform the transcription
|
17 |
result = whisper.decode(model, mel, options)
|
18 |
return result.text
|
19 |
|
20 |
# Create the Gradio interface
|
21 |
iface = gr.Interface(
|
22 |
fn=transcribe,
|
23 |
-
inputs=gr.Audio(label="Upload your audio file"),
|
24 |
outputs="text",
|
25 |
title="Whisper ASR",
|
26 |
description="Upload an audio file and it will be transcribed using OpenAI's Whisper model."
|
|
|
5 |
model = whisper.load_model("large")
|
6 |
|
7 |
def transcribe(audio_file):
|
8 |
+
# The audio_file parameter is a tuple with the filename and the file object
|
9 |
+
# We only need the file object which is the second element of the tuple
|
10 |
+
audio_data = audio_file[1]
|
11 |
+
audio = whisper.load_audio(audio_data)
|
12 |
audio = whisper.pad_or_trim(audio)
|
|
|
13 |
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
|
|
14 |
options = whisper.DecodingOptions()
|
|
|
15 |
result = whisper.decode(model, mel, options)
|
16 |
return result.text
|
17 |
|
18 |
# Create the Gradio interface
|
19 |
iface = gr.Interface(
|
20 |
fn=transcribe,
|
21 |
+
inputs=gr.Audio(label="Upload your audio file", type="file"),
|
22 |
outputs="text",
|
23 |
title="Whisper ASR",
|
24 |
description="Upload an audio file and it will be transcribed using OpenAI's Whisper model."
|