Woziii commited on
Commit
78dc1fd
·
verified ·
1 Parent(s): 0f4a81a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -71
app.py CHANGED
@@ -5,6 +5,7 @@ import os
5
  import time
6
  import torch
7
 
 
8
  # Initialisation du modèle TTS avec GPU désactivé
9
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
10
 
@@ -43,8 +44,8 @@ with gr.Blocks() as demo:
43
  gr.Markdown("Le nom du projet sera utilisé pour organiser les fichiers dans un dossier dédié.")
44
  speaker = gr.Dropdown(label="Voix 🎙️", choices=["Margaux"], value="Margaux")
45
  gr.Markdown("Choisissez la voix souhaitée pour générer vos fichiers audio. Plus de voix seront ajoutées prochainement.")
46
- agree = gr.Checkbox(label="✅ Jaccepte les conditions dutilisation")
47
- gr.Markdown("Vous devez accepter les conditions dutilisation pour continuer.")
48
  next_btn_1 = gr.Button("Créer le Projet ➡️")
49
 
50
  # Étape 2 : Gestion des Sections
@@ -55,17 +56,28 @@ with gr.Blocks() as demo:
55
  Chaque section correspond à une partie de votre script. Par exemple, une introduction, une explication, ou une conclusion.
56
  Donnez un nom unique à chaque section et saisissez le texte correspondant.
57
  """)
 
 
 
 
 
 
 
 
 
58
 
59
- sections_list = gr.List(
60
- [gr.Group([
61
- gr.Textbox(label="Nom de la Section 🏷️", placeholder="Exemple : Introduction"),
62
- gr.TextArea(label="Texte de la Section ✏️", placeholder="Écrivez ici le texte à convertir en voix off.")
63
- ])],
64
- label="Sections"
65
- )
66
 
67
  add_section_btn = gr.Button("Ajouter une Section ➕")
68
  remove_section_btn = gr.Button("Supprimer une Section ➖")
 
 
 
 
69
  next_btn_2 = gr.Button("Valider les Sections ➡️")
70
  prev_btn_2 = gr.Button("⬅️ Retour")
71
 
@@ -84,12 +96,22 @@ with gr.Blocks() as demo:
84
  # Étape 4 : Génération des Audios
85
  with gr.Group(visible=False) as step4:
86
  gr.Markdown("## 🎧 Étape 4 : Génération des Audios")
87
- audio_outputs = []
88
 
89
- def render_audio_outputs(sections):
90
- return [gr.Audio(label=f"Audio de {section['name']}") for section in sections]
91
-
92
- audio_outputs.extend(render_audio_outputs(sections))
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  save_project_btn = gr.Button("Sauvegarder le Projet ✅")
95
 
@@ -113,29 +135,6 @@ with gr.Blocks() as demo:
113
  return "Veuillez remplir tous les champs et accepter les conditions.", None
114
  return f"Projet '{name}' créé avec succès !", {"name": name, "voice": voice}, 2
115
 
116
- def add_section(sections):
117
- sections.append({"name": f"Section {len(sections) + 1}", "text": ""})
118
- return sections
119
-
120
- def remove_section(sections):
121
- if sections:
122
- sections.pop()
123
- return sections
124
- return sections
125
-
126
- def generate_audios(project_info, sections):
127
- outputs = []
128
- for section in sections:
129
- audio_path = generate_section_audio(
130
- project_info["name"],
131
- section["name"],
132
- section["text"],
133
- project_info["voice"]
134
- )
135
- outputs.append(audio_path)
136
-
137
- return outputs
138
-
139
  # Événements
140
  next_btn_1.click(
141
  create_project,
@@ -144,55 +143,43 @@ with gr.Blocks() as demo:
144
  ).then(
145
  update_visibility,
146
  inputs=[current_step],
147
- outputs=[step1, step2, step3]
148
- )
149
-
150
- add_section_btn.click(
151
- add_section,
152
- inputs=[sections],
153
- outputs=[sections_list]
154
- )
155
-
156
- remove_section_btn.click(
157
- remove_section,
158
- inputs=[sections],
159
- outputs=[sections_list]
160
  )
161
 
162
  next_btn_2.click(
163
- lambda x: x + 1,
164
- inputs=[current_step],
165
- outputs=[current_step]
166
  ).then(
167
- update_visibility,
168
- inputs=[current_step],
169
- outputs=[step1, step2, step3]
170
  )
171
 
172
  prev_btn_2.click(
173
- prev_step,
174
- inputs=[current_step],
175
- outputs=[current_step]
176
  ).then(
177
- update_visibility,
178
- inputs=[current_step],
179
- outputs=[step1, step2, step3]
180
  )
181
 
182
  generate_btn.click(
183
- generate_audios,
184
- inputs=[project_info, sections],
185
- outputs=audio_outputs
186
  )
187
 
188
  prev_btn_3.click(
189
- prev_step,
190
- inputs=[current_step],
191
- outputs=[current_step]
192
  ).then(
193
- update_visibility,
194
- inputs=[current_step],
195
- outputs=[step1, step2, step3]
196
  )
197
 
198
  demo.launch()
 
5
  import time
6
  import torch
7
 
8
+
9
  # Initialisation du modèle TTS avec GPU désactivé
10
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
11
 
 
44
  gr.Markdown("Le nom du projet sera utilisé pour organiser les fichiers dans un dossier dédié.")
45
  speaker = gr.Dropdown(label="Voix 🎙️", choices=["Margaux"], value="Margaux")
46
  gr.Markdown("Choisissez la voix souhaitée pour générer vos fichiers audio. Plus de voix seront ajoutées prochainement.")
47
+ agree = gr.Checkbox(label="✅ J'accepte les conditions d'utilisation")
48
+ gr.Markdown("Vous devez accepter les conditions d'utilisation pour continuer.")
49
  next_btn_1 = gr.Button("Créer le Projet ➡️")
50
 
51
  # Étape 2 : Gestion des Sections
 
56
  Chaque section correspond à une partie de votre script. Par exemple, une introduction, une explication, ou une conclusion.
57
  Donnez un nom unique à chaque section et saisissez le texte correspondant.
58
  """)
