Spaces:
Sleeping
Sleeping
Update Gradio/app.py
Browse files- Gradio/app.py +16 -20
Gradio/app.py
CHANGED
@@ -11,21 +11,24 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
11 |
|
12 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "Urdu-ASR-flags")
|
13 |
|
14 |
-
##############
|
15 |
|
16 |
-
Model = "kingabzpro/wav2vec2-large-xls-r-300m-Urdu"
|
17 |
-
# This is not working because Huggingface has completely changed the git server.
|
18 |
-
# from dagshub.streaming import install_hooks
|
19 |
-
# install_hooks()
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
23 |
|
24 |
-
def asr(audio):
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
|
31 |
################### Gradio Web APP ################################
|
@@ -47,19 +50,12 @@ article = "<p style='text-align: center'><a href='https://dagshub.com/kingabzpro
|
|
47 |
examples = [["Sample/sample1.mp3"], ["Sample/sample2.mp3"], ["Sample/sample3.mp3"]]
|
48 |
|
49 |
|
50 |
-
Input = gr.Audio(
|
51 |
-
source="microphone",
|
52 |
-
type="filepath",
|
53 |
-
label="Please Record Your Voice",
|
54 |
-
)
|
55 |
-
Output = gr.Textbox(label="Urdu Script")
|
56 |
-
|
57 |
|
58 |
def main():
|
59 |
iface = gr.Interface(
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
title=title,
|
64 |
allow_flagging="manual",
|
65 |
flagging_callback=hf_writer,
|
|
|
11 |
|
12 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "Urdu-ASR-flags")
|
13 |
|
14 |
+
############## Inference ##############################
|
15 |
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
|
18 |
+
|
19 |
+
def transcribe(audio):
|
20 |
+
sr, y = audio
|
21 |
+
y = y.astype(np.float32)
|
22 |
+
y /= np.max(np.abs(y))
|
23 |
|
24 |
+
return transcriber({"sampling_rate": sr, "raw": y})["text"]
|
25 |
|
|
|
26 |
|
27 |
+
demo = gr.Interface(
|
28 |
+
transcribe,
|
29 |
+
gr.Audio(sources=["microphone"]),
|
30 |
+
"text",
|
31 |
+
)
|
32 |
|
33 |
|
34 |
################### Gradio Web APP ################################
|
|
|
50 |
examples = [["Sample/sample1.mp3"], ["Sample/sample2.mp3"], ["Sample/sample3.mp3"]]
|
51 |
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
def main():
|
55 |
iface = gr.Interface(
|
56 |
+
transcribe,
|
57 |
+
gr.Audio(sources=["microphone"]),
|
58 |
+
"text",
|
59 |
title=title,
|
60 |
allow_flagging="manual",
|
61 |
flagging_callback=hf_writer,
|