Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai_whisper import whisper
|
| 3 |
+
|
| 4 |
+
# Load the Whisper model
|
| 5 |
+
model = whisper.load_model("base")
|
| 6 |
+
|
| 7 |
+
def transcribe(audio_file):
|
| 8 |
+
# Process the audio file
|
| 9 |
+
audio = whisper.load_audio(audio_file.name)
|
| 10 |
+
audio = whisper.pad_or_trim(audio)
|
| 11 |
+
|
| 12 |
+
# Make predictions
|
| 13 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
| 14 |
+
options = whisper.DecodingOptions(fp16=False)
|
| 15 |
+
result = whisper.decode(model, mel, options)
|
| 16 |
+
|
| 17 |
+
# Return the transcription
|
| 18 |
+
return result.text
|
| 19 |
+
|
| 20 |
+
# Create the Gradio interface
|
| 21 |
+
iface = gr.Interface(fn=transcribe,
|
| 22 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="Whisper Transcription",
|
| 25 |
+
description="Upload an audio file to transcribe it using OpenAI's Whisper model.")
|
| 26 |
+
|
| 27 |
+
# Launch the app
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
iface.launch()
|