Update app.py
Browse files
app.py
CHANGED
@@ -31,30 +31,6 @@ def recap_sentence(string):
|
|
31 |
return recap_result
|
32 |
|
33 |
|
34 |
-
@spaces.GPU(duration=30)
|
35 |
-
def return_prediction_w2v2(mic=None, file=None, device=device):
|
36 |
-
if mic is not None:
|
37 |
-
waveform, sr = librosa.load(mic, sr=16000)
|
38 |
-
waveform = waveform[:60*sr]
|
39 |
-
w2v2_result = w2v2_classifier.classify_file_w2v2(waveform, device)
|
40 |
-
elif file is not None:
|
41 |
-
waveform, sr = librosa.load(file, sr=16000)
|
42 |
-
waveform = waveform[:60*sr]
|
43 |
-
w2v2_result = w2v2_classifier.classify_file_w2v2(waveform, device)
|
44 |
-
else:
|
45 |
-
return "You must either provide a mic recording or a file"
|
46 |
-
|
47 |
-
recap_result = recap_sentence(w2v2_result[0])
|
48 |
-
|
49 |
-
# If the letter after punct is small, recap it
|
50 |
-
for i, letter in enumerate(recap_result):
|
51 |
-
if i > 1 and recap_result[i-2] in [".", "!", "?"] and letter.islower():
|
52 |
-
recap_result = recap_result[:i] + letter.upper() + recap_result[i+1:]
|
53 |
-
|
54 |
-
clean_up_memory()
|
55 |
-
return recap_result
|
56 |
-
|
57 |
-
|
58 |
@spaces.GPU(duration=30)
|
59 |
def return_prediction_whisper_mic(mic=None, progress=gr.Progress(), device=device):
|
60 |
progress(0, desc="Транскриптот се генерира")
|
@@ -64,7 +40,7 @@ def return_prediction_whisper_mic(mic=None, progress=gr.Progress(), device=devic
|
|
64 |
# waveform = waveform[:30*sr]
|
65 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
66 |
else:
|
67 |
-
return "You must provide a mic recording"
|
68 |
|
69 |
recap_result = ""
|
70 |
prev_segment = ""
|
@@ -108,7 +84,7 @@ def return_prediction_whisper_file(file=None, progress=gr.Progress(), device=dev
|
|
108 |
# waveform = waveform[:3600*sr]
|
109 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
110 |
else:
|
111 |
-
return "You must provide a mic recording"
|
112 |
|
113 |
recap_result = ""
|
114 |
prev_segment = ""
|
@@ -161,7 +137,7 @@ recap_model.eval()
|
|
161 |
|
162 |
with gr.Blocks() as mic_transcribe_whisper:
|
163 |
def clear_outputs():
|
164 |
-
return
|
165 |
|
166 |
with gr.Row():
|
167 |
audio_input = gr.Audio(sources="microphone", type="filepath", label="Record Audio")
|
@@ -223,16 +199,6 @@ project_description = '''
|
|
223 |
4. **Никола Стиков**
|
224 |
|
225 |
Оваа колаборација е дел од активностите на **Центарот за напредни интердисциплинарни истражувања ([ЦеНИИс](https://ukim.edu.mk/en/centri/centar-za-napredni-interdisciplinarni-istrazhuvanja-ceniis))** при УКИМ.
|
226 |
-
|
227 |
-
## Во тренирањето на овој модел се употребени податоци од:
|
228 |
-
1. Дигитален архив за етнолошки и антрополошки ресурси ([ДАЕАР](https://iea.pmf.ukim.edu.mk/tabs/view/61f236ed7d95176b747c20566ddbda1a)) при Институтот за етнологија и антропологија, Природно-математички факултет при УКИМ.
|
229 |
-
2. Аудио верзија на меѓународното списание [„ЕтноАнтропоЗум“](https://etno.pmf.ukim.mk/index.php/eaz/issue/archive) на Институтот за етнологија и антропологија, Природно-математички факултет при УКИМ.
|
230 |
-
3. Аудио подкастот [„Обични луѓе“](https://obicniluge.mk/episodes/) на Илина Јакимовска
|
231 |
-
4. Научните видеа од серијалот [„Наука за деца“](http://naukazadeca.mk), фондација [КАНТАРОТ](https://qantarot.substack.com/)
|
232 |
-
5. Македонска верзија на [Mozilla Common Voice](https://commonvoice.mozilla.org/en/datasets) (верзија 18.0)
|
233 |
-
|
234 |
-
## Како да придонесете за подобрување на македонските модели за препознавање на говор?
|
235 |
-
На следниот [линк](https://drive.google.com/file/d/1YdZJz9o1X8AMc6J4MNPnVZjASyIXnvoZ/view?usp=sharing) ќе најдете инструкции за тоа како да донирате македонски говор преку платформата Mozilla Common Voice.
|
236 |
'''
|
237 |
|
238 |
# Custom CSS
|
@@ -261,12 +227,6 @@ with transcriber_app:
|
|
261 |
state = gr.State()
|
262 |
gr.Markdown(project_description, elem_classes="custom-markdown")
|
263 |
|
264 |
-
# gr.TabbedInterface(
|
265 |
-
# [mic_transcribe_whisper, mic_transcribe_compare],
|
266 |
-
# ["Буки-Whisper транскрипција", "Споредба на модели"],
|
267 |
-
# )
|
268 |
-
# state = gr.State(value=[], delete_callback=lambda v: print("STATE DELETED"))
|
269 |
-
|
270 |
gr.TabbedInterface(
|
271 |
[mic_transcribe_whisper, file_transcribe_whisper],
|
272 |
[" Буки-Whisper транскрипција од микрофон", "Буки-Whisper транскрипција од фајл"],
|
@@ -275,7 +235,6 @@ with transcriber_app:
|
|
275 |
|
276 |
transcriber_app.unload(return_prediction_whisper_mic)
|
277 |
transcriber_app.unload(return_prediction_whisper_file)
|
278 |
-
transcriber_app.unload(return_prediction_w2v2)
|
279 |
|
280 |
|
281 |
# transcriber_app.launch(debug=True, share=True, ssl_verify=False)
|
|
|
31 |
return recap_result
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
@spaces.GPU(duration=30)
|
35 |
def return_prediction_whisper_mic(mic=None, progress=gr.Progress(), device=device):
|
36 |
progress(0, desc="Транскриптот се генерира")
|
|
|
40 |
# waveform = waveform[:30*sr]
|
41 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
42 |
else:
|
43 |
+
return "You must provide a mic recording"
|
44 |
|
45 |
recap_result = ""
|
46 |
prev_segment = ""
|
|
|
84 |
# waveform = waveform[:3600*sr]
|
85 |
whisper_result = whisper_classifier.classify_file_whisper_mkd(waveform, device)
|
86 |
else:
|
87 |
+
return "You must provide a mic recording"
|
88 |
|
89 |
recap_result = ""
|
90 |
prev_segment = ""
|
|
|
137 |
|
138 |
with gr.Blocks() as mic_transcribe_whisper:
|
139 |
def clear_outputs():
|
140 |
+
return None, "", None
|
141 |
|
142 |
with gr.Row():
|
143 |
audio_input = gr.Audio(sources="microphone", type="filepath", label="Record Audio")
|
|
|
199 |
4. **Никола Стиков**
|
200 |
|
201 |
Оваа колаборација е дел од активностите на **Центарот за напредни интердисциплинарни истражувања ([ЦеНИИс](https://ukim.edu.mk/en/centri/centar-za-napredni-interdisciplinarni-istrazhuvanja-ceniis))** при УКИМ.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
'''
|
203 |
|
204 |
# Custom CSS
|
|
|
227 |
state = gr.State()
|
228 |
gr.Markdown(project_description, elem_classes="custom-markdown")
|
229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
gr.TabbedInterface(
|
231 |
[mic_transcribe_whisper, file_transcribe_whisper],
|
232 |
[" Буки-Whisper транскрипција од микрофон", "Буки-Whisper транскрипција од фајл"],
|
|
|
235 |
|
236 |
transcriber_app.unload(return_prediction_whisper_mic)
|
237 |
transcriber_app.unload(return_prediction_whisper_file)
|
|
|
238 |
|
239 |
|
240 |
# transcriber_app.launch(debug=True, share=True, ssl_verify=False)
|