Spaces:
Runtime error
Runtime error
import os | |
import unicodedata | |
from transformers import pipeline | |
import gradio as gr | |
# Set the Hugging Face token | |
HF_TOKEN = "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" | |
os.environ["HF_TOKEN"] = HF_TOKEN | |
# Define the ASR function | |
def asr(audio): | |
asr = pipeline("automatic-speech-recognition", model="kingabzpro/wav2vec2-large-xls-r-300m-Urdu") | |
prediction = asr(audio, chunk_length_s=30) | |
return unicodedata.normalize("NFC", prediction[0]["text"]) | |
# Define the Gradio interface | |
title = "Urdu Automatic Speech Recognition" | |
description = "This model performs automatic speech recognition for the Urdu language." | |
input_audio = gr.inputs.Audio(source="microphone", type="numpy", label="Record your voice") | |
output_text = gr.outputs.Textbox(label="Transcription") | |
gr.Interface(fn=asr, inputs=input_audio, outputs=output_text, title=title, description=description).launch() | |
# Ensure to replace "YOUR_HF_TOKEN" with your actual Hugging Face token. | |