Spaces:
Building
on
T4
Building
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,6 +81,7 @@ def predict(prompt, language, reference_audio):
|
|
| 81 |
|
| 82 |
output_path = "pedro_labattaglia_TTS.wav"
|
| 83 |
# Guardar el audio directamente desde el output del modelo
|
|
|
|
| 84 |
wavfile.write(output_path, config.audio["output_sample_rate"], out["wav"])
|
| 85 |
|
| 86 |
audio_length = len(out["wav"]) / config.audio["output_sample_rate"] # duración del audio en segundos
|
|
@@ -124,27 +125,71 @@ Sintetizador de voz con la voz del locutor argentino Pedro Labattaglia.
|
|
| 124 |
- Presione generar voz
|
| 125 |
"""
|
| 126 |
|
| 127 |
-
# JavaScript
|
| 128 |
clear_auth_js = """
|
| 129 |
function clearAuthData() {
|
| 130 |
localStorage.removeItem('gradio_auth_token');
|
| 131 |
localStorage.removeItem('gradio_auth_expiration');
|
| 132 |
-
sessionStorage.removeItem('gradio_auth_token');
|
| 133 |
-
sessionStorage.removeItem('gradio_auth_expiration');
|
| 134 |
-
document.cookie = 'gradio_auth_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
| 135 |
-
document.cookie = 'gradio_auth_expiration=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
| 136 |
}
|
| 137 |
|
|
|
|
| 138 |
window.addEventListener('beforeunload', clearAuthData);
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
"""
|
| 145 |
|
| 146 |
-
#
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
#image-container img {
|
| 149 |
display: block;
|
| 150 |
margin-left: auto;
|
|
@@ -152,95 +197,7 @@ custom_css = """
|
|
| 152 |
max-width: 256px;
|
| 153 |
height: auto;
|
| 154 |
}
|
| 155 |
-
.logout-button {
|
| 156 |
-
position: fixed;
|
| 157 |
-
top: 10px;
|
| 158 |
-
right: 10px;
|
| 159 |
-
z-index: 1000;
|
| 160 |
-
padding: 8px 16px;
|
| 161 |
-
background-color: #f44336;
|
| 162 |
-
color: white;
|
| 163 |
-
border: none;
|
| 164 |
-
border-radius: 4px;
|
| 165 |
-
cursor: pointer;
|
| 166 |
-
}
|
| 167 |
-
.logout-button:hover {
|
| 168 |
-
background-color: #d32f2f;
|
| 169 |
-
}
|
| 170 |
-
.login-container {
|
| 171 |
-
background-color: white;
|
| 172 |
-
padding: 2rem;
|
| 173 |
-
border-radius: 10px;
|
| 174 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 175 |
-
text-align: center;
|
| 176 |
-
max-width: 400px;
|
| 177 |
-
width: 100%;
|
| 178 |
-
}
|
| 179 |
-
.login-container h1 {
|
| 180 |
-
margin-bottom: 1rem;
|
| 181 |
-
color: #4a4a4a;
|
| 182 |
-
}
|
| 183 |
-
.login-container input {
|
| 184 |
-
width: 100%;
|
| 185 |
-
padding: 0.5rem;
|
| 186 |
-
margin-bottom: 1rem;
|
| 187 |
-
border: 1px solid #ddd;
|
| 188 |
-
border-radius: 4px;
|
| 189 |
-
}
|
| 190 |
-
.login-container button {
|
| 191 |
-
width: 100%;
|
| 192 |
-
padding: 0.5rem;
|
| 193 |
-
background-color: #3498db;
|
| 194 |
-
color: white;
|
| 195 |
-
border: none;
|
| 196 |
-
border-radius: 4px;
|
| 197 |
-
cursor: pointer;
|
| 198 |
-
}
|
| 199 |
-
.login-container button:hover {
|
| 200 |
-
background-color: #2980b9;
|
| 201 |
-
}
|
| 202 |
"""
|
| 203 |
|
| 204 |
-
# Modificar la parte del formulario de inicio de sesión
|
| 205 |
-
def custom_auth(username, password):
|
| 206 |
-
if (username, password) in [("Pedro Labattaglia", "PL2024"), ("Invitado", "PLTTS2024")]:
|
| 207 |
-
return True
|
| 208 |
-
return False
|
| 209 |
-
|
| 210 |
-
iface = gr.Interface(
|
| 211 |
-
fn=predict,
|
| 212 |
-
inputs=[
|
| 213 |
-
gr.Textbox(label="Texto a sintetizar", placeholder="Escribe aquí el texto que quieres convertir a voz..."),
|
| 214 |
-
gr.Dropdown(label="Idioma", choices=supported_languages),
|
| 215 |
-
gr.Dropdown(label="Audio de referencia", choices=reference_audios)
|
| 216 |
-
],
|
| 217 |
-
outputs=[
|
| 218 |
-
gr.Audio(label="Audio generado"),
|
| 219 |
-
gr.Textbox(label="Métricas")
|
| 220 |
-
],
|
| 221 |
-
title="Sintetizador de voz de Pedro Labattaglia",
|
| 222 |
-
description=description,
|
| 223 |
-
theme=theme,
|
| 224 |
-
css=custom_css,
|
| 225 |
-
allow_flagging="never"
|
| 226 |
-
)
|
| 227 |
-
|
| 228 |
-
# Crear una nueva interfaz para el inicio de sesión
|
| 229 |
-
login_iface = gr.Interface(
|
| 230 |
-
fn=custom_auth,
|
| 231 |
-
inputs=[
|
| 232 |
-
gr.Textbox(label="Usuario", placeholder="Ingrese su nombre de usuario"),
|
| 233 |
-
gr.Textbox(label="Contraseña", type="password", placeholder="Ingrese su contraseña")
|
| 234 |
-
],
|
| 235 |
-
outputs=gr.Textbox(visible=False),
|
| 236 |
-
title="Bienvenido al sintetizador de voz de Pedro Labattaglia",
|
| 237 |
-
description="Por favor, introduzca sus credenciales para acceder.",
|
| 238 |
-
theme=theme,
|
| 239 |
-
css=custom_css
|
| 240 |
-
)
|
| 241 |
-
|
| 242 |
-
# Combinar las interfaces
|
| 243 |
-
demo = gr.TabbedInterface([login_iface, iface], ["Login", "Sintetizador"])
|
| 244 |
-
|
| 245 |
if __name__ == "__main__":
|
| 246 |
-
demo.launch()
|
|
|
|
| 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
|
|
|
|
| 125 |
- Presione generar voz
|
| 126 |
"""
|
| 127 |
|
| 128 |
+
# JavaScript para limpiar los datos de autenticación
|
| 129 |
clear_auth_js = """
|
| 130 |
function clearAuthData() {
|
| 131 |
localStorage.removeItem('gradio_auth_token');
|
| 132 |
localStorage.removeItem('gradio_auth_expiration');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
| 134 |
|
| 135 |
+
// Limpiar datos de autenticación cuando la página se refresca o se cierra
|
| 136 |
window.addEventListener('beforeunload', clearAuthData);
|
| 137 |
|
| 138 |
+
// Agregar un botón para limpiar manualmente los datos de autenticación
|
| 139 |
+
document.addEventListener('DOMContentLoaded', (event) => {
|
| 140 |
+
const clearAuthButton = document.createElement('button');
|
| 141 |
+
clearAuthButton.textContent = 'Cerrar sesión';
|
| 142 |
+
clearAuthButton.style.position = 'fixed';
|
| 143 |
+
clearAuthButton.style.top = '10px';
|
| 144 |
+
clearAuthButton.style.right = '10px';
|
| 145 |
+
clearAuthButton.style.zIndex = '1000';
|
| 146 |
+
clearAuthButton.onclick = function() {
|
| 147 |
+
clearAuthData();
|
| 148 |
+
alert('Sesión cerrada. Por favor, recarga la página.');
|
| 149 |
+
};
|
| 150 |
+
document.body.appendChild(clearAuthButton);
|
| 151 |
+
});
|
| 152 |
"""
|
| 153 |
|
| 154 |
+
# Interfaz de Gradio
|
| 155 |
+
with gr.Blocks(theme=theme) as demo:
|
| 156 |
+
gr.Markdown(description)
|
| 157 |
+
|
| 158 |
+
# Fila para centrar la imagen
|
| 159 |
+
with gr.Row():
|
| 160 |
+
with gr.Column(equal_height=True):
|
| 161 |
+
gr.Image(
|
| 162 |
+
"https://www.labattaglia.com.ar/images/about_me_pic2.jpg",
|
| 163 |
+
label="",
|
| 164 |
+
show_label=False,
|
| 165 |
+
container=False,
|
| 166 |
+
elem_id="image-container"
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
# Fila para seleccionar idioma, referencia y generar voz
|
| 170 |
+
with gr.Row():
|
| 171 |
+
with gr.Column(scale=2):
|
| 172 |
+
language_selector = gr.Dropdown(label="Idioma", choices=supported_languages)
|
| 173 |
+
reference_audio = gr.Dropdown(label="Audio de referencia", choices=reference_audios)
|
| 174 |
+
input_text = gr.Textbox(label="Texto a sintetizar", placeholder="Escribe aquí el texto que quieres convertir a voz...")
|
| 175 |
+
generate_button = gr.Button("Generar voz", variant="primary")
|
| 176 |
+
|
| 177 |
+
with gr.Column(scale=1):
|
| 178 |
+
generated_audio = gr.Audio(label="Audio generado", interactive=False)
|
| 179 |
+
metrics_output = gr.Textbox(label="Métricas", value="Tiempo de generación: -- segundos\nFactor de tiempo real: --")
|
| 180 |
+
|
| 181 |
+
# Configuración del botón para generar voz
|
| 182 |
+
generate_button.click(
|
| 183 |
+
predict,
|
| 184 |
+
inputs=[input_text, language_selector, reference_audio],
|
| 185 |
+
outputs=[generated_audio, metrics_output]
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
# Agregar el JavaScript para limpiar los datos de autenticación
|
| 189 |
+
gr.HTML("<script>" + clear_auth_js + "</script>")
|
| 190 |
+
|
| 191 |
+
# Estilos CSS personalizados
|
| 192 |
+
demo.css = """
|
| 193 |
#image-container img {
|
| 194 |
display: block;
|
| 195 |
margin-left: auto;
|
|
|
|
| 197 |
max-width: 256px;
|
| 198 |
height: auto;
|
| 199 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
"""
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
if __name__ == "__main__":
|
| 203 |
+
demo.launch(auth=[("Pedro Labattaglia", "PL2024"), ("Invitado", "PLTTS2024")])
|