cdactvm commited on
Commit
51cfe72
1 Parent(s): 1004043

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries and filter warnings
2
+ import warnings
3
+ warnings.filterwarnings("ignore")
4
+
5
+ import os
6
+ import re
7
+ import torchaudio
8
+ import gradio as gr
9
+ import numpy as np
10
+ from transformers import pipeline
11
+ from transformers import AutoProcessor
12
+ from pyctcdecode import build_ctcdecoder
13
+ from transformers import Wav2Vec2ProcessorWithLM
14
+ from text2int import text_to_int
15
+ from isNumber import is_number
16
+ from Text2List import text_to_list
17
+ from convert2list import convert_to_list
18
+ from processDoubles import process_multiples
19
+ from replaceWords import replace_words
20
+
21
+ pipe = pipeline(task="automatic-speech-recognition", model="C:/Users/WCHL/Desktop/huggingface_english/hf_eng")
22
+
23
+
24
+ def transcribe_english(audio):
25
+ # # Process the audio file
26
+ transcript = pipe(audio)
27
+ text_value = transcript['text']
28
+ cleaned_text=text_value.replace("<s>", "")
29
+ converted_to_list=convert_to_list(cleaned_text,text_to_list())
30
+ processd_multiples=process_multiples(converted_to_list)
31
+ replaced_words = replace_words(processd_multiples)
32
+ converted_text=text_to_int(replaced_words)
33
+ return converted_text
34
+
35
+ # def sel_lng(lng, mic=None, file=None):
36
+ # if mic is not None:
37
+ # audio = mic
38
+ # elif file is not None:
39
+ # audio = file
40
+ # else:
41
+ # return "You must either provide a mic recording or a file"
42
+
43
+ # if lng == "model_1":
44
+ # return transcribe_hindi_old(audio)
45
+ # elif lng == "model_2":
46
+ # return transcribe_hindi_new(audio)
47
+ # elif lng== "model_3":
48
+ # return transcribe_hindi_lm(audio)
49
+
50
+ demo=gr.Interface(
51
+ transcribe_english,
52
+ inputs=[
53
+ gr.Audio(sources=["microphone","upload"], type="filepath"),
54
+ ],
55
+ outputs=[
56
+ "textbox"
57
+ ],
58
+ title="Automatic Speech Recognition",
59
+ description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
60
+ ).launch()
61
+
62
+ # demo=gr.Interface(
63
+ # fn=sel_lng,
64
+
65
+ # inputs=[
66
+ # gr.Dropdown([
67
+ # "model_1","model_2","model_3"],label="Select Model"),
68
+ # gr.Audio(sources=["microphone","upload"], type="filepath"),
69
+ # ],
70
+ # outputs=[
71
+ # "textbox"
72
+ # ],
73
+ # title="Automatic Speech Recognition",
74
+ # description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
75
+ # ).launch()