Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,115 +1,101 @@
|
|
1 |
import subprocess
|
2 |
-
|
3 |
-
# Run the setup.py install command
|
4 |
-
try:
|
5 |
-
subprocess.run(['python', 'setup.py', 'install', '--user'], check=True)
|
6 |
-
print("Installation successful.")
|
7 |
-
except subprocess.CalledProcessError as e:
|
8 |
-
print(f"Installation failed with error: {e}")
|
9 |
-
|
10 |
import gradio as gr
|
11 |
from TTS.api import TTS
|
12 |
import os
|
13 |
import time
|
14 |
import torch
|
15 |
-
from torch.serialization import add_safe_globals
|
16 |
-
from TTS.tts.configs.xtts_config import XttsConfig
|
17 |
|
18 |
-
# Ajouter XttsConfig comme "safe global" pour éviter les erreurs de désérialisation
|
19 |
-
add_safe_globals([XttsConfig])
|
20 |
|
21 |
-
# Charger le modèle XTTS
|
22 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
|
23 |
|
24 |
-
# Créer le dossier de sortie
|
25 |
output_folder = "output_audio"
|
26 |
os.makedirs(output_folder, exist_ok=True)
|
27 |
|
28 |
def predict(prompt, speaker, agree, subfolder_name, file_name):
|
29 |
if not agree:
|
30 |
raise gr.Error("Veuillez accepter les conditions d'utilisation.")
|
31 |
-
|
32 |
-
# Utiliser le nom fourni pour le sous-dossier ou en générer un par défaut
|
33 |
subfolder_name = subfolder_name.strip() or f"session_{int(time.time())}"
|
34 |
session_folder = os.path.join(output_folder, subfolder_name)
|
35 |
os.makedirs(session_folder, exist_ok=True)
|
36 |
|
37 |
-
# Utiliser le nom fourni pour le fichier ou un nom par défaut
|
38 |
file_name = file_name.strip() or "output.wav"
|
39 |
if not file_name.endswith(".wav"):
|
40 |
file_name += ".wav"
|
41 |
-
|
42 |
output_path = os.path.join(session_folder, file_name)
|
43 |
|
44 |
-
# Charger tous les fichiers WAV du speaker sélectionné
|
45 |
speaker_wav_paths = [os.path.join("examples", f) for f in os.listdir("examples") if f.startswith(speaker) and f.endswith(".wav")]
|
46 |
-
|
47 |
if not speaker_wav_paths:
|
48 |
raise gr.Error(f"Aucun fichier audio trouvé pour le speaker : {speaker}")
|
49 |
|
50 |
-
# Synthèse vocale
|
51 |
tts.tts_to_file(
|
52 |
text=prompt,
|
53 |
file_path=output_path,
|
54 |
-
speaker_wav=speaker_wav_paths,
|
55 |
-
language="fr"
|
56 |
)
|
57 |
|
58 |
-
|
59 |
-
waveform = gr.make_waveform(audio=output_path)
|
60 |
|
61 |
-
return 100, waveform, output_path
|
62 |
-
|
63 |
-
# Interface utilisateur
|
64 |
custom_css = """
|
65 |
.gradio-container {
|
66 |
-
font-family: '
|
67 |
-
background-color: #
|
68 |
}
|
69 |
.gr-form {
|
70 |
background-color: white;
|
71 |
-
border-radius:
|
72 |
-
padding:
|
73 |
-
box-shadow: 0
|
74 |
}
|
75 |
.gr-button {
|
76 |
background-color: #4a90e2;
|
77 |
border: none;
|
|
|
|
|
|
|
78 |
}
|
79 |
.gr-button:hover {
|
80 |
background-color: #3a7bc8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
82 |
"""
|
83 |
|
84 |
-
title = "Synthèse Vocale XTTS
|
85 |
-
|
86 |
description = """
|
87 |
-
<h3>Bienvenue sur notre outil de synthèse vocale XTTS !</h3>
|
88 |
-
<p
|
89 |
-
Choisissez une voix, entrez votre texte, et écoutez le résultat !</p>
|
90 |
"""
|
91 |
-
|
92 |
article = """
|
93 |
-
<div style='margin:20px auto; text-align: center;'>
|
94 |
-
<p>En utilisant cette démo, vous acceptez les conditions d'utilisation du modèle Coqui Public
|
95 |
-
<a href='https://coqui.ai/cpml' target='_blank'>https://coqui.ai/cpml</a></p>
|
96 |
</div>
|
97 |
"""
|
98 |
|
99 |
-
# Générer la liste des speakers à partir des fichiers WAV dans le dossier examples
|
100 |
available_speakers = list(set([f.split('_')[0] for f in os.listdir("examples") if f.endswith(".wav")]))
|
101 |
|
102 |
with gr.Blocks(css=custom_css) as demo:
|
103 |
-
gr.Markdown(f"<h1 style='text-align: center;'>{title}</h1>")
|
104 |
gr.Markdown(description)
|
105 |
|
106 |
with gr.Row():
|
107 |
with gr.Column(scale=2):
|
108 |
prompt = gr.Textbox(
|
109 |
label="Texte pour la synthèse vocale",
|
110 |
-
info="Une ou deux phrases à la fois sont préférables
|
111 |
placeholder="Bonjour ! Comment allez-vous aujourd'hui ?",
|
112 |
-
lines=
|
113 |
)
|
114 |
with gr.Column(scale=1):
|
115 |
speaker = gr.Dropdown(
|
@@ -131,18 +117,14 @@ with gr.Blocks(css=custom_css) as demo:
|
|
131 |
)
|
132 |
|
133 |
generate_btn = gr.Button("Générer la voix", variant="primary")
|
134 |
-
|
135 |
-
|
136 |
-
with gr.Row():
|
137 |
-
audio_output = gr.Audio(label="Audio généré")
|
138 |
-
waveform_output = gr.Video(label="Forme d'onde")
|
139 |
|
140 |
generate_btn.click(
|
141 |
predict,
|
142 |
inputs=[prompt, speaker, agree, subfolder_name, file_name],
|
143 |
-
outputs=[
|
144 |
)
|
145 |
|
146 |
gr.Markdown(article)
|
147 |
|
148 |
-
demo.launch(debug=True
|
|
|
1 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
from TTS.api import TTS
|
4 |
import os
|
5 |
import time
|
6 |
import torch
|
|
|
|
|
7 |
|
|
|
|
|
8 |
|
|
|
9 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
|
10 |
|
|
|
11 |
output_folder = "output_audio"
|
12 |
os.makedirs(output_folder, exist_ok=True)
|
13 |
|
14 |
def predict(prompt, speaker, agree, subfolder_name, file_name):
|
15 |
if not agree:
|
16 |
raise gr.Error("Veuillez accepter les conditions d'utilisation.")
|
17 |
+
|
|
|
18 |
subfolder_name = subfolder_name.strip() or f"session_{int(time.time())}"
|
19 |
session_folder = os.path.join(output_folder, subfolder_name)
|
20 |
os.makedirs(session_folder, exist_ok=True)
|
21 |
|
|
|
22 |
file_name = file_name.strip() or "output.wav"
|
23 |
if not file_name.endswith(".wav"):
|
24 |
file_name += ".wav"
|
|
|
25 |
output_path = os.path.join(session_folder, file_name)
|
26 |
|
|
|
27 |
speaker_wav_paths = [os.path.join("examples", f) for f in os.listdir("examples") if f.startswith(speaker) and f.endswith(".wav")]
|
|
|
28 |
if not speaker_wav_paths:
|
29 |
raise gr.Error(f"Aucun fichier audio trouvé pour le speaker : {speaker}")
|
30 |
|
|
|
31 |
tts.tts_to_file(
|
32 |
text=prompt,
|
33 |
file_path=output_path,
|
34 |
+
speaker_wav=speaker_wav_paths,
|
35 |
+
language="fr"
|
36 |
)
|
37 |
|
38 |
+
return output_path
|
|
|
39 |
|
|
|
|
|
|
|
40 |
custom_css = """
|
41 |
.gradio-container {
|
42 |
+
font-family: 'Roboto', sans-serif;
|
43 |
+
background-color: #f7f9fc;
|
44 |
}
|
45 |
.gr-form {
|
46 |
background-color: white;
|
47 |
+
border-radius: 15px;
|
48 |
+
padding: 30px;
|
49 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
50 |
}
|
51 |
.gr-button {
|
52 |
background-color: #4a90e2;
|
53 |
border: none;
|
54 |
+
color: white;
|
55 |
+
font-weight: bold;
|
56 |
+
transition: all 0.3s ease;
|
57 |
}
|
58 |
.gr-button:hover {
|
59 |
background-color: #3a7bc8;
|
60 |
+
transform: translateY(-2px);
|
61 |
+
}
|
62 |
+
.gr-input, .gr-dropdown {
|
63 |
+
border: 1px solid #e0e0e0;
|
64 |
+
border-radius: 8px;
|
65 |
+
padding: 10px;
|
66 |
+
}
|
67 |
+
.gr-checkbox {
|
68 |
+
margin-top: 10px;
|
69 |
+
}
|
70 |
+
.gr-form > div {
|
71 |
+
margin-bottom: 20px;
|
72 |
}
|
73 |
"""
|
74 |
|
75 |
+
title = "🎙️ Synthèse Vocale XTTS"
|
|
|
76 |
description = """
|
77 |
+
<h3 style='text-align: center; margin-bottom: 1em;'>Bienvenue sur notre outil de synthèse vocale XTTS !</h3>
|
78 |
+
<p style='text-align: center;'>Générez une voix naturelle à partir de votre texte en français. Choisissez une voix, entrez votre texte, et écoutez le résultat !</p>
|
|
|
79 |
"""
|
|
|
80 |
article = """
|
81 |
+
<div style='margin: 20px auto; text-align: center; padding: 10px; background-color: #e8f0fe; border-radius: 10px;'>
|
82 |
+
<p>En utilisant cette démo, vous acceptez les <a href='https://coqui.ai/cpml' target='_blank' style='color: #4a90e2; text-decoration: none;'>conditions d'utilisation du modèle Coqui Public</a></p>
|
|
|
83 |
</div>
|
84 |
"""
|
85 |
|
|
|
86 |
available_speakers = list(set([f.split('_')[0] for f in os.listdir("examples") if f.endswith(".wav")]))
|
87 |
|
88 |
with gr.Blocks(css=custom_css) as demo:
|
89 |
+
gr.Markdown(f"<h1 style='text-align: center; color: #4a90e2;'>{title}</h1>")
|
90 |
gr.Markdown(description)
|
91 |
|
92 |
with gr.Row():
|
93 |
with gr.Column(scale=2):
|
94 |
prompt = gr.Textbox(
|
95 |
label="Texte pour la synthèse vocale",
|
96 |
+
info="Une ou deux phrases à la fois sont préférables (max : 10)",
|
97 |
placeholder="Bonjour ! Comment allez-vous aujourd'hui ?",
|
98 |
+
lines=5
|
99 |
)
|
100 |
with gr.Column(scale=1):
|
101 |
speaker = gr.Dropdown(
|
|
|
117 |
)
|
118 |
|
119 |
generate_btn = gr.Button("Générer la voix", variant="primary")
|
120 |
+
audio_output = gr.Audio(label="Audio généré")
|
|
|
|
|
|
|
|
|
121 |
|
122 |
generate_btn.click(
|
123 |
predict,
|
124 |
inputs=[prompt, speaker, agree, subfolder_name, file_name],
|
125 |
+
outputs=[audio_output]
|
126 |
)
|
127 |
|
128 |
gr.Markdown(article)
|
129 |
|
130 |
+
demo.launch(debug=True
|