on1onmangoes commited on
Commit
517848a
·
1 Parent(s): 88430f1

Simple Real Time ASR

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()