Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import whisper
|
| 3 |
+
|
| 4 |
+
# Initialize the Whisper model
|
| 5 |
+
model = whisper.load_model("large")
|
| 6 |
+
|
| 7 |
+
def transcribe(audio_file):
|
| 8 |
+
audio = whisper.load_audio(audio_file.name)
|
| 9 |
+
audio = whisper.pad_or_trim(audio)
|
| 10 |
+
# Generate a mel spectrogram
|
| 11 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
| 12 |
+
# Options for decoding the spectrogram
|
| 13 |
+
options = whisper.DecodingOptions()
|
| 14 |
+
# Perform the transcription
|
| 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.inputs.Audio(source="upload", type="file", label="Upload your audio file"),
|
| 22 |
+
outputs="text",
|
| 23 |
+
title="Whisper ASR",
|
| 24 |
+
description="Upload an audio file and it will be transcribed using OpenAI's Whisper model."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Launch the app
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
iface.launch()
|