Spaces:
Runtime error
Runtime error
AkshatJain1402
commited on
Commit
•
0150ddb
1
Parent(s):
8e58957
made a git file retriever
Browse files
app.py
CHANGED
@@ -1,180 +1,18 @@
|
|
1 |
-
import
|
2 |
-
from
|
3 |
-
import nemo.collections.asr as nemo_asr
|
4 |
-
from pydub import AudioSegment
|
5 |
-
import subprocess
|
6 |
-
import io
|
7 |
-
import os
|
8 |
-
import uuid
|
9 |
-
# from func_timeout import func_timeout, FunctionTimedOut
|
10 |
-
import streamlit.components.v1 as components
|
11 |
-
import wave
|
12 |
-
import shutil
|
13 |
-
import contextlib
|
14 |
|
|
|
|
|
|
|
15 |
|
16 |
-
def
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
download = subprocess.run(["wget","-P",model_path,model_link],capture_output=True, text=True)
|
21 |
-
|
22 |
-
if download.returncode != 0:
|
23 |
-
raise Exception(lang + " Model Download Failed: {download.stderr}")
|
24 |
-
|
25 |
-
else:
|
26 |
-
print('Downloaded AM: ' + lang)
|
27 |
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
@st.cache_resource
|
31 |
-
def get_model():
|
32 |
-
try:
|
33 |
-
os.makedirs("audio_cache")
|
34 |
-
except:
|
35 |
-
shutil.rmtree("audio_cache")
|
36 |
-
os.makedirs("audio_cache")
|
37 |
-
|
38 |
-
download_model("./hi_am_model", "https://storage.googleapis.com/vakyansh-open-models/conformer_models/hindi/filtered_v1_ssl_2022-07-08_19-43-25/Conformer-CTC-BPE-Large.nemo", "hindi")
|
39 |
-
download_model("./en_am_model", "https://storage.googleapis.com/vakyansh-open-models/conformer_models/english/2022-09-13_15-50-48/Conformer-CTC-BPE-Large.nemo", "english")
|
40 |
-
|
41 |
-
try:
|
42 |
-
en_asr_model = nemo_asr.models.EncDecCTCModelBPE.restore_from("./en_am_model/Conformer-CTC-BPE-Large.nemo") #("/home/tanmay/zb/en_Conformer-CTC-BPE-Large.nemo")
|
43 |
-
hi_asr_model = nemo_asr.models.EncDecCTCModelBPE.restore_from("./hi_am_model/Conformer-CTC-BPE-Large.nemo") #("/home/tanmay/zb/hi_Conformer-CTC-BPE-Large.nemo")
|
44 |
-
except Exception as e:
|
45 |
-
print("ERROR Loading Model... ",e)
|
46 |
-
exit (1)
|
47 |
-
|
48 |
-
return en_asr_model, hi_asr_model
|
49 |
-
|
50 |
-
|
51 |
-
en_asr_model, hi_asr_model = get_model()
|
52 |
-
|
53 |
-
|
54 |
-
def get_audio_length_wave(filename):
|
55 |
-
with contextlib.closing(wave.open(filename,'r')) as f:
|
56 |
-
frames = f.getnframes()
|
57 |
-
rate = f.getframerate()
|
58 |
-
duration = frames / float(rate)
|
59 |
-
return duration
|
60 |
-
|
61 |
-
def save_audio_file_using_mic(audio_location, wav_audio_data):
|
62 |
-
audio_file = io.BytesIO(wav_audio_data)
|
63 |
-
audio = AudioSegment.from_file(audio_file)
|
64 |
-
audio = audio.set_sample_width(2)
|
65 |
-
audio = audio.set_channels(1)
|
66 |
-
audio = audio.set_frame_rate(16000)
|
67 |
-
audio.export(audio_location, format="wav")
|
68 |
-
|
69 |
-
def delete_audio_file(audio_location):
|
70 |
-
if os.path.exists(audio_location):
|
71 |
-
try:
|
72 |
-
os.remove(audio_location)
|
73 |
-
print(f"File deleted: {audio_location}")
|
74 |
-
except OSError as e:
|
75 |
-
print(f"Error deleting file: {e}")
|
76 |
-
|
77 |
-
def save_audio_file_using_upload(audio_location, uploaded_file):
|
78 |
-
|
79 |
-
if not uploaded_file.name.endswith(".wav"):
|
80 |
-
st.write("ERROR! File extension should be wav")
|
81 |
-
return 0
|
82 |
-
|
83 |
-
# get audio file length
|
84 |
-
with open(audio_location, "wb") as f:
|
85 |
-
f.write(uploaded_file.getvalue())
|
86 |
-
audioDuration = get_audio_length_wave(audio_location)
|
87 |
-
|
88 |
-
st.write("Audio Duration: ",audioDuration)
|
89 |
-
if audioDuration < 60 and audioDuration > 0:
|
90 |
-
return 1
|
91 |
-
else:
|
92 |
-
st.write('ERROR! File is more than 1 minute')
|
93 |
-
st.write('Uploaded File duration is restricted upto 1 minute')
|
94 |
-
return 0
|
95 |
-
|
96 |
-
########################################################################################################################################
|
97 |
-
# APP FUNCTIONALITY STARTS #
|
98 |
-
########################################################################################################################################
|
99 |
-
|
100 |
-
st.title("💬 Vocalize: Empower Your Voice ")
|
101 |
-
st.write("You can either try to record your own voice using a microphone or upload a small file, up to 1 minute in length, to transcribe.")
|
102 |
-
st.write('')
|
103 |
-
|
104 |
-
col1, ___, ____ = st.columns(3)
|
105 |
-
|
106 |
-
with col1:
|
107 |
-
language = st.selectbox('Select Your Preferred Language.',('English', 'Hindi'))
|
108 |
-
|
109 |
-
|
110 |
-
st.header("Transcribe Your Voice Using Mic")
|
111 |
-
wav_audio_data = st_audiorec()
|
112 |
-
|
113 |
-
if wav_audio_data:
|
114 |
-
|
115 |
-
audio_location = "audio_cache/" + str(uuid.uuid4()) + ".wav"
|
116 |
-
|
117 |
-
save_audio_file_using_mic(audio_location, wav_audio_data)
|
118 |
-
|
119 |
-
if language == "Hindi":
|
120 |
-
text = hi_asr_model.transcribe([audio_location], logprobs=False)[0]
|
121 |
-
|
122 |
-
else:
|
123 |
-
text = en_asr_model.transcribe([audio_location], logprobs=False)[0]
|
124 |
-
|
125 |
-
print(text)
|
126 |
-
st.write("Transcription:")
|
127 |
-
st.write(text)
|
128 |
-
|
129 |
-
delete_audio_file(audio_location)
|
130 |
-
|
131 |
-
|
132 |
-
st.header("Transcribe Files")
|
133 |
-
st.write("Ensure that the file extension is .wav with a sample rate of 16,000 Hz and a single channel (mono)")
|
134 |
-
|
135 |
-
try:
|
136 |
-
|
137 |
-
uploaded_file = st.file_uploader("Upload Your Recording", disabled=False,type='')
|
138 |
-
|
139 |
-
if uploaded_file is not None:
|
140 |
-
|
141 |
-
# Store the uploaded file:
|
142 |
-
audio_location = "audio_cache/" + str(uuid.uuid4()) + ".wav"
|
143 |
-
|
144 |
-
flag = save_audio_file_using_upload(audio_location, uploaded_file)
|
145 |
-
if flag == 1:
|
146 |
-
if language == "Hindi":
|
147 |
-
with st.spinner():
|
148 |
-
text = hi_asr_model.transcribe([audio_location], logprobs=False)[0]
|
149 |
-
print(text)
|
150 |
-
else:
|
151 |
-
with st.spinner():
|
152 |
-
text = en_asr_model.transcribe([audio_location], logprobs=False)[0]
|
153 |
-
print(text)
|
154 |
-
|
155 |
-
st.write(text)
|
156 |
-
|
157 |
-
delete_audio_file(audio_location)
|
158 |
-
|
159 |
-
except Exception as e:
|
160 |
-
st.write("ERROR! Something is wrong with the uploaded file.")
|
161 |
-
st.write("The file extension should be .wav with a sample rate of 16,000 Hz and a mono channel")
|
162 |
-
print(str(e))
|
163 |
-
delete_audio_file(audio_location)
|
164 |
-
|
165 |
-
|
166 |
-
# Footer mentioning the website
|
167 |
-
footer = """
|
168 |
-
<style>
|
169 |
-
.footer {
|
170 |
-
width: 100%;
|
171 |
-
text-align: center;
|
172 |
-
padding: 10px 0;
|
173 |
-
margin-top: 240px; /* Add margin-top for some gap */
|
174 |
-
}
|
175 |
-
</style>
|
176 |
-
<div class="footer">
|
177 |
-
<p>Powered by: <a href="https://zinglebytes.com">zinglebytes.com</a> | <a href="mailto:info@zinglebytes.com">Email us</a></p>
|
178 |
-
</div>
|
179 |
-
"""
|
180 |
-
st.markdown(footer, unsafe_allow_html=True)
|
|
|
1 |
+
import git
|
2 |
+
from git import Repo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
GITHUB_USERNAME = "AkshatJain1402"
|
5 |
+
GITHUB_PAT = "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"
|
6 |
+
REPO_URL = "https://github.com/AkshatJain1402/finalASRNEMO"
|
7 |
|
8 |
+
def clone_and_execute():
|
9 |
+
repo = Repo.clone_from(f"{REPO_URL}", "repo_folder", auth=("token", GITHUB_PAT)) # Clone into a local folder
|
10 |
|
11 |
+
# Import the module (assuming app.py is in the root)
|
12 |
+
import repo_folder.app as app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# Execute the main function
|
15 |
+
if __name__ == "__main__":
|
16 |
+
app.main()
|
17 |
|
18 |
+
clone_and_execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|