59
+
60
+ section_inputs = []
61
+
62
+ def add_section(sections):
63
+ section_name_input = gr.Textbox(label=f"Nom de la Section 🏷️", placeholder="Exemple : Introduction")
64
+ section_text_input = gr.TextArea(label=f"Texte de la Section ✏️", placeholder="Écrivez ici le texte à convertir en voix off.")
65
+ section_inputs.append((section_name_input, section_text_input))
66
+ sections.append({"name": "", "text": ""})
67
+ return sections
68
 
69
+ def remove_section(sections):
70
+ if sections:
71
+ sections.pop()
72
+ section_inputs.pop()
73
+ return sections
 
 
74
 
75
  add_section_btn = gr.Button("Ajouter une Section ➕")
76
  remove_section_btn = gr.Button("Supprimer une Section ➖")
77
+
78
+ add_section_btn.click(add_section, inputs=[sections], outputs=[sections])
79
+ remove_section_btn.click(remove_section, inputs=[sections], outputs=[sections])
80
+
81
  next_btn_2 = gr.Button("Valider les Sections ➡️")
82
  prev_btn_2 = gr.Button("⬅️ Retour")
83
 
 
96
  # Étape 4 : Génération des Audios
97
  with gr.Group(visible=False) as step4:
98
  gr.Markdown("## 🎧 Étape 4 : Génération des Audios")
 
99
 
100
+ def generate_audios(project_info, sections):
101
+ outputs = []
102
+ for i, (name_input, text_input) in enumerate(section_inputs):
103
+ name = name_input.value
104
+ text = text_input.value
105
+ audio_path = generate_section_audio(
106
+ project_info["name"],
107
+ name,
108
+ text,
109
+ project_info["voice"]
110
+ )
111
+ outputs.append(gr.Audio(value=audio_path))
112
+ return outputs
113
+
114
+ audio_outputs_container = gr.Column()
115
 
116
  save_project_btn = gr.Button("Sauvegarder le Projet ✅")
117
 
 
135
  return "Veuillez remplir tous les champs et accepter les conditions.", None
136
  return f"Projet '{name}' créé avec succès !", {"name": name, "voice": voice}, 2
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  # Événements
139
  next_btn_1.click(
140
  create_project,
 
143
  ).then(
144
  update_visibility,
145
  inputs=[current_step],
146
+ outputs=[step1, step2, step3, step4]
 
 
 
 
 
 
 
 
 
 
 
 
147
  )
148
 
149
  next_btn_2.click(
150
+ lambda x: x + 1,
151
+ inputs=[current_step],
152
+ outputs=[current_step]
153
  ).then(
154
+ update_visibility,
155
+ inputs=[current_step],
156
+ outputs=[step1, step2, step3, step4]
157
  )
158
 
159
  prev_btn_2.click(
160
+ prev_step,
161
+ inputs=[current_step],
162
+ outputs=[current_step]
163
  ).then(
164
+ update_visibility,
165
+ inputs=[current_step],
166
+ outputs=[step1, step2, step3, step4]
167
  )
168
 
169
  generate_btn.click(
170
+ generate_audios,
171
+ inputs=[project_info, sections],
172
+ outputs=audio_outputs_container
173
  )
174
 
175
  prev_btn_3.click(
176
+ prev_step,
177
+ inputs=[current_step],
178
+ outputs=[current_step]
179
  ).then(
180
+ update_visibility,
181
+ inputs=[current_step],
182
+ outputs=[step1, step2, step3, step4]
183
  )
184
 
185
  demo.launch()