Spaces:
Running
Running
Added app.py
Browse files
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tempfile
|
3 |
+
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
from torch import no_grad, package
|
6 |
+
import ctypes
|
7 |
+
import gc
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
config = {
|
12 |
+
"mykyta": "theodotus/tts-vits-mykyta-uk",
|
13 |
+
"olena": "theodotus/tts-vits-olena-uk",
|
14 |
+
"lada": "theodotus/tts-vits-lada-uk",
|
15 |
+
}
|
16 |
+
|
17 |
+
voices = list(config.keys())
|
18 |
+
|
19 |
+
tts_kwargs = {
|
20 |
+
"speaker_name": "uk",
|
21 |
+
"language_name": "uk",
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
def trim_memory():
|
26 |
+
libc = ctypes.CDLL("libc.so.6")
|
27 |
+
libc.malloc_trim(0)
|
28 |
+
gc.collect()
|
29 |
+
|
30 |
+
|
31 |
+
def init_models():
|
32 |
+
models = {}
|
33 |
+
for name, model_name in config.items():
|
34 |
+
model_path = hf_hub_download(model_name, "model.pt")
|
35 |
+
importer = package.PackageImporter(model_path)
|
36 |
+
synt = importer.load_pickle("tts_models", "model")
|
37 |
+
models[name] = synt
|
38 |
+
return models
|
39 |
+
|
40 |
+
|
41 |
+
def tts(text: str, voice: str):
|
42 |
+
synt = models[voice]
|
43 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
44 |
+
with no_grad():
|
45 |
+
wav_data = synt.tts(text, **tts_kwargs)
|
46 |
+
synt.save_wav(wav_data, fp)
|
47 |
+
trim_memory()
|
48 |
+
return fp.name
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
models = init_models()
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
iface = gr.Interface(
|
57 |
+
fn=tts,
|
58 |
+
inputs=[
|
59 |
+
gr.Textbox(
|
60 |
+
label="Input",
|
61 |
+
value="К+ам'ян+ець-Под+ільський - м+істо в Хмельн+ицькій +області Укра+їни, ц+ентр Кам'ян+ець-Под+ільської міськ+ої об'+єднаної територі+альної гром+ади +і Кам'ян+ець-Под+ільського рай+ону.",
|
62 |
+
),
|
63 |
+
gr.Radio(
|
64 |
+
label="Voice",
|
65 |
+
choices=voices,
|
66 |
+
value=voices[0],
|
67 |
+
),
|
68 |
+
],
|
69 |
+
outputs=gr.Audio(label="Output"),
|
70 |
+
title="🇺🇦 - Ukrainian Voices",
|
71 |
+
)
|
72 |
+
|
73 |
+
iface.launch()
|