Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Whisper pipeline (supports Hindi, Punjabi, etc.) | |
| asr_pipeline = pipeline( | |
| task="automatic-speech-recognition", | |
| model="openai/whisper-small", | |
| ) | |
| # Function to transcribe and detect language | |
| def transcribe(audio_np, sample_rate): | |
| result = asr_pipeline({ | |
| "array": audio_np, | |
| "sampling_rate": sample_rate | |
| }) | |
| text = result["text"] | |
| lang = result.get("language", "unknown") | |
| return f"Detected Language: {lang}\n\nTranscription:\n{text}" | |
| # Gradio Interface | |
| interface = gr.Interface( | |
| fn=transcribe, | |
| inputs=gr.Audio(type="numpy", label="Upload or Record Audio"), # FIXED | |
| outputs=gr.Textbox(label="Detected Language & Transcription"), | |
| title="Auto Language Detection - Whisper", | |
| description="Upload or record Hindi or Punjabi audio. Whisper will auto-detect language and transcribe." | |
| ) | |
| interface.launch() | |