audio-to-text / app.py
zanemotiwala's picture
Update app.py
b3e5e27 verified
import gradio as gr
import logging
from transformers import pipeline
# Set up logging
logging.basicConfig(level=logging.INFO)
# Load Whisper model (tiny version for speed)
asr = pipeline(task="automatic-speech-recognition", model="openai/whisper-tiny.en")
# Function to transcribe audio from a file path
def transcribe_speech(audio_path):
if audio_path is None:
logging.error("No audio provided.")
return "No audio found, please retry."
try:
logging.info(f"Received audio file path: {audio_path}")
output = asr(audio_path)
return output["text"]
except Exception as e:
logging.error(f"Error during transcription: {str(e)}")
return f"Error processing the audio file: {str(e)}"
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("# 🎀 Simple Speech Recognition App")
gr.Markdown("Record or upload audio, then click **Transcribe Audio**")
mic = gr.Audio(label="πŸŽ™οΈ Microphone or Upload", type="filepath") # This is the key change
transcribe_button = gr.Button("πŸ“ Transcribe Audio")
transcription = gr.Textbox(label="πŸ—’οΈ Transcription", lines=3, placeholder="Transcription will appear here...")
transcribe_button.click(fn=transcribe_speech, inputs=mic, outputs=transcription)
demo.launch(share=True)