Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,64 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
import json
|
| 4 |
-
from datetime import datetime
|
| 5 |
from chatbot_nuti import buscar_respuesta
|
| 6 |
from coach_emocional import coach_emocional_inteligente
|
| 7 |
from retos_saludables import mostrar_retos, completar_reto
|
| 8 |
|
| 9 |
-
# ---------- MEMORIA ---------- #
|
| 10 |
-
MEMORIA_NUTI = []
|
| 11 |
-
MEMORIA_COACH = []
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# ---------- CHATBOT NUTI ---------- #
|
| 18 |
def conversar_nuti(mensaje, historial):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
historial.append({"role": "assistant", "content": respuesta})
|
| 23 |
return historial, ""
|
| 24 |
|
|
|
|
| 25 |
# ---------- COACH EMOCIONAL ---------- #
|
| 26 |
def conversar_coach(mensaje, historial):
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
historial.append({"role": "assistant", "content": respuesta})
|
| 31 |
return historial, ""
|
| 32 |
|
|
|
|
| 33 |
# ---------- CÁLCULO DE CALORÍAS ---------- #
|
| 34 |
def calcular_calorias(edad, peso, altura, genero, actividad, meta):
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
if genero.lower() == "mujer":
|
| 38 |
bmr = 655 + (9.6 * peso) + (1.8 * altura) - (4.7 * edad)
|
|
@@ -56,14 +82,27 @@ def calcular_calorias(edad, peso, altura, genero, actividad, meta):
|
|
| 56 |
else:
|
| 57 |
calorias_totales = round(calorias_base)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# ---------- CALORÍAS DEL RELOJ ---------- #
|
| 63 |
def calorias_reloj(calorias_quemadas):
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
# ---------- FOTO DE COMIDA ---------- #
|
| 69 |
def analizar_foto(imagen):
|
|
@@ -80,63 +119,108 @@ def analizar_foto(imagen):
|
|
| 80 |
("Pollo con arroz", 500),
|
| 81 |
("Pasta con salsa", 600)
|
| 82 |
]
|
|
|
|
| 83 |
nombre, calorias = random.choice(comidas)
|
| 84 |
return f"🍽️ Parece que comiste **{nombre}** (~{calorias} kcal).", calorias
|
| 85 |
|
|
|
|
| 86 |
def registrar_comida(imagen):
|
| 87 |
-
global calorias_restantes, historial_comidas
|
| 88 |
info, calorias = analizar_foto(imagen)
|
| 89 |
-
calorias_restantes -= calorias
|
| 90 |
-
calorias_restantes = max(calorias_restantes, 0)
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
def mostrar_historial():
|
| 96 |
-
if not historial_comidas:
|
| 97 |
return "📭 Aún no has registrado comidas hoy."
|
| 98 |
|
| 99 |
texto = "🍴 **Historial de comidas:**\n\n"
|
| 100 |
-
for i, item in enumerate(historial_comidas, 1):
|
| 101 |
texto += f"{i}. {item['comida']}\n"
|
| 102 |
|
| 103 |
-
texto += f"\n🔥 Te quedan **{calorias_restantes} kcal** por consumir hoy."
|
| 104 |
return texto
|
| 105 |
|
| 106 |
-
# ---------- RECETAS ---------- #
|
| 107 |
-
RECETAS = []
|
| 108 |
|
|
|
|
| 109 |
def subir_receta(nombre, descripcion, imagen):
|
| 110 |
if nombre and descripcion:
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
return f"✅ Receta '{nombre}' añadida correctamente."
|
|
|
|
| 113 |
return "⚠️ Ingresa nombre y descripción."
|
| 114 |
|
|
|
|
| 115 |
def mostrar_recetas():
|
| 116 |
-
if not
|
| 117 |
return "📭 No hay recetas cargadas aún."
|
| 118 |
|
| 119 |
texto = "🍽️ **Recetas Recomendadas:**\n\n"
|
| 120 |
-
for
|
| 121 |
-
texto += f"**{
|
|
|
|
| 122 |
return texto
|
| 123 |
|
|
|
|
| 124 |
# ---------- BUSCAR NUTRIÓLOGOS ---------- #
|
| 125 |
def buscar_nutriologos(pais, estado, ciudad):
|
| 126 |
ejemplos = [
|
| 127 |
-
{
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
]
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
resultados = [
|
| 136 |
n for n in ejemplos
|
| 137 |
-
if n["pais"].lower() == pais
|
| 138 |
-
or n["estado"].lower() == estado
|
| 139 |
-
or n["ciudad"].lower() == ciudad
|
| 140 |
]
|
| 141 |
|
| 142 |
if not resultados:
|
|
@@ -146,12 +230,15 @@ def buscar_nutriologos(pais, estado, ciudad):
|
|
| 146 |
for n in resultados:
|
| 147 |
texto += (
|
| 148 |
f"**{n['nombre']}** - {n['especialidad']} "
|
| 149 |
-
f"({n['ciudad']}, {n['pais']})\n
|
|
|
|
|
|
|
| 150 |
)
|
| 151 |
|
| 152 |
return texto
|
| 153 |
|
| 154 |
-
|
|
|
|
| 155 |
def guardar_informacion(nombre, edad, peso, altura, genero, actividad, meta, condicion, alergias):
|
| 156 |
perfil = {
|
| 157 |
"nombre": nombre,
|
|
@@ -164,123 +251,146 @@ def guardar_informacion(nombre, edad, peso, altura, genero, actividad, meta, con
|
|
| 164 |
"condicion": condicion,
|
| 165 |
"alergias": alergias
|
| 166 |
}
|
| 167 |
-
with open("perfil_usuario.json", "w") as f:
|
| 168 |
-
json.dump(perfil, f, indent=4)
|
| 169 |
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
# ---------- INTERFAZ PRINCIPAL ---------- #
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
with gr.
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
if __name__ == "__main__":
|
| 286 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
import json
|
|
|
|
| 4 |
from chatbot_nuti import buscar_respuesta
|
| 5 |
from coach_emocional import coach_emocional_inteligente
|
| 6 |
from retos_saludables import mostrar_retos, completar_reto
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# ---------- ESTADO GLOBAL SIMPLE ---------- #
|
| 10 |
+
estado_app = {
|
| 11 |
+
"memoria_nuti": [],
|
| 12 |
+
"memoria_coach": [],
|
| 13 |
+
"calorias_totales": 0,
|
| 14 |
+
"calorias_restantes": 0,
|
| 15 |
+
"historial_comidas": [],
|
| 16 |
+
"recetas": []
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
|
| 20 |
# ---------- CHATBOT NUTI ---------- #
|
| 21 |
def conversar_nuti(mensaje, historial):
|
| 22 |
+
if not mensaje.strip():
|
| 23 |
+
return historial, ""
|
| 24 |
+
|
| 25 |
+
estado_app["memoria_nuti"].append({"user": mensaje})
|
| 26 |
+
|
| 27 |
+
if historial is None:
|
| 28 |
+
historial = []
|
| 29 |
+
|
| 30 |
+
historial.append({"role": "user", "content": mensaje})
|
| 31 |
+
|
| 32 |
+
respuesta = buscar_respuesta(mensaje, estado_app["memoria_nuti"])
|
| 33 |
+
estado_app["memoria_nuti"].append({"nuti": respuesta})
|
| 34 |
+
|
| 35 |
historial.append({"role": "assistant", "content": respuesta})
|
| 36 |
return historial, ""
|
| 37 |
|
| 38 |
+
|
| 39 |
# ---------- COACH EMOCIONAL ---------- #
|
| 40 |
def conversar_coach(mensaje, historial):
|
| 41 |
+
if not mensaje.strip():
|
| 42 |
+
return historial, ""
|
| 43 |
+
|
| 44 |
+
estado_app["memoria_coach"].append({"user": mensaje})
|
| 45 |
+
|
| 46 |
+
if historial is None:
|
| 47 |
+
historial = []
|
| 48 |
+
|
| 49 |
+
historial.append({"role": "user", "content": mensaje})
|
| 50 |
+
|
| 51 |
+
respuesta = coach_emocional_inteligente(mensaje, estado_app["memoria_coach"])
|
| 52 |
+
estado_app["memoria_coach"].append({"coach": respuesta})
|
| 53 |
+
|
| 54 |
historial.append({"role": "assistant", "content": respuesta})
|
| 55 |
return historial, ""
|
| 56 |
|
| 57 |
+
|
| 58 |
# ---------- CÁLCULO DE CALORÍAS ---------- #
|
| 59 |
def calcular_calorias(edad, peso, altura, genero, actividad, meta):
|
| 60 |
+
if not all([edad, peso, altura, genero, actividad, meta]):
|
| 61 |
+
return "⚠️ Completa todos los datos para calcular tus calorías."
|
| 62 |
|
| 63 |
if genero.lower() == "mujer":
|
| 64 |
bmr = 655 + (9.6 * peso) + (1.8 * altura) - (4.7 * edad)
|
|
|
|
| 82 |
else:
|
| 83 |
calorias_totales = round(calorias_base)
|
| 84 |
|
| 85 |
+
estado_app["calorias_totales"] = calorias_totales
|
| 86 |
+
estado_app["calorias_restantes"] = calorias_totales
|
| 87 |
+
|
| 88 |
+
return (
|
| 89 |
+
f"🎯 Tu meta es **{meta.lower()}**.\n"
|
| 90 |
+
f"🔥 Puedes consumir aproximadamente **{calorias_totales} calorías por día**."
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
|
| 94 |
# ---------- CALORÍAS DEL RELOJ ---------- #
|
| 95 |
def calorias_reloj(calorias_quemadas):
|
| 96 |
+
if calorias_quemadas is None:
|
| 97 |
+
return "⚠️ Ingresa las calorías quemadas."
|
| 98 |
+
|
| 99 |
+
estado_app["calorias_restantes"] += calorias_quemadas
|
| 100 |
+
|
| 101 |
+
return (
|
| 102 |
+
f"⌚ Has quemado **{calorias_quemadas} kcal**.\n"
|
| 103 |
+
f"🔥 Te quedan **{estado_app['calorias_restantes']} kcal** disponibles hoy."
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
|
| 107 |
# ---------- FOTO DE COMIDA ---------- #
|
| 108 |
def analizar_foto(imagen):
|
|
|
|
| 119 |
("Pollo con arroz", 500),
|
| 120 |
("Pasta con salsa", 600)
|
| 121 |
]
|
| 122 |
+
|
| 123 |
nombre, calorias = random.choice(comidas)
|
| 124 |
return f"🍽️ Parece que comiste **{nombre}** (~{calorias} kcal).", calorias
|
| 125 |
|
| 126 |
+
|
| 127 |
def registrar_comida(imagen):
|
|
|
|
| 128 |
info, calorias = analizar_foto(imagen)
|
|
|
|
|
|
|
| 129 |
|
| 130 |
+
if calorias == 0:
|
| 131 |
+
return info
|
| 132 |
+
|
| 133 |
+
estado_app["calorias_restantes"] -= calorias
|
| 134 |
+
estado_app["calorias_restantes"] = max(estado_app["calorias_restantes"], 0)
|
| 135 |
+
|
| 136 |
+
estado_app["historial_comidas"].append({
|
| 137 |
+
"comida": info,
|
| 138 |
+
"calorias": calorias
|
| 139 |
+
})
|
| 140 |
+
|
| 141 |
+
return (
|
| 142 |
+
f"{info}\n\n"
|
| 143 |
+
f"🔥 Calorías restantes del día: **{estado_app['calorias_restantes']} kcal**."
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
|
| 147 |
def mostrar_historial():
|
| 148 |
+
if not estado_app["historial_comidas"]:
|
| 149 |
return "📭 Aún no has registrado comidas hoy."
|
| 150 |
|
| 151 |
texto = "🍴 **Historial de comidas:**\n\n"
|
| 152 |
+
for i, item in enumerate(estado_app["historial_comidas"], 1):
|
| 153 |
texto += f"{i}. {item['comida']}\n"
|
| 154 |
|
| 155 |
+
texto += f"\n🔥 Te quedan **{estado_app['calorias_restantes']} kcal** por consumir hoy."
|
| 156 |
return texto
|
| 157 |
|
|
|
|
|
|
|
| 158 |
|
| 159 |
+
# ---------- RECETAS ---------- #
|
| 160 |
def subir_receta(nombre, descripcion, imagen):
|
| 161 |
if nombre and descripcion:
|
| 162 |
+
estado_app["recetas"].append({
|
| 163 |
+
"nombre": nombre,
|
| 164 |
+
"descripcion": descripcion,
|
| 165 |
+
"imagen": imagen
|
| 166 |
+
})
|
| 167 |
return f"✅ Receta '{nombre}' añadida correctamente."
|
| 168 |
+
|
| 169 |
return "⚠️ Ingresa nombre y descripción."
|
| 170 |
|
| 171 |
+
|
| 172 |
def mostrar_recetas():
|
| 173 |
+
if not estado_app["recetas"]:
|
| 174 |
return "📭 No hay recetas cargadas aún."
|
| 175 |
|
| 176 |
texto = "🍽️ **Recetas Recomendadas:**\n\n"
|
| 177 |
+
for receta in estado_app["recetas"]:
|
| 178 |
+
texto += f"**{receta['nombre']}**\n{receta['descripcion']}\n\n"
|
| 179 |
+
|
| 180 |
return texto
|
| 181 |
|
| 182 |
+
|
| 183 |
# ---------- BUSCAR NUTRIÓLOGOS ---------- #
|
| 184 |
def buscar_nutriologos(pais, estado, ciudad):
|
| 185 |
ejemplos = [
|
| 186 |
+
{
|
| 187 |
+
"nombre": "Dra. Sofía Martínez",
|
| 188 |
+
"pais": "México",
|
| 189 |
+
"estado": "Sonora",
|
| 190 |
+
"ciudad": "Hermosillo",
|
| 191 |
+
"especialidad": "Nutrición deportiva",
|
| 192 |
+
"redes": "@nutrisofi (Instagram)",
|
| 193 |
+
"reseña": "⭐️⭐️⭐️⭐️⭐️ 4.9"
|
| 194 |
+
},
|
| 195 |
+
{
|
| 196 |
+
"nombre": "Lic. Andrés Gómez",
|
| 197 |
+
"pais": "México",
|
| 198 |
+
"estado": "CDMX",
|
| 199 |
+
"ciudad": "Coyoacán",
|
| 200 |
+
"especialidad": "Nutrición clínica",
|
| 201 |
+
"redes": "@andresnutricion (TikTok)",
|
| 202 |
+
"reseña": "⭐️⭐️⭐️⭐️ 4.7"
|
| 203 |
+
},
|
| 204 |
+
{
|
| 205 |
+
"nombre": "Dra. Camila Silva",
|
| 206 |
+
"pais": "Chile",
|
| 207 |
+
"estado": "Región Metropolitana",
|
| 208 |
+
"ciudad": "Santiago",
|
| 209 |
+
"especialidad": "Salud emocional",
|
| 210 |
+
"redes": "@camila.wellness (Instagram)",
|
| 211 |
+
"reseña": "⭐️⭐️⭐️⭐️⭐️ 5.0"
|
| 212 |
+
}
|
| 213 |
]
|
| 214 |
|
| 215 |
+
pais = (pais or "").strip().lower()
|
| 216 |
+
estado = (estado or "").strip().lower()
|
| 217 |
+
ciudad = (ciudad or "").strip().lower()
|
| 218 |
+
|
| 219 |
resultados = [
|
| 220 |
n for n in ejemplos
|
| 221 |
+
if (pais and n["pais"].lower() == pais)
|
| 222 |
+
or (estado and n["estado"].lower() == estado)
|
| 223 |
+
or (ciudad and n["ciudad"].lower() == ciudad)
|
| 224 |
]
|
| 225 |
|
| 226 |
if not resultados:
|
|
|
|
| 230 |
for n in resultados:
|
| 231 |
texto += (
|
| 232 |
f"**{n['nombre']}** - {n['especialidad']} "
|
| 233 |
+
f"({n['ciudad']}, {n['pais']})\n"
|
| 234 |
+
f"📱 {n['redes']}\n"
|
| 235 |
+
f"💬 {n['reseña']}\n\n"
|
| 236 |
)
|
| 237 |
|
| 238 |
return texto
|
| 239 |
|
| 240 |
+
|
| 241 |
+
# ---------- GUARDAR DATOS ---------- #
|
| 242 |
def guardar_informacion(nombre, edad, peso, altura, genero, actividad, meta, condicion, alergias):
|
| 243 |
perfil = {
|
| 244 |
"nombre": nombre,
|
|
|
|
| 251 |
"condicion": condicion,
|
| 252 |
"alergias": alergias
|
| 253 |
}
|
|
|
|
|
|
|
| 254 |
|
| 255 |
+
with open("perfil_usuario.json", "w", encoding="utf-8") as f:
|
| 256 |
+
json.dump(perfil, f, indent=4, ensure_ascii=False)
|
| 257 |
+
|
| 258 |
+
mensaje_guardado = (
|
| 259 |
+
f"✅ Información guardada.\n"
|
| 260 |
+
f"**Condición:** {condicion or 'ninguna'}\n"
|
| 261 |
+
f"**Alergias:** {alergias or 'ninguna'}"
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
mensaje_calorias = calcular_calorias(edad, peso, altura, genero, actividad, meta)
|
| 265 |
+
|
| 266 |
+
return f"{mensaje_guardado}\n\n{mensaje_calorias}"
|
| 267 |
+
|
| 268 |
|
| 269 |
# ---------- INTERFAZ PRINCIPAL ---------- #
|
| 270 |
+
with gr.Blocks(title="NutriBot IA 🥗") as app:
|
| 271 |
+
gr.Markdown("# 🧠 Bienvenido a **NutriBot IA** 🍎")
|
| 272 |
+
gr.Markdown("Comer sano, inteligente y divertido. 🌿")
|
| 273 |
+
|
| 274 |
+
# --- DATOS PERSONALES --- #
|
| 275 |
+
with gr.Tab("👤 Datos Personales"):
|
| 276 |
+
with gr.Row():
|
| 277 |
+
nombre = gr.Textbox(label="Nombre completo")
|
| 278 |
+
edad = gr.Number(label="Edad (años)")
|
| 279 |
+
peso = gr.Number(label="Peso (kg)")
|
| 280 |
+
altura = gr.Number(label="Altura (cm)")
|
| 281 |
+
|
| 282 |
+
genero = gr.Radio(["Hombre", "Mujer"], label="Género")
|
| 283 |
+
actividad = gr.Dropdown(
|
| 284 |
+
["Sedentario", "Ligero", "Moderado", "Activo", "Muy activo"],
|
| 285 |
+
label="Nivel de actividad física"
|
| 286 |
+
)
|
| 287 |
+
meta = gr.Radio(
|
| 288 |
+
["Bajar de peso", "Mantener peso", "Subir de peso"],
|
| 289 |
+
label="🎯 Meta personal"
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
condicion = gr.Textbox(
|
| 293 |
+
label="🩺 Condición alimenticia o enfermedad",
|
| 294 |
+
placeholder="Ejemplo: diabetes, hipertensión, intolerancia a la lactosa..."
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
alergias = gr.Textbox(
|
| 298 |
+
label="🚫 Alergias alimenticias",
|
| 299 |
+
placeholder="Ejemplo: maní, gluten, mariscos..."
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
guardar_datos = gr.Button("Guardar información 🧾")
|
| 303 |
+
salida_datos = gr.Markdown()
|
| 304 |
+
|
| 305 |
+
guardar_datos.click(
|
| 306 |
+
guardar_informacion,
|
| 307 |
+
inputs=[nombre, edad, peso, altura, genero, actividad, meta, condicion, alergias],
|
| 308 |
+
outputs=salida_datos
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
# --- REGISTRO DE COMIDAS --- #
|
| 312 |
+
with gr.Tab("📸 Registro de Comidas"):
|
| 313 |
+
gr.Markdown("Sube una foto de tu comida y NutriBot estimará las calorías 🍽️")
|
| 314 |
+
imagen = gr.Image(label="Foto de tu comida", type="filepath")
|
| 315 |
+
|
| 316 |
+
boton_registrar = gr.Button("Registrar comida 🍎")
|
| 317 |
+
salida_foto = gr.Markdown()
|
| 318 |
+
boton_registrar.click(registrar_comida, inputs=imagen, outputs=salida_foto)
|
| 319 |
+
|
| 320 |
+
boton_historial = gr.Button("Ver historial 🍴")
|
| 321 |
+
salida_historial = gr.Markdown()
|
| 322 |
+
boton_historial.click(mostrar_historial, outputs=salida_historial)
|
| 323 |
+
|
| 324 |
+
# --- CALORÍAS DEL RELOJ --- #
|
| 325 |
+
with gr.Tab("⌚ Calorías del Reloj"):
|
| 326 |
+
calorias_quemadas = gr.Number(label="Calorías quemadas (reloj inteligente)")
|
| 327 |
+
boton_reloj = gr.Button("Actualizar 🔁")
|
| 328 |
+
salida_reloj = gr.Markdown()
|
| 329 |
+
boton_reloj.click(calorias_reloj, inputs=calorias_quemadas, outputs=salida_reloj)
|
| 330 |
+
|
| 331 |
+
# --- CHAT NUTI --- #
|
| 332 |
+
with gr.Tab("🤖 Chat con Nuti"):
|
| 333 |
+
chat_nuti = gr.Chatbot(label="Nuti - Tu guía de nutrición 🍎", type="messages")
|
| 334 |
+
entrada_nuti = gr.Textbox(label="Escribe algo para Nuti...")
|
| 335 |
+
boton_nuti = gr.Button("Enviar")
|
| 336 |
+
boton_nuti.click(
|
| 337 |
+
conversar_nuti,
|
| 338 |
+
inputs=[entrada_nuti, chat_nuti],
|
| 339 |
+
outputs=[chat_nuti, entrada_nuti]
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
# --- COACH EMOCIONAL --- #
|
| 343 |
+
with gr.Tab("🧘 Coach Emocional"):
|
| 344 |
+
chat_coach = gr.Chatbot(label="Coach Emocional 🌿", type="messages")
|
| 345 |
+
entrada_coach = gr.Textbox(label="Cuéntame cómo te sientes hoy...")
|
| 346 |
+
boton_coach = gr.Button("Enviar")
|
| 347 |
+
boton_coach.click(
|
| 348 |
+
conversar_coach,
|
| 349 |
+
inputs=[entrada_coach, chat_coach],
|
| 350 |
+
outputs=[chat_coach, entrada_coach]
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
# --- RECETAS --- #
|
| 354 |
+
with gr.Tab("🍽️ Recetas del Nutriólogo"):
|
| 355 |
+
nombre_rec = gr.Textbox(label="Nombre de la receta")
|
| 356 |
+
descripcion = gr.Textbox(label="Descripción o ingredientes")
|
| 357 |
+
imagen_receta = gr.Image(label="Imagen (opcional)")
|
| 358 |
+
boton_subir = gr.Button("Subir receta")
|
| 359 |
+
salida_subir = gr.Textbox(label="Estado")
|
| 360 |
+
boton_subir.click(
|
| 361 |
+
subir_receta,
|
| 362 |
+
inputs=[nombre_rec, descripcion, imagen_receta],
|
| 363 |
+
outputs=salida_subir
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
+
boton_ver = gr.Button("Ver recetas disponibles 🍲")
|
| 367 |
+
salida_recetas = gr.Markdown()
|
| 368 |
+
boton_ver.click(mostrar_recetas, outputs=salida_recetas)
|
| 369 |
+
|
| 370 |
+
# --- RETOS --- #
|
| 371 |
+
with gr.Tab("🎯 Retos Saludables"):
|
| 372 |
+
salida_retos = gr.Markdown()
|
| 373 |
+
|
| 374 |
+
boton_ver_retos = gr.Button("Ver Retos del Día")
|
| 375 |
+
boton_ver_retos.click(mostrar_retos, outputs=salida_retos)
|
| 376 |
+
|
| 377 |
+
numero_reto = gr.Number(label="Número de reto completado")
|
| 378 |
+
boton_completar = gr.Button("Completar Reto 🏅")
|
| 379 |
+
boton_completar.click(completar_reto, inputs=numero_reto, outputs=salida_retos)
|
| 380 |
+
|
| 381 |
+
# --- NUTRIÓLOGOS --- #
|
| 382 |
+
with gr.Tab("🧑⚕️ Buscar Nutriólogos"):
|
| 383 |
+
pais = gr.Textbox(label="País")
|
| 384 |
+
estado = gr.Textbox(label="Estado")
|
| 385 |
+
ciudad = gr.Textbox(label="Ciudad")
|
| 386 |
+
boton_buscar = gr.Button("Buscar Nutriólogos 🌍")
|
| 387 |
+
salida_nutri = gr.Markdown()
|
| 388 |
+
boton_buscar.click(
|
| 389 |
+
buscar_nutriologos,
|
| 390 |
+
inputs=[pais, estado, ciudad],
|
| 391 |
+
outputs=salida_nutri
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
|
| 395 |
if __name__ == "__main__":
|
| 396 |
+
app.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|