File size: 1,993 Bytes
e29e51c
 
 
 
 
 
 
 
 
df4dcda
 
 
e29e51c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b06cb80
e29e51c
8057a6f
e29e51c
 
 
 
54b920c
e29e51c
 
 
7b9b10a
078d7bc
e29e51c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e01d41
e29e51c
 
 
 
3e01d41
e29e51c
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import unicodedata
from datasets import load_dataset, Audio
from transformers import pipeline
import gradio as gr
import torch

############### HF ###########################

#HF_TOKEN = os.getenv("HF_TOKEN")
HF_TOKEN = "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"
os.environ["HF_TOKEN"] = HF_TOKEN

hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "Urdu-ASR-flags")

############## DagsHub ################################

Model = "kingabzpro/wav2vec2-large-xls-r-300m-Urdu"
# This is not working because Huggingface has completely changed the git server. 
# from dagshub.streaming import install_hooks
# install_hooks()

############## Inference ##############################


def asr(audio):

    asr = pipeline("automatic-speech-recognition", model=Model)
    prediction = asr(audio, chunk_length_s=30)
    return unicodedata.normalize("NFC",prediction["text"])


################### Gradio Web APP ################################
#<img src="https://huggingface.co/spaces/kingabzpro/Urdu-ASR-SOTA/resolve/main/Images/cover.jpg" alt="logo" width="550"/>

title = "Automatic Speech Recognition System for Urdu Language"

description = """
<p>
<center>

</center>
</p>
"""
article = "<p style='text-align: center'><a href='https://seventick.com/asr-model-for-urdu-language/' target='_blank'>Visit for more info</a></p>"
examples = [["Sample/sample1.mp3"], ["Sample/sample2.mp3"]]


Input = gr.Audio(
    source="microphone",
    type="filepath",
    label="Please Record Your Voice",
)
Output = gr.Textbox(label="Urdu Script")


def main():
    iface = gr.Interface(
        asr,
        Input,
        Output,
        title=title,
        allow_flagging="manual",
        flagging_callback=hf_writer,
        description=description,
        article=article,
        examples=examples,
        theme='sketch'
    )

    iface.launch(enable_queue=True)

# theme='JohnSmith9982/small_and_pretty'
# enable_queue=True,auth=("admin", "pass1234")

if __name__ == "__main__":
    main()