Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,6 +52,7 @@ def predict(prompt, language, reference_audio):
|
|
52 |
if len(prompt) < 2 or len(prompt) > 600:
|
53 |
return None, "El texto debe tener entre 2 y 600 caracteres."
|
54 |
|
|
|
55 |
temperature = config.model_args.get("temperature", 0.85)
|
56 |
length_penalty = config.model_args.get("length_penalty", 1.0)
|
57 |
repetition_penalty = config.model_args.get("repetition_penalty", 2.0)
|
@@ -79,9 +80,11 @@ def predict(prompt, language, reference_audio):
|
|
79 |
inference_time = time.time() - start_time
|
80 |
|
81 |
output_path = "pedro_labattaglia_TTS.wav"
|
|
|
|
|
82 |
wavfile.write(output_path, config.audio["output_sample_rate"], out["wav"])
|
83 |
|
84 |
-
audio_length = len(out["wav"]) / config.audio["output_sample_rate"]
|
85 |
real_time_factor = inference_time / audio_length
|
86 |
|
87 |
metrics_text = f"Tiempo de generación: {inference_time:.2f} segundos\n"
|
@@ -122,6 +125,7 @@ Sintetizador de voz con la voz del locutor argentino Pedro Labattaglia.
|
|
122 |
- Presione generar voz
|
123 |
"""
|
124 |
|
|
|
125 |
with gr.Blocks(theme=theme) as demo:
|
126 |
gr.Markdown(description)
|
127 |
|
@@ -148,24 +152,24 @@ with gr.Blocks(theme=theme) as demo:
|
|
148 |
generated_audio = gr.Audio(label="Audio generado", interactive=False)
|
149 |
metrics_output = gr.Textbox(label="Métricas", value="Tiempo de generación: -- segundos\nFactor de tiempo real: --")
|
150 |
|
|
|
|
|
|
|
|
|
151 |
generate_button.click(
|
152 |
predict,
|
153 |
inputs=[input_text, language_selector, reference_audio],
|
154 |
outputs=[generated_audio, metrics_output]
|
155 |
)
|
156 |
|
157 |
-
#
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
"""
|
166 |
-
|
167 |
-
# Agregar el JavaScript para limpiar los datos de autenticación
|
168 |
-
gr.HTML("<script>" + clear_auth_js + "</script>")
|
169 |
|
170 |
# Estilos CSS personalizados
|
171 |
demo.css = """
|
|
|
52 |
if len(prompt) < 2 or len(prompt) > 600:
|
53 |
return None, "El texto debe tener entre 2 y 600 caracteres."
|
54 |
|
55 |
+
# Obtener los parámetros de la configuración JSON
|
56 |
temperature = config.model_args.get("temperature", 0.85)
|
57 |
length_penalty = config.model_args.get("length_penalty", 1.0)
|
58 |
repetition_penalty = config.model_args.get("repetition_penalty", 2.0)
|
|
|
80 |
inference_time = time.time() - start_time
|
81 |
|
82 |
output_path = "pedro_labattaglia_TTS.wav"
|
83 |
+
# Guardar el audio directamente desde el output del modelo
|
84 |
+
import scipy.io.wavfile as wavfile
|
85 |
wavfile.write(output_path, config.audio["output_sample_rate"], out["wav"])
|
86 |
|
87 |
+
audio_length = len(out["wav"]) / config.audio["output_sample_rate"] # duración del audio en segundos
|
88 |
real_time_factor = inference_time / audio_length
|
89 |
|
90 |
metrics_text = f"Tiempo de generación: {inference_time:.2f} segundos\n"
|
|
|
125 |
- Presione generar voz
|
126 |
"""
|
127 |
|
128 |
+
# Interfaz de Gradio
|
129 |
with gr.Blocks(theme=theme) as demo:
|
130 |
gr.Markdown(description)
|
131 |
|
|
|
152 |
generated_audio = gr.Audio(label="Audio generado", interactive=False)
|
153 |
metrics_output = gr.Textbox(label="Métricas", value="Tiempo de generación: -- segundos\nFactor de tiempo real: --")
|
154 |
|
155 |
+
# Botón de logout
|
156 |
+
logout_button = gr.LogoutButton(label="Logout")
|
157 |
+
|
158 |
+
# Configuración del botón para generar voz
|
159 |
generate_button.click(
|
160 |
predict,
|
161 |
inputs=[input_text, language_selector, reference_audio],
|
162 |
outputs=[generated_audio, metrics_output]
|
163 |
)
|
164 |
|
165 |
+
# Agregar el JavaScript para ejecutar el logout al refrescar o cerrar la pestaña
|
166 |
+
gr.HTML("""
|
167 |
+
<script>
|
168 |
+
window.addEventListener("beforeunload", function (event) {
|
169 |
+
fetch('/logout', { method: 'POST' });
|
170 |
+
});
|
171 |
+
</script>
|
172 |
+
""")
|
|
|
|
|
|
|
|
|
173 |
|
174 |
# Estilos CSS personalizados
|
175 |
demo.css = """
|