Walid-Ahmed's picture
Update app.py
3482efe verified
raw
history blame
962 Bytes
import whisper
import gradio as gr
# Force the model to run on CPU
device = "cpu"
print("Running on CPU")
# Load the Whisper model on CPU
model_name = "tiny" # Change to "base", "small", etc., as needed
whisper_model = whisper.load_model(model_name, device=device)
# Define the transcription function
def transcribe(audio):
# Perform transcription using the Whisper model
result = whisper_model.transcribe(audio)
return result["text"]
# Create the Gradio interface
demo = gr.Interface(
fn=transcribe, # The function to be called for transcription
inputs=gr.Audio(source="microphone", type="filepath", label="Speak into the microphone"), # Input audio
outputs=gr.Textbox(label="Transcription"), # Output transcription
title="Whisper Speech-to-Text", # Title of the interface
description="Record audio using your microphone and get a transcription using the Whisper model."
)
# Launch the Gradio interface
demo.launch()