Nông Văn Thắng
commited on
Commit
•
f718110
1
Parent(s):
5901011
main
Browse files
app.py
CHANGED
@@ -18,37 +18,11 @@ from huggingface_hub import hf_hub_download, snapshot_download
|
|
18 |
from underthesea import sent_tokenize
|
19 |
from unidecode import unidecode
|
20 |
from vinorm import TTSnorm
|
21 |
-
|
|
|
22 |
print("Setting up the environment...")
|
23 |
import subprocess
|
24 |
|
25 |
-
setup_command = [
|
26 |
-
"pip", "install", "--use-deprecated=legacy-resolver", "-e", ".", "-q",
|
27 |
-
"&&", "cd", "TTS ",
|
28 |
-
"&&", "git submodule update --init --recursive",
|
29 |
-
"&&", "echo", "Installing other requirements...",
|
30 |
-
"&&", "pip", "install", "-r", "requirements.txt", "-q",
|
31 |
-
"&&", "echo", "Downloading Japanese/Chinese tokenizer...",
|
32 |
-
"&&", "python", "-m", "unidic", "download",
|
33 |
-
"&&", "pip", "install", "--upgrade", "gradio"
|
34 |
-
]
|
35 |
-
|
36 |
-
try:
|
37 |
-
subprocess.run(setup_command, check=True, shell=True)
|
38 |
-
print("Environment setup completed successfully.")
|
39 |
-
except subprocess.CalledProcessError as e:
|
40 |
-
print(f"Error during environment setup: {e}")
|
41 |
-
print("Please run the setup command manually if needed.")
|
42 |
-
|
43 |
-
print("\nTo set up the environment manually, run the following command:")
|
44 |
-
print("pip install --use-deprecated=legacy-resolver -e . -q && \\ ")
|
45 |
-
print("cd .. && \\ ")
|
46 |
-
print("echo \"Installing other requirements...\" && \\ ")
|
47 |
-
print("pip install -r requirements.txt -q && \\ ")
|
48 |
-
print("echo \"Downloading Japanese/Chinese tokenizer...\" && \\ ")
|
49 |
-
print("python -m unidic download && \\ ")
|
50 |
-
print("pip install --upgrade gradio")
|
51 |
-
|
52 |
XTTS_MODEL = None
|
53 |
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
54 |
MODEL_DIR = os.path.join(SCRIPT_DIR, "model")
|
@@ -84,20 +58,21 @@ def load_model(checkpoint_dir="model/", repo_id="capleaf/viXTTS", use_deepspeed=
|
|
84 |
yield f"Model download finished..."
|
85 |
|
86 |
xtts_config = os.path.join(checkpoint_dir, "config.json")
|
87 |
-
|
88 |
-
from TTS.tts.models.xtts import Xtts
|
89 |
config = XttsConfig()
|
90 |
config.load_json(xtts_config)
|
91 |
XTTS_MODEL = Xtts.init_from_config(config)
|
92 |
-
yield "
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
101 |
|
102 |
|
103 |
# Define dictionaries to store cached results
|
@@ -362,7 +337,7 @@ if __name__ == "__main__":
|
|
362 |
value=True, label="Sử dụng DeepSpeed để suy luận nhanh hơn"
|
363 |
)
|
364 |
|
365 |
-
progress_load = gr.Label(label="
|
366 |
load_btn = gr.Button(
|
367 |
value="Khởi tạo model", variant="primary"
|
368 |
)
|
@@ -399,7 +374,7 @@ if __name__ == "__main__":
|
|
399 |
)
|
400 |
|
401 |
use_filter = gr.Checkbox(
|
402 |
-
label="Lọc
|
403 |
value=True,
|
404 |
)
|
405 |
|
|
|
18 |
from underthesea import sent_tokenize
|
19 |
from unidecode import unidecode
|
20 |
from vinorm import TTSnorm
|
21 |
+
from TTS.tts.configs.xtts_config import XttsConfig
|
22 |
+
from TTS.tts.models.xtts import Xtts
|
23 |
print("Setting up the environment...")
|
24 |
import subprocess
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
XTTS_MODEL = None
|
27 |
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
28 |
MODEL_DIR = os.path.join(SCRIPT_DIR, "model")
|
|
|
58 |
yield f"Model download finished..."
|
59 |
|
60 |
xtts_config = os.path.join(checkpoint_dir, "config.json")
|
61 |
+
|
|
|
62 |
config = XttsConfig()
|
63 |
config.load_json(xtts_config)
|
64 |
XTTS_MODEL = Xtts.init_from_config(config)
|
65 |
+
yield "Đang tải model.."
|
66 |
+
try:
|
67 |
+
XTTS_MODEL.load_checkpoint(
|
68 |
+
config, checkpoint_dir=checkpoint_dir, use_deepspeed=use_deepspeed
|
69 |
+
)
|
70 |
+
if torch.cuda.is_available():
|
71 |
+
XTTS_MODEL.cuda()
|
72 |
+
except:
|
73 |
+
print("error")
|
74 |
+
finally:
|
75 |
+
yield "Đã tải model!"
|
76 |
|
77 |
|
78 |
# Define dictionaries to store cached results
|
|
|
337 |
value=True, label="Sử dụng DeepSpeed để suy luận nhanh hơn"
|
338 |
)
|
339 |
|
340 |
+
progress_load = gr.Label(label="Tiến trình:")
|
341 |
load_btn = gr.Button(
|
342 |
value="Khởi tạo model", variant="primary"
|
343 |
)
|
|
|
374 |
)
|
375 |
|
376 |
use_filter = gr.Checkbox(
|
377 |
+
label="Lọc tiếng ồn",
|
378 |
value=True,
|
379 |
)
|
380 |
|