barbaroo commited on
Commit
ebd3d99
1 Parent(s): 2ecefed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -5,20 +5,26 @@ from transformers import pipeline
5
  p = pipeline("automatic-speech-recognition",
6
  model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h")
7
 
8
- def transcribe(audio, state="", uploaded_audio=""):
9
- if uploaded_audio:
10
  audio = uploaded_audio
11
- time.sleep(3)
12
- text = p(audio)["text"]
13
- state += text + " - "
14
- return state, state
 
 
 
 
 
 
15
 
16
  gr.Interface(
17
  fn=transcribe,
18
  inputs=[
19
  gr.inputs.Audio(source="microphone", type="filepath"),
20
  'state',
21
- gr.inputs.Audio(label="Upload Audio File", type="numpy", source="upload")
22
  ],
23
  outputs=[
24
  "textbox",
 
5
  p = pipeline("automatic-speech-recognition",
6
  model="carlosdanielhernandezmena/wav2vec2-large-xlsr-53-faroese-100h")
7
 
8
+ def transcribe(audio, state="", uploaded_audio=None):
9
+ if uploaded_audio is not None:
10
  audio = uploaded_audio
11
+ if not audio:
12
+ return "Please input audio.", state # Return a meaningful message
13
+ try:
14
+ time.sleep(3)
15
+ text = p(audio)["text"]
16
+ state += text + " "
17
+ return state, state
18
+ except Exception as e:
19
+ return "An error occurred during transcription.", state # Handle other exceptions
20
+
21
 
22
  gr.Interface(
23
  fn=transcribe,
24
  inputs=[
25
  gr.inputs.Audio(source="microphone", type="filepath"),
26
  'state',
27
+ gr.inputs.Audio(label="Upload Audio File", type="filepath", source="upload")
28
  ],
29
  outputs=[
30
  "textbox",