Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,108 +53,93 @@ class TTSInterface:
|
|
| 53 |
label="✅ J'accepte les conditions d'utilisation"
|
| 54 |
)
|
| 55 |
create_btn = gr.Button("Créer le Projet ➡️", variant="primary")
|
|
|
|
| 56 |
|
| 57 |
# Étape 2: Gestion des sections
|
| 58 |
with gr.Tab("✍️ Sections"):
|
| 59 |
with gr.Column():
|
| 60 |
gr.Markdown("### Gestion des sections")
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
add_section = gr.Button("+ Ajouter une Section ➕")
|
| 67 |
remove_section = gr.Button("- Supprimer la dernière Section ➖")
|
| 68 |
-
|
| 69 |
-
# Template pour une section
|
| 70 |
-
def create_section_template(index):
|
| 71 |
-
with gr.Group():
|
| 72 |
-
with gr.Box():
|
| 73 |
-
gr.Markdown(f"#### Section {index}")
|
| 74 |
-
name = gr.Textbox(
|
| 75 |
-
label="Nom de la section",
|
| 76 |
-
value=f"Section_{index}"
|
| 77 |
-
)
|
| 78 |
-
text = gr.TextArea(
|
| 79 |
-
label="Texte à synthétiser",
|
| 80 |
-
placeholder="Entrez votre texte ici..."
|
| 81 |
-
)
|
| 82 |
-
return [name, text]
|
| 83 |
|
| 84 |
# Étape 3: Génération des audios
|
| 85 |
with gr.Tab("🎧 Génération"):
|
| 86 |
with gr.Column():
|
| 87 |
gr.Markdown("### Génération des audios")
|
| 88 |
generate_all = gr.Button("Générer tous les audios ▶️", variant="primary")
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
# Fonctions de callback
|
| 93 |
def update_project_info(name, terms):
|
| 94 |
if not terms:
|
| 95 |
-
return
|
| 96 |
if not name.strip():
|
| 97 |
-
return
|
| 98 |
-
return
|
| 99 |
|
| 100 |
-
def add_new_section(
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
}
|
| 106 |
-
current_sections.append(new_section)
|
| 107 |
-
return {"sections": current_sections}
|
| 108 |
|
| 109 |
-
def remove_last_section(
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
return {"sections": current_sections}
|
| 114 |
|
| 115 |
-
def generate_audio(
|
| 116 |
try:
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
f"{section_data['name']}.wav"
|
| 122 |
-
)
|
| 123 |
|
| 124 |
-
#
|
| 125 |
self.tts.tts_to_file(
|
| 126 |
-
text=
|
| 127 |
file_path=output_path,
|
| 128 |
language="fr"
|
| 129 |
)
|
| 130 |
|
| 131 |
-
return
|
| 132 |
except Exception as e:
|
| 133 |
-
return
|
| 134 |
|
| 135 |
# Événements
|
| 136 |
create_btn.click(
|
| 137 |
-
update_project_info,
|
| 138 |
inputs=[project_name, terms],
|
| 139 |
-
outputs=[
|
| 140 |
)
|
| 141 |
|
| 142 |
add_section.click(
|
| 143 |
-
add_new_section,
|
| 144 |
-
inputs=[
|
| 145 |
-
outputs=[
|
| 146 |
)
|
| 147 |
|
| 148 |
remove_section.click(
|
| 149 |
-
remove_last_section,
|
| 150 |
-
inputs=[
|
| 151 |
-
outputs=[
|
| 152 |
)
|
| 153 |
|
| 154 |
generate_all.click(
|
| 155 |
-
|
| 156 |
-
inputs=[
|
| 157 |
-
outputs=[
|
| 158 |
)
|
| 159 |
|
| 160 |
return demo
|
|
|
|
| 53 |
label="✅ J'accepte les conditions d'utilisation"
|
| 54 |
)
|
| 55 |
create_btn = gr.Button("Créer le Projet ➡️", variant="primary")
|
| 56 |
+
status_message = gr.Markdown("") # Pour afficher les messages de statut
|
| 57 |
|
| 58 |
# Étape 2: Gestion des sections
|
| 59 |
with gr.Tab("✍️ Sections"):
|
| 60 |
with gr.Column():
|
| 61 |
gr.Markdown("### Gestion des sections")
|
| 62 |
|
| 63 |
+
# Template pour une section
|
| 64 |
+
section_template = gr.DataFrame(
|
| 65 |
+
headers=["Nom", "Texte"],
|
| 66 |
+
row_count=0,
|
| 67 |
+
col_count=2,
|
| 68 |
+
interactive=True
|
| 69 |
+
)
|
| 70 |
|
| 71 |
with gr.Row():
|
| 72 |
add_section = gr.Button("+ Ajouter une Section ➕")
|
| 73 |
remove_section = gr.Button("- Supprimer la dernière Section ➖")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# Étape 3: Génération des audios
|
| 76 |
with gr.Tab("🎧 Génération"):
|
| 77 |
with gr.Column():
|
| 78 |
gr.Markdown("### Génération des audios")
|
| 79 |
generate_all = gr.Button("Générer tous les audios ▶️", variant="primary")
|
| 80 |
+
audio_output = gr.Audio(label="Audio généré") # Un seul composant Audio pour l'exemple
|
| 81 |
+
status = gr.Markdown("") # Pour les messages de statut de génération
|
| 82 |
|
| 83 |
# Fonctions de callback
|
| 84 |
def update_project_info(name, terms):
|
| 85 |
if not terms:
|
| 86 |
+
return "⚠️ Veuillez accepter les conditions d'utilisation"
|
| 87 |
if not name.strip():
|
| 88 |
+
return "⚠️ Le nom du projet est requis"
|
| 89 |
+
return f"✅ Projet '{name}' créé avec succès!"
|
| 90 |
|
| 91 |
+
def add_new_section(data):
|
| 92 |
+
if data is None:
|
| 93 |
+
data = []
|
| 94 |
+
new_row = [f"Section_{len(data) + 1}", ""]
|
| 95 |
+
return data + [new_row]
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
def remove_last_section(data):
|
| 98 |
+
if data and len(data) > 0:
|
| 99 |
+
return data[:-1]
|
| 100 |
+
return data
|
|
|
|
| 101 |
|
| 102 |
+
def generate_audio(text, project_name):
|
| 103 |
try:
|
| 104 |
+
if not text or not project_name:
|
| 105 |
+
return None, "⚠️ Texte ou nom de projet manquant"
|
| 106 |
+
|
| 107 |
+
output_path = os.path.join(self.output_folder, f"{project_name}_output.wav")
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
# Gén��ration de l'audio
|
| 110 |
self.tts.tts_to_file(
|
| 111 |
+
text=text,
|
| 112 |
file_path=output_path,
|
| 113 |
language="fr"
|
| 114 |
)
|
| 115 |
|
| 116 |
+
return output_path, "✅ Audio généré avec succès"
|
| 117 |
except Exception as e:
|
| 118 |
+
return None, f"⚠️ Erreur: {str(e)}"
|
| 119 |
|
| 120 |
# Événements
|
| 121 |
create_btn.click(
|
| 122 |
+
fn=update_project_info,
|
| 123 |
inputs=[project_name, terms],
|
| 124 |
+
outputs=[status_message]
|
| 125 |
)
|
| 126 |
|
| 127 |
add_section.click(
|
| 128 |
+
fn=add_new_section,
|
| 129 |
+
inputs=[section_template],
|
| 130 |
+
outputs=[section_template]
|
| 131 |
)
|
| 132 |
|
| 133 |
remove_section.click(
|
| 134 |
+
fn=remove_last_section,
|
| 135 |
+
inputs=[section_template],
|
| 136 |
+
outputs=[section_template]
|
| 137 |
)
|
| 138 |
|
| 139 |
generate_all.click(
|
| 140 |
+
fn=generate_audio,
|
| 141 |
+
inputs=[project_name, speaker],
|
| 142 |
+
outputs=[audio_output, status]
|
| 143 |
)
|
| 144 |
|
| 145 |
return demo
|