Download app.py from mkfallah/pasr: direct link, hf CLI and curl.
- Browser
- Download file 891 Bytes
-
https://huggingface.co/spaces/mkfallah/pasr/resolve/main/app.py
- Command line
-
hf download hf://spaces/mkfallah/pasr/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mkfallah/pasr/resolve/main/app.py
891 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| # initialize ASR pipeline | |
| asr = pipeline( | |
| task="automatic-speech-recognition", | |
| model="vhdm/whisper-large-fa-v1", | |
| device=-1 # CPU; set device=0 for GPU | |
| ) | |
| def transcribe(audio_file): | |
| """ | |
| audio_file: path to WAV file (Gradio mic or upload) | |
| """ | |
| if not audio_file: | |
| return "No audio input detected." | |
| try: | |
| # run ASR | |
| result = asr(audio_file, chunk_length_s=30, stride_length_s=[5,5]) | |
| except Exception as e: | |
| return f"ASR error: {e}" | |
| text = result.get("text", "") | |
| return text | |
| # gradio interface | |
| iface = gr.Interface( | |
| fn=transcribe, | |
| inputs=gr.Audio(type="filepath", label="Record or upload audio"), | |
| outputs="text", | |
| title="Persian ASR", | |
| description=""" Speak in Persian or upload an audio file.""" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |