Spaces:
Sleeping
Sleeping
File size: 962 Bytes
a2a46d0 aa0a69d 3482efe b94d057 3482efe b94d057 3482efe aa0a69d 3482efe aa0a69d dc1d260 aa0a69d dc1d260 3482efe a2a46d0 dc1d260 3482efe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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()
|