AudioMax / app.py
sifujohn's picture
Create app.py
2d25adc verified
raw
history blame contribute delete
816 Bytes
import gradio as gr
import torch
from transformers import pipeline
MODEL = "openai/whisper-tiny" # good balance of speed + accuracy
# Load model once at startup
device = 0 if torch.cuda.is_available() else -1
transcriber = pipeline(
"automatic-speech-recognition",
model=MODEL,
device=device
)
def transcribe(audio):
if audio is None:
return "Please upload or record audio."
result = transcriber(audio)
return result["text"]
demo = gr.Interface(
fn=transcribe,
inputs=gr.Audio(
sources=["microphone", "upload"],
type="filepath"
),
outputs=gr.Textbox(label="Transcription"),
title="๐ŸŽ™ Voice to Text",
description="Upload or record audio. Powered by Whisper running locally in HF Spaces."
)
if __name__ == "__main__":
demo.launch()