Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
-
import numpy as np
|
5 |
|
6 |
# Fetch the token from the environment
|
7 |
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
|
@@ -9,10 +8,11 @@ model_id = "akadriu/whisper-medium-sq" # update with your model id
|
|
9 |
pipe = pipeline("automatic-speech-recognition", model=model_id, token=hf_token)
|
10 |
|
11 |
def transcribe_speech(filepath):
|
12 |
-
#
|
13 |
if filepath is None:
|
14 |
raise ValueError("No audio file provided.")
|
15 |
|
|
|
16 |
output = pipe(
|
17 |
filepath,
|
18 |
max_new_tokens=256,
|
@@ -25,16 +25,16 @@ def transcribe_speech(filepath):
|
|
25 |
)
|
26 |
return output["text"]
|
27 |
|
28 |
-
# Create Gradio
|
29 |
mic_transcribe = gr.Interface(
|
30 |
fn=transcribe_speech,
|
31 |
-
inputs=gr.Audio(
|
32 |
outputs="text",
|
33 |
)
|
34 |
|
35 |
file_transcribe = gr.Interface(
|
36 |
fn=transcribe_speech,
|
37 |
-
inputs=gr.Audio(
|
38 |
outputs="text",
|
39 |
)
|
40 |
|
@@ -48,3 +48,4 @@ with demo:
|
|
48 |
|
49 |
demo.launch(debug=True)
|
50 |
|
|
|
|
1 |
import os
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
# Fetch the token from the environment
|
6 |
hf_token = os.getenv("HUGGINGFACE_HUB_TOKEN")
|
|
|
8 |
pipe = pipeline("automatic-speech-recognition", model=model_id, token=hf_token)
|
9 |
|
10 |
def transcribe_speech(filepath):
|
11 |
+
# Check if the filepath is valid
|
12 |
if filepath is None:
|
13 |
raise ValueError("No audio file provided.")
|
14 |
|
15 |
+
# Perform speech transcription
|
16 |
output = pipe(
|
17 |
filepath,
|
18 |
max_new_tokens=256,
|
|
|
25 |
)
|
26 |
return output["text"]
|
27 |
|
28 |
+
# Create Gradio interfaces without the 'source' argument
|
29 |
mic_transcribe = gr.Interface(
|
30 |
fn=transcribe_speech,
|
31 |
+
inputs=gr.Audio(type="filepath"),
|
32 |
outputs="text",
|
33 |
)
|
34 |
|
35 |
file_transcribe = gr.Interface(
|
36 |
fn=transcribe_speech,
|
37 |
+
inputs=gr.Audio(type="filepath"),
|
38 |
outputs="text",
|
39 |
)
|
40 |
|
|
|
48 |
|
49 |
demo.launch(debug=True)
|
50 |
|
51 |
+
|