navjotk commited on
Commit
138ec1e
·
verified ·
1 Parent(s): 5a12036

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,21 +1,22 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load Wav2Vec 2.0 pipeline for automatic speech recognition
5
  asr = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
6
 
7
- # Function to transcribe audio
8
  def transcribe(audio):
9
- text = asr(audio)["text"]
10
- return text
 
11
 
12
- # Gradio UI
13
  interface = gr.Interface(
14
  fn=transcribe,
15
- inputs=gr.Audio(source="microphone", type="filepath", label="Record or Upload Audio"),
16
  outputs=gr.Textbox(label="Transcribed Text"),
17
- title="Wav2Vec 2.0 Speech-to-Text",
18
- description="Speak or upload an audio file. The model will convert it to text using Wav2Vec2."
19
  )
20
 
21
  interface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load Wav2Vec 2.0 speech recognition model
5
  asr = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-base-960h")
6
 
7
+ # Function to process audio and return transcribed text
8
  def transcribe(audio):
9
+ if audio is None:
10
+ return "No audio provided."
11
+ return asr(audio)["text"]
12
 
13
+ # Gradio Interface
14
  interface = gr.Interface(
15
  fn=transcribe,
16
+ inputs=gr.Audio(type="filepath", label="Upload or Record Audio"),
17
  outputs=gr.Textbox(label="Transcribed Text"),
18
+ title="🎤 Wav2Vec 2.0 - Speech to Text",
19
+ description="Upload or record an audio file and get the transcribed text using Facebook's Wav2Vec 2.0."
20
  )
21
 
22
  interface.launch()