Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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="
|
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",
|