sehaj13 commited on
Commit
2009c4b
·
verified ·
1 Parent(s): 2382f52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -1,21 +1,30 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load Whisper model
5
- asr_pipeline = pipeline(model="openai/whisper-small", task="automatic-speech-recognition")
 
 
 
6
 
7
- # Define transcription function
8
- def transcribe(audio):
9
- result = asr_pipeline(audio)
10
- return result["text"]
 
 
 
 
 
11
 
12
- # Gradio Interface (v4.x style)
13
  interface = gr.Interface(
14
  fn=transcribe,
15
- inputs=gr.Audio(type="filepath", label="Upload or Record Audio"), # No 'source'
16
- outputs=gr.Textbox(label="Transcription"),
17
- title="Hindi Speech-to-Text",
18
- description="Speak or upload audio in Hindi to get transcription using Whisper."
19
  )
20
 
21
  interface.launch()
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Whisper pipeline (supports Hindi, Punjabi, etc.)
5
+ asr_pipeline = pipeline(
6
+ task="automatic-speech-recognition",
7
+ model="openai/whisper-small",
8
+ )
9
 
10
+ # Function to transcribe and detect language
11
+ def transcribe(audio_np, sample_rate):
12
+ result = asr_pipeline({
13
+ "array": audio_np,
14
+ "sampling_rate": sample_rate
15
+ })
16
+ text = result["text"]
17
+ lang = result.get("language", "unknown")
18
+ return f"Detected Language: {lang}\n\nTranscription:\n{text}"
19
 
20
+ # Gradio Interface
21
  interface = gr.Interface(
22
  fn=transcribe,
23
+ inputs=gr.Audio(type="numpy", label="Upload or Record Audio"), # FIXED
24
+ outputs=gr.Textbox(label="Detected Language & Transcription"),
25
+ title="Auto Language Detection - Whisper",
26
+ description="Upload or record Hindi or Punjabi audio. Whisper will auto-detect language and transcribe."
27
  )
28
 
29
  interface.launch()
30
+