Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ def conversar_coach(mensaje, email):
|
|
| 32 |
return respuesta
|
| 33 |
|
| 34 |
# ---------- INTERFAZ PRINCIPAL (NutriBot) ---------- #
|
| 35 |
-
def crear_interfaz_nutribot(email):
|
| 36 |
with gr.Blocks(title="NutriBot Ultra 🥗") as app:
|
| 37 |
gr.Markdown(f"## 🌈 ¡Bienvenido, {email}! Tu asistente inteligente de salud y bienestar 🧠💪")
|
| 38 |
gr.Markdown("Habla con Nuti o con tu Coach Emocional, según cómo te sientas hoy 💚")
|
|
@@ -49,47 +49,11 @@ def crear_interfaz_nutribot(email):
|
|
| 49 |
boton_coach = gr.Button("Enviar")
|
| 50 |
boton_coach.click(conversar_coach, inputs=[entrada_coach, gr.State(email)], outputs=chat_coach)
|
| 51 |
|
| 52 |
-
gr.Button("Cerrar sesión 🚪").click(cerrar_sesion, outputs=None)
|
| 53 |
-
|
| 54 |
return app
|
| 55 |
|
| 56 |
-
# ---------- LOGIN Y REGISTRO ---------- #
|
| 57 |
-
def interfaz_login():
|
| 58 |
-
with gr.Blocks(title="Inicio de Sesión - NutriBot Ultra") as login_ui:
|
| 59 |
-
gr.Markdown("# 🥗 Bienvenido a NutriBot Ultra 🌟\nTu IA de nutrición y bienestar emocional.")
|
| 60 |
-
|
| 61 |
-
with gr.Tab("🔑 Iniciar sesión"):
|
| 62 |
-
email = gr.Textbox(label="Correo electrónico")
|
| 63 |
-
password = gr.Textbox(label="Contraseña", type="password")
|
| 64 |
-
boton_login = gr.Button("Entrar")
|
| 65 |
-
mensaje_login = gr.Textbox(label="Estado")
|
| 66 |
-
|
| 67 |
-
def login_action(email, password):
|
| 68 |
-
res = iniciar_sesion(email, password)
|
| 69 |
-
if res.startswith("✅"):
|
| 70 |
-
guardar_sesion(email)
|
| 71 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 72 |
-
return res
|
| 73 |
-
|
| 74 |
-
boton_login.click(login_action, inputs=[email, password], outputs=[login_ui, mensaje_login])
|
| 75 |
-
|
| 76 |
-
with gr.Tab("📝 Registrarse"):
|
| 77 |
-
nombre = gr.Textbox(label="Nombre completo")
|
| 78 |
-
correo = gr.Textbox(label="Correo electrónico")
|
| 79 |
-
contra = gr.Textbox(label="Contraseña", type="password")
|
| 80 |
-
boton_reg = gr.Button("Crear cuenta")
|
| 81 |
-
salida_reg = gr.Textbox(label="Resultado del registro")
|
| 82 |
-
boton_reg.click(registrar_usuario, inputs=[nombre, correo, contra], outputs=salida_reg)
|
| 83 |
-
|
| 84 |
-
return login_ui
|
| 85 |
-
|
| 86 |
# ---------- FLUJO PRINCIPAL ---------- #
|
| 87 |
def main():
|
| 88 |
-
|
| 89 |
-
if usuario_actual:
|
| 90 |
-
app = crear_interfaz_nutribot(usuario_actual)
|
| 91 |
-
else:
|
| 92 |
-
app = interfaz_login()
|
| 93 |
app.launch()
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
|
|
|
| 32 |
return respuesta
|
| 33 |
|
| 34 |
# ---------- INTERFAZ PRINCIPAL (NutriBot) ---------- #
|
| 35 |
+
def crear_interfaz_nutribot(email="Usuario invitado"):
|
| 36 |
with gr.Blocks(title="NutriBot Ultra 🥗") as app:
|
| 37 |
gr.Markdown(f"## 🌈 ¡Bienvenido, {email}! Tu asistente inteligente de salud y bienestar 🧠💪")
|
| 38 |
gr.Markdown("Habla con Nuti o con tu Coach Emocional, según cómo te sientas hoy 💚")
|
|
|
|
| 49 |
boton_coach = gr.Button("Enviar")
|
| 50 |
boton_coach.click(conversar_coach, inputs=[entrada_coach, gr.State(email)], outputs=chat_coach)
|
| 51 |
|
|
|
|
|
|
|
| 52 |
return app
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
# ---------- FLUJO PRINCIPAL ---------- #
|
| 55 |
def main():
|
| 56 |
+
app = crear_interfaz_nutribot()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
app.launch()
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|