Spaces:
No application file
No application file
import gradio as gr | |
import requests | |
# Set the model ID for Whisper small English model | |
model_id = "openai/whisper-small.en" | |
# Function to send audio to Hugging Face Inference API and get transcription | |
def transcribe(audio): | |
if audio is None: | |
return "No audio provided." | |
API_URL = f"https://api-inference.huggingface.co/models/{model_id}" | |
headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_TOKEN"} | |
# Read and send the audio file | |
with open(audio, "rb") as f: | |
data = f.read() | |
response = requests.post(API_URL, headers=headers, data=data) | |
# Return the transcription or error | |
if response.status_code == 200: | |
return response.json().get("text", "No text returned.") | |
else: | |
return f"Error: {response.status_code} - {response.text}" | |
# Gradio Interface | |
interface = gr.Interface( | |
fn=transcribe, | |
inputs=gr.Audio(source="upload", type="filepath", label="Upload Audio"), | |
outputs=gr.Textbox(label="Transcribed Text"), | |
title="Speech Recognition with Whisper", | |
description="Upload an audio file and get the transcribed text using OpenAI Whisper (small.en)." | |
) | |
interface.launch() | |