Spaces:
Running
Running
Update app_utils.py
Browse files- app_utils.py +17 -109
app_utils.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import os
|
2 |
import json
|
3 |
-
import gradio as gr
|
4 |
import shutil
|
5 |
import subprocess
|
6 |
import requests
|
@@ -12,67 +11,21 @@ import numpy as np
|
|
12 |
|
13 |
|
14 |
models = [
|
15 |
-
['mms fa','https://huggingface.co/willwade/mms-tts-multilingual-models-onnx/resolve/main/fas'],
|
16 |
-
['coqui-vits-female1-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/persian-tts-female1-vits-coqui'],
|
17 |
-
['coqui-vits-male1-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/persian-tts-male1-vits-coqui'],
|
18 |
-
['coqui-vits-male-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/male-male-coqui-vits'],
|
19 |
-
['coqui-vits-female-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/female-female-coqui-vits'],
|
20 |
-
['coqui-vits-female-GPTInformal-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/female-GPTInformal-coqui-vits'],
|
21 |
-
['coqui-vits-male-SmartGitiCorp','https://huggingface.co/karim23657/persian-tts-vits/tree/main/male-SmartGitiCorp-coqui-vits'],
|
22 |
-
['vits-piper-fa-
|
23 |
-
['piper-fa-
|
24 |
-
['vits-
|
25 |
-
['
|
|
|
|
|
26 |
]
|
27 |
-
|
28 |
-
[
|
29 |
-
"mms fa",
|
30 |
-
"🌠 راد"
|
31 |
-
],
|
32 |
-
[
|
33 |
-
"coqui-vits-female1-karim23657",
|
34 |
-
"🌺 نگار"
|
35 |
-
],
|
36 |
-
[
|
37 |
-
"coqui-vits-male1-karim23657",
|
38 |
-
"🌟 آرش"
|
39 |
-
],
|
40 |
-
[
|
41 |
-
"coqui-vits-male-karim23657",
|
42 |
-
"🦁 کیان"
|
43 |
-
],
|
44 |
-
[
|
45 |
-
"coqui-vits-female-karim23657",
|
46 |
-
"🌷 مهتاب"
|
47 |
-
],
|
48 |
-
[
|
49 |
-
"coqui-vits-female-GPTInformal-karim23657",
|
50 |
-
"🌼 شیوا"
|
51 |
-
],
|
52 |
-
[
|
53 |
-
"coqui-vits-male-SmartGitiCorp",
|
54 |
-
"🚀 بهمن"
|
55 |
-
],
|
56 |
-
[
|
57 |
-
"vits-piper-fa-gyro-medium",
|
58 |
-
"💧 نیما"
|
59 |
-
],
|
60 |
-
[
|
61 |
-
"piper-fa-amir-medium",
|
62 |
-
"⚡️ آریا"
|
63 |
-
],
|
64 |
-
[
|
65 |
-
"vits-mimic3-fa-haaniye_low",
|
66 |
-
"🌹 ریما"
|
67 |
-
],
|
68 |
-
[
|
69 |
-
"vits-piper-fa_en-rezahedayatfar-ibrahimwalk-medium",
|
70 |
-
"🌠 پیام"
|
71 |
-
]
|
72 |
-
]
|
73 |
-
for i,m in enumerate(models):
|
74 |
-
models_n[i][0]=m[1]
|
75 |
-
dropdown_choices = list([i[1] for i in models_n])
|
76 |
def download_and_extract_model(url, destination):
|
77 |
"""Download and extract the model files."""
|
78 |
print(f"Downloading from URL: {url}")
|
@@ -272,9 +225,9 @@ def generate_audio(text, model_info):
|
|
272 |
if not os.path.exists(model_dir):
|
273 |
print(f"Model directory doesn't exist, downloading {model_info}...")
|
274 |
os.makedirs(model_dir, exist_ok=True)
|
275 |
-
for i in
|
276 |
-
if model_info == i[
|
277 |
-
model_url=i[
|
278 |
download_and_extract_model(model_url, model_dir)
|
279 |
|
280 |
print(f"Contents of {model_dir}:")
|
@@ -414,48 +367,3 @@ def tts_interface(selected_model, text, status_output):
|
|
414 |
error_msg = str(e)
|
415 |
return None, f"Error: {error_msg}"
|
416 |
|
417 |
-
# Gradio Interface
|
418 |
-
with gr.Blocks() as app:
|
419 |
-
gr.Markdown("# Sherpa-ONNX متن به گفتار")
|
420 |
-
with gr.Row():
|
421 |
-
with gr.Column():
|
422 |
-
model_dropdown = gr.Radio(
|
423 |
-
choices=dropdown_choices,
|
424 |
-
label="مدل",
|
425 |
-
value=dropdown_choices[0] if dropdown_choices else None
|
426 |
-
)
|
427 |
-
text_input = gr.Textbox(
|
428 |
-
label="متن",
|
429 |
-
placeholder="متن را وارد کنید ...",
|
430 |
-
lines=3
|
431 |
-
)
|
432 |
-
|
433 |
-
with gr.Row():
|
434 |
-
generate_btn = gr.Button("بگو")
|
435 |
-
stop_btn = gr.Button("توقف")
|
436 |
-
|
437 |
-
with gr.Column():
|
438 |
-
audio_output = gr.Audio(
|
439 |
-
label="گفتار",
|
440 |
-
type="numpy"
|
441 |
-
)
|
442 |
-
status_text = gr.Textbox(
|
443 |
-
label="وضعیت",
|
444 |
-
interactive=False
|
445 |
-
)
|
446 |
-
|
447 |
-
|
448 |
-
# Set up event handlers
|
449 |
-
gen_event = generate_btn.click(
|
450 |
-
fn=tts_interface,
|
451 |
-
inputs=[model_dropdown, text_input, status_text],
|
452 |
-
outputs=[audio_output, status_text]
|
453 |
-
)
|
454 |
-
|
455 |
-
stop_btn.click(
|
456 |
-
fn=None,
|
457 |
-
cancels=gen_event,
|
458 |
-
queue=False
|
459 |
-
)
|
460 |
-
|
461 |
-
app.launch()
|
|
|
1 |
import os
|
2 |
import json
|
|
|
3 |
import shutil
|
4 |
import subprocess
|
5 |
import requests
|
|
|
11 |
|
12 |
|
13 |
models = [
|
14 |
+
['mms fa','https://huggingface.co/willwade/mms-tts-multilingual-models-onnx/resolve/main/fas',"🌠 راد",'https://huggingface.co/facebook/mms-tts-fas'],
|
15 |
+
['coqui-vits-female1-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/persian-tts-female1-vits-coqui',"🌺 نگار",'https://huggingface.co/Kamtera/persian-tts-female1-vits'],
|
16 |
+
['coqui-vits-male1-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/persian-tts-male1-vits-coqui',"🌟 آرش",'https://huggingface.co/Kamtera/persian-tts-male1-vits'],
|
17 |
+
['coqui-vits-male-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/male-male-coqui-vits',"🦁 کیان",'https://huggingface.co/Kamtera/persian-tts-male-vits'],
|
18 |
+
['coqui-vits-female-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/female-female-coqui-vits',"🌷 مهتاب",'https://huggingface.co/Kamtera/persian-tts-female-vits'],
|
19 |
+
['coqui-vits-female-GPTInformal-karim23657','https://huggingface.co/karim23657/persian-tts-vits/tree/main/female-GPTInformal-coqui-vits',"🌼 شیوا",'https://huggingface.co/karim23657/persian-tts-female-GPTInformal-Persian-vits'],
|
20 |
+
['coqui-vits-male-SmartGitiCorp','https://huggingface.co/karim23657/persian-tts-vits/tree/main/male-SmartGitiCorp-coqui-vits',"🚀 بهمن",'https://huggingface.co/SmartGitiCorp/persian_tts_vits'],
|
21 |
+
['vits-piper-fa-ganji','https://huggingface.co/karim23657/persian-tts-vits/tree/main/vits-piper-fa-ganji',"🚀 برنا",'https://huggingface.co/SadeghK/persian-text-to-speech'],
|
22 |
+
['vits-piper-fa-ganji-adabi','https://huggingface.co/karim23657/persian-tts-vits/tree/main/vits-piper-fa-ganji-adabi',"🚀 برنا-1",'https://huggingface.co/SadeghK/persian-text-to-speech'],
|
23 |
+
['vits-piper-fa-gyro-medium','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-fa_IR-gyro-medium.tar.bz2',"💧 نیما",'https://huggingface.co/gyroing/Persian-Piper-Model-gyro'],
|
24 |
+
['piper-fa-amir-medium','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-fa_IR-amir-medium.tar.bz2',"⚡️ آریا",'https://huggingface.co/SadeghK/persian-text-to-speech'],
|
25 |
+
['vits-mimic3-fa-haaniye_low','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-mimic3-fa-haaniye_low.tar.bz2',"🌹 ریما",'https://github.com/MycroftAI/mimic3'],
|
26 |
+
['vits-piper-fa_en-rezahedayatfar-ibrahimwalk-medium','https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-piper-fa_en-rezahedayatfar-ibrahimwalk-medium.tar.bz2',"🌠 پیام",'https://huggingface.co/mah92/persian-english-piper-tts-model'],
|
27 |
]
|
28 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
def download_and_extract_model(url, destination):
|
30 |
"""Download and extract the model files."""
|
31 |
print(f"Downloading from URL: {url}")
|
|
|
225 |
if not os.path.exists(model_dir):
|
226 |
print(f"Model directory doesn't exist, downloading {model_info}...")
|
227 |
os.makedirs(model_dir, exist_ok=True)
|
228 |
+
for i in models:
|
229 |
+
if model_info == i[2]:
|
230 |
+
model_url=i[1]
|
231 |
download_and_extract_model(model_url, model_dir)
|
232 |
|
233 |
print(f"Contents of {model_dir}:")
|
|
|
367 |
error_msg = str(e)
|
368 |
return None, f"Error: {error_msg}"
|
369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|