asm3515's picture
Update app.py
73570fe verified
raw
history blame
842 Bytes
import gradio as gr
from transformers import pipeline
# Load the Whisper model for speech recognition
pipe = pipeline("automatic-speech-recognition", model="openai/whisper-small")
# Function to handle the speech recognition
def transcribe_audio(audio):
# Use the pipeline to transcribe the audio
result = pipe(audio)["text"]
return result
# Create a Gradio interface for the audio input and transcription output
interface = gr.Interface(
fn=transcribe_audio, # Function that handles the transcription
inputs=gr.Audio(source="microphone", type="filepath"), # Input as audio from mic
outputs="text", # Output as text
title="Whisper Speech Recognition",
description="Transcribe speech to text using OpenAI's Whisper model."
)
# Launch the Gradio interface
if __name__ == "__main__":
interface.launch()