Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,21 +5,52 @@ import zipfile
|
|
5 |
import requests
|
6 |
from TTS.api import TTS
|
7 |
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
model_sharing_section = gr.components.Section("Model Sharing")
|
12 |
|
13 |
-
|
14 |
-
model_output = gr.components.Markdown(label="Shared Models")
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Combine the two interfaces
|
25 |
iface = gr.Interface(
|
@@ -36,9 +67,12 @@ iface = gr.Interface(
|
|
36 |
use this colab with caution <3.
|
37 |
""",
|
38 |
theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate"),
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
)
|
41 |
|
42 |
-
iface.add_component(model_sharing_iface, "Model Sharing")
|
43 |
-
|
44 |
iface.launch(share=True)
|
|
|
5 |
import requests
|
6 |
from TTS.api import TTS
|
7 |
|
8 |
+
# Verifica se è disponibile una GPU, altrimenti utilizza la CPU
|
9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
+
os.environ["COQUI_TOS_AGREED"] = "1"
|
|
|
12 |
|
13 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
|
|
|
14 |
|
15 |
+
def clone(text, url, language):
|
16 |
+
response = requests.get(url)
|
17 |
+
|
18 |
+
with open("temp.zip", "wb") as f:
|
19 |
+
f.write(response.content)
|
20 |
+
|
21 |
+
with zipfile.ZipFile("temp.zip", "r") as zip_ref:
|
22 |
+
zip_ref.extractall()
|
23 |
+
|
24 |
+
audio_file = [f for f in os.listdir(".") if f.endswith(".wav")][0]
|
25 |
+
|
26 |
+
tts.tts_to_file(text=text, speaker_wav=audio_file, language=language, file_path="./output.wav")
|
27 |
+
|
28 |
+
os.remove(audio_file)
|
29 |
+
os.remove("temp.zip")
|
30 |
+
|
31 |
+
return "./output.wav"
|
32 |
+
|
33 |
+
languages = [
|
34 |
+
"en", "es", "fr", "de", "it",
|
35 |
+
"pt", "pl", "tr", "ru", "nl",
|
36 |
+
"cs", "ar", "zh-cn", "ja", "hu",
|
37 |
+
"ko", "hi"
|
38 |
+
]
|
39 |
+
|
40 |
+
# Create a separate tab for model sharing
|
41 |
+
def model_sharing_tab():
|
42 |
+
model_input = gr.components.Textbox(label="Share your model/link")
|
43 |
+
model_output = gr.components.Markdown(label="Shared Models")
|
44 |
+
|
45 |
+
model_sharing_iface = gr.Interface(
|
46 |
+
fn=lambda x: x, # dummy function to display the input
|
47 |
+
inputs=model_input,
|
48 |
+
outputs=model_output,
|
49 |
+
title="Share Your Model",
|
50 |
+
description="Share your model or link with the community!"
|
51 |
+
)
|
52 |
+
|
53 |
+
model_sharing_iface.launch()
|
54 |
|
55 |
# Combine the two interfaces
|
56 |
iface = gr.Interface(
|
|
|
67 |
use this colab with caution <3.
|
68 |
""",
|
69 |
theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate"),
|
70 |
+
style=gr.Box.vertical,
|
71 |
+
# Add the model sharing tab
|
72 |
+
children=[
|
73 |
+
iface,
|
74 |
+
gr.Blocks(model_sharing_tab)
|
75 |
+
]
|
76 |
)
|
77 |
|
|
|
|
|
78 |
iface.launch(share=True)
|