Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,100 +38,82 @@ def generate_section_audio(project_name, section_name, text, speaker):
|
|
38 |
except Exception as e:
|
39 |
return str(e) # Retourne l'erreur pour gestion dans l'interface
|
40 |
|
41 |
-
# Fonction pour
|
42 |
-
def
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# Interface Gradio
|
46 |
with gr.Blocks() as demo:
|
47 |
-
# État global pour gérer les sections
|
48 |
-
sections = gr.State(value=[])
|
49 |
-
|
50 |
-
# Introduction générale
|
51 |
gr.Markdown("""
|
52 |
# 🎙️ Synthèse Vocale Margaux
|
53 |
-
## 👋 Bienvenue sur Margaux
|
54 |
-
|
55 |
-
**Étapes principales :**
|
56 |
-
1. 🛠️ **Créer un projet** : Définissez le nom du projet et choisissez la voix.
|
57 |
-
2. ✍️ **Ajouter des sections** : Divisez votre texte en parties claires, chacune avec un nom unique.
|
58 |
-
3. 🎧 **Générer les audios** : Chaque section est transformée en fichier audio individuel.
|
59 |
-
4. 📁 **Sauvegardez le projet** : Finalisez et récupérez les fichiers validés.
|
60 |
""")
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
gr.Markdown("### 🛠️ Étape 1 : Création du Projet")
|
65 |
project_name = gr.Textbox(label="Nom du Projet", placeholder="Exemple : Capsule_Video_PLU")
|
66 |
speaker = gr.Dropdown(label="Voix 🎙️", choices=["Margaux"], value="Margaux") # Liste de voix
|
67 |
agree = gr.Checkbox(label="✅ J'accepte les conditions d'utilisation")
|
68 |
-
project_message = gr.Markdown(value="", visible=False) # Composant pour afficher les messages
|
69 |
-
next_btn_1 = gr.Button("Suivant ➡️")
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
gr.
|
74 |
sections_list = gr.Column() # Conteneur pour afficher les sections ajoutées
|
75 |
add_section_btn = gr.Button("+ Ajouter une Section ➕")
|
76 |
remove_section_btn = gr.Button("- Supprimer la dernière Section ➖")
|
77 |
-
prev_btn_2 = gr.Button("⬅️ Précédent")
|
78 |
-
next_btn_2 = gr.Button("Suivant ➡️")
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
generate_btn = gr.Button("Générer les Audios ▶️")
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
save_project_btn = gr.Button("Sauvegarder le Projet ✅")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
-
|
89 |
-
def create_project(project_name, speaker, agree):
|
90 |
-
if not agree:
|
91 |
-
return "❗ Veuillez accepter les conditions d'utilisation.", False, False
|
92 |
-
if not project_name:
|
93 |
-
return "❗ Le nom du projet est obligatoire.", False, False
|
94 |
-
os.makedirs(os.path.join(output_folder, project_name), exist_ok=True)
|
95 |
-
return f"✅ Projet '{project_name}' créé avec succès !", True, False
|
96 |
-
|
97 |
-
next_btn_1.click(
|
98 |
-
create_project,
|
99 |
-
inputs=[project_name, speaker, agree],
|
100 |
-
outputs=[project_message, step1, step2],
|
101 |
-
)
|
102 |
-
|
103 |
-
def add_section(sections):
|
104 |
-
section = {"name": f"Section_{len(sections) + 1}", "text": ""}
|
105 |
-
sections.append(section)
|
106 |
-
return sections
|
107 |
-
|
108 |
-
add_section_btn.click(add_section, inputs=[sections], outputs=[sections_list])
|
109 |
-
|
110 |
-
def remove_section(sections):
|
111 |
-
if sections:
|
112 |
-
sections.pop()
|
113 |
-
return sections
|
114 |
-
|
115 |
-
remove_section_btn.click(remove_section, inputs=[sections], outputs=[sections_list])
|
116 |
-
|
117 |
-
def generate_audios(project_name, sections, speaker):
|
118 |
-
results = []
|
119 |
-
for section in sections:
|
120 |
-
name = section["name"]
|
121 |
-
text = section["text"]
|
122 |
-
audio_path = generate_section_audio(project_name, name, text, speaker)
|
123 |
-
results.append(audio_path)
|
124 |
-
return results
|
125 |
-
|
126 |
-
generate_btn.click(
|
127 |
-
generate_audios,
|
128 |
-
inputs=[project_name, sections, speaker],
|
129 |
-
outputs=[results_output],
|
130 |
-
)
|
131 |
-
|
132 |
-
prev_btn_2.click(lambda: (True, False), inputs=None, outputs=[step1, step2])
|
133 |
-
next_btn_2.click(lambda: (False, True), inputs=None, outputs=[step2, step3])
|
134 |
-
prev_btn_3.click(lambda: (True, False), inputs=None, outputs=[step2, step3])
|
135 |
|
136 |
# Lancement de l'interface
|
137 |
demo.launch(debug=True)
|
|
|
38 |
except Exception as e:
|
39 |
return str(e) # Retourne l'erreur pour gestion dans l'interface
|
40 |
|
41 |
+
# Fonction pour ajouter une section
|
42 |
+
def add_section(sections):
|
43 |
+
section = {"name": f"Section_{len(sections) + 1}", "text": ""}
|
44 |
+
sections.append(section)
|
45 |
+
return sections
|
46 |
+
|
47 |
+
# Fonction pour supprimer la dernière section
|
48 |
+
def remove_section(sections):
|
49 |
+
if sections:
|
50 |
+
sections.pop()
|
51 |
+
return sections
|
52 |
+
|
53 |
+
# Fonction pour générer les audios de toutes les sections
|
54 |
+
def generate_all_audios(project_name, sections, speaker):
|
55 |
+
results = []
|
56 |
+
for section in sections:
|
57 |
+
name = section["name"]
|
58 |
+
text = section["text"]
|
59 |
+
audio_path = generate_section_audio(project_name, name, text, speaker)
|
60 |
+
results.append(audio_path)
|
61 |
+
return results
|
62 |
|
63 |
# Interface Gradio
|
64 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
65 |
gr.Markdown("""
|
66 |
# 🎙️ Synthèse Vocale Margaux
|
67 |
+
## 👋 Bienvenue sur Margaux
|
68 |
+
Créez des voix off naturelles à partir de textes. Divisez votre contenu en plusieurs sections pour une meilleure qualité audio.
|
|
|
|
|
|
|
|
|
|
|
69 |
""")
|
70 |
|
71 |
+
with gr.Box():
|
72 |
+
gr.Markdown("### 🛠️ Configuration du Projet")
|
|
|
73 |
project_name = gr.Textbox(label="Nom du Projet", placeholder="Exemple : Capsule_Video_PLU")
|
74 |
speaker = gr.Dropdown(label="Voix 🎙️", choices=["Margaux"], value="Margaux") # Liste de voix
|
75 |
agree = gr.Checkbox(label="✅ J'accepte les conditions d'utilisation")
|
|
|
|
|
76 |
|
77 |
+
with gr.Box():
|
78 |
+
gr.Markdown("### ✍️ Gestion des Sections")
|
79 |
+
sections = gr.State(value=[])
|
80 |
sections_list = gr.Column() # Conteneur pour afficher les sections ajoutées
|
81 |
add_section_btn = gr.Button("+ Ajouter une Section ➕")
|
82 |
remove_section_btn = gr.Button("- Supprimer la dernière Section ➖")
|
|
|
|
|
83 |
|
84 |
+
def update_section_list(sections):
|
85 |
+
return [gr.Textbox(label=f"Nom : {s['name']}", value=s["text"], lines=2) for s in sections]
|
86 |
+
|
87 |
+
add_section_btn.click(add_section, inputs=[sections], outputs=[sections_list])
|
88 |
+
remove_section_btn.click(remove_section, inputs=[sections], outputs=[sections_list])
|
89 |
+
|
90 |
+
with gr.Box():
|
91 |
+
gr.Markdown("### 🎧 Génération des Audios")
|
92 |
generate_btn = gr.Button("Générer les Audios ▶️")
|
93 |
+
results_output = gr.Column() # Conteneur pour afficher les audios générés
|
94 |
+
|
95 |
+
def generate_audios_and_display(project_name, sections, speaker):
|
96 |
+
results = generate_all_audios(project_name, sections, speaker)
|
97 |
+
return [gr.Audio(label=f"Audio : {s['name']}", value=path) for s, path in zip(sections, results)]
|
98 |
+
|
99 |
+
generate_btn.click(
|
100 |
+
generate_audios_and_display,
|
101 |
+
inputs=[project_name, sections, speaker],
|
102 |
+
outputs=[results_output]
|
103 |
+
)
|
104 |
+
|
105 |
+
with gr.Box():
|
106 |
+
gr.Markdown("### 📁 Sauvegarde du Projet")
|
107 |
save_project_btn = gr.Button("Sauvegarder le Projet ✅")
|
108 |
+
save_message = gr.Markdown("")
|
109 |
+
|
110 |
+
def save_project(project_name, sections):
|
111 |
+
project_path = os.path.join(output_folder, project_name)
|
112 |
+
if not os.path.exists(project_path):
|
113 |
+
return "⚠️ Aucun audio génér�� à sauvegarder."
|
114 |
+
return f"🎉 Projet '{project_name}' sauvegardé dans le dossier '{project_path}'."
|
115 |
|
116 |
+
save_project_btn.click(save_project, inputs=[project_name, sections], outputs=[save_message])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
# Lancement de l'interface
|
119 |
demo.launch(debug=True)
|