Spaces:
Runtime error
Runtime error
Commit
•
e72779d
1
Parent(s):
7c19fb8
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,45 @@
|
|
1 |
-
import
|
2 |
-
import torchaudio
|
3 |
import gradio as gr
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
def transcribe(audio):
|
13 |
-
waveform, sample_rate = torchaudio.load(audio.name)
|
14 |
-
input_dict = processor(waveform, return_tensors="pt", padding=True)
|
15 |
-
logits = model(input_dict.input_values).logits
|
16 |
-
predicted_ids = torch.argmax(logits, dim=-1).squeeze()
|
17 |
-
transcription = processor.decode(predicted_ids)
|
18 |
-
return transcription
|
19 |
|
20 |
-
|
21 |
-
audio_input = gr.inputs.Audio(source="upload", type="file", label="Upload audio file")
|
22 |
-
text_output = gr.outputs.Textbox(label="Transcription")
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
|
|
2 |
import gradio as gr
|
3 |
+
import time
|
4 |
+
import unicodedata
|
5 |
+
p = pipeline("automatic-speech-recognition",model="kingabzpro/wav2vec2-large-xls-r-300m-Urdu")
|
6 |
|
7 |
+
def transcribe(audio, state=""):
|
8 |
+
time.sleep(2)
|
9 |
+
text = p(audio)["text"]
|
10 |
+
state += unicodedata.normalize("NFC",text) + " "
|
11 |
+
return state, state
|
12 |
|
13 |
+
################### Gradio Web APP ################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
title = "Real-Time Urdu ASR"
|
|
|
|
|
16 |
|
17 |
+
description = """
|
18 |
+
<p>
|
19 |
+
<center>
|
20 |
+
This model is a fine-tuned version of facebook/wav2vec2-xls-r-300m on the common_voice dataset.
|
21 |
+
</center>
|
22 |
+
</p>
|
23 |
+
<center>
|
24 |
+
<img src="https://huggingface.co/spaces/kingabzpro/real-time-Urdu-ASR/resolve/main/Images/cover.jpg" alt="logo" width="550"/>
|
25 |
+
</center>
|
26 |
+
"""
|
27 |
+
|
28 |
+
article = "<p style='text-align: center'><a href='https://dagshub.com/kingabzpro/Urdu-ASR-SOTA' target='_blank'>Source Code on DagsHub</a></p><p style='text-align: center'><a href='https://huggingface.co/blog/fine-tune-xlsr-wav2vec2' target='_blank'>Fine-tuning XLS-R for Multi-Lingual ASR with 🤗 Transformers</a></p></center><center><img src='https://visitor-badge.glitch.me/badge?page_id=kingabzpro/real-time-Urdu-ASR' alt='visitor badge'></center></p>"
|
29 |
+
|
30 |
+
|
31 |
+
gr.Interface(
|
32 |
+
fn=transcribe,
|
33 |
+
inputs=[
|
34 |
+
gr.Audio(source="microphone", type="filepath", streaming=True),
|
35 |
+
"state"
|
36 |
+
],
|
37 |
+
outputs=[
|
38 |
+
"textbox",
|
39 |
+
"state"
|
40 |
+
],
|
41 |
+
title=title,
|
42 |
+
description=description,
|
43 |
+
article=article,
|
44 |
+
theme='EveryPizza/Cartoony-Gradio-Theme',
|
45 |
+
live=True).launch()
|