Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -152,143 +152,134 @@ def generar_link_primo(consulta):
|
|
| 152 |
# 🤖 Función principal
|
| 153 |
def responder(mensaje, historial):
|
| 154 |
mensaje = mensaje.lower().strip()
|
| 155 |
-
historial_global.append(mensaje)
|
| 156 |
|
| 157 |
-
respuestas = []
|
| 158 |
saludo = ""
|
|
|
|
| 159 |
|
| 160 |
-
# 👋
|
| 161 |
-
if any(s in mensaje for s in
|
| 162 |
saludo = "¡Hola! 😊\n\n"
|
| 163 |
-
|
| 164 |
-
|
| 165 |
if any(s in mensaje for s in saludos) and len(mensaje.strip()) < 10:
|
| 166 |
return random.choice([
|
| 167 |
"¡Hola! 😊 Soy tu asistente de la biblioteca UTB 📚\n\n¿En qué puedo ayudarte?",
|
| 168 |
"¡Hola! 👋 Estoy aquí para ayudarte con la biblioteca 📚",
|
| 169 |
-
"¡Hola! 😄 Puedes preguntarme sobre libros, horarios, servicios
|
| 170 |
])
|
| 171 |
|
| 172 |
# 🎓 CAPACITACIONES
|
| 173 |
-
if
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
| 177 |
|
| 178 |
# 📚 HORARIO
|
| 179 |
-
if any(p in mensaje for p in ["horario", "hora", "abren", "
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
# 📊 BASES DE DATOS
|
| 185 |
-
if
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
| 189 |
|
| 190 |
# 🏛️ REPOSITORIO
|
| 191 |
-
if
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
| 208 |
# 📖 RENOVACIÓN
|
| 209 |
if "renov" in mensaje:
|
| 210 |
respuesta += """📖 Renovación de libros:
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
# 📚 RESERVA
|
| 218 |
if "reserv" in mensaje:
|
| 219 |
respuesta += """📚 Reserva de libros:
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
# 📄 PAZ Y SALVO
|
| 230 |
-
if
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
if any(p in mensaje for p in ["prestamo", "préstamo", "prestar", "cuantos libros", "cuantos dias","prestan"]):
|
| 248 |
for item in base_conocimiento:
|
| 249 |
if "prestamo" in item["claves"] or "préstamo" in item["claves"]:
|
| 250 |
-
|
| 251 |
-
|
| 252 |
# 🔎 BÚSQUEDA DE LIBROS
|
| 253 |
if (
|
| 254 |
-
|
| 255 |
-
|
| 256 |
):
|
| 257 |
consulta = limpiar_consulta(mensaje).strip()
|
| 258 |
|
| 259 |
if consulta:
|
| 260 |
consultas = separar_consultas(consulta)
|
| 261 |
|
| 262 |
-
|
| 263 |
|
| 264 |
for c in consultas:
|
| 265 |
link = generar_link_primo(c)
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
respuestas.append(texto_libros)
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
# 📚 BASE DE CONOCIMIENTO (otros)
|
| 272 |
-
for item in base_conocimiento:
|
| 273 |
-
if any(p in mensaje for p in item["claves"]):
|
| 274 |
-
respuestas.append(item["respuesta"])
|
| 275 |
-
break
|
| 276 |
-
|
| 277 |
-
# 🤖 SI NO ENTENDIÓ NADA
|
| 278 |
-
if not respuestas:
|
| 279 |
-
return random.choice([
|
| 280 |
-
"No tengo esa información exacta 😅, pero puedo ayudarte con la biblioteca.",
|
| 281 |
-
"Intenta preguntarme sobre: Búsqueda de libros,📅 Horarios,🎓 Capacitaciones,📊 Bases de datos,💻Servicios,📄Reglamento,📷Fototeca,👩🏻💻Repositorio,📗Préstamos y renovación,🧾Paz y salvo,✍🏻Trabajos de grado"
|
| 282 |
-
])
|
| 283 |
|
| 284 |
-
|
| 285 |
-
respuestas = list(dict.fromkeys(respuestas))
|
| 286 |
|
| 287 |
-
#
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
-
#
|
| 291 |
-
return saludo +
|
| 292 |
|
| 293 |
chat = gr.ChatInterface(
|
| 294 |
responder,
|
|
|
|
| 152 |
# 🤖 Función principal
|
| 153 |
def responder(mensaje, historial):
|
| 154 |
mensaje = mensaje.lower().strip()
|
|
|
|
| 155 |
|
|
|
|
| 156 |
saludo = ""
|
| 157 |
+
respuesta = ""
|
| 158 |
|
| 159 |
+
# 👋 SALUDO
|
| 160 |
+
if any(s in mensaje for s in ["hola", "buenas", "buenos días", "buenas tardes"]):
|
| 161 |
saludo = "¡Hola! 😊\n\n"
|
| 162 |
+
|
| 163 |
+
# 👋 SOLO SALUDO
|
| 164 |
if any(s in mensaje for s in saludos) and len(mensaje.strip()) < 10:
|
| 165 |
return random.choice([
|
| 166 |
"¡Hola! 😊 Soy tu asistente de la biblioteca UTB 📚\n\n¿En qué puedo ayudarte?",
|
| 167 |
"¡Hola! 👋 Estoy aquí para ayudarte con la biblioteca 📚",
|
| 168 |
+
"¡Hola! 😄 Puedes preguntarme sobre libros, horarios, servicios y más"
|
| 169 |
])
|
| 170 |
|
| 171 |
# 🎓 CAPACITACIONES
|
| 172 |
+
if "capacit" in mensaje or "asesor" in mensaje:
|
| 173 |
+
respuesta += """🎓 Puedes agendar tu capacitación aquí:
|
| 174 |
+
|
| 175 |
+
👉 [Agendar capacitación](https://outlook.office365.com/book/ServiciosBibliotecarios@utb.edu.co/?ismsaljsauthenabled=true)
|
| 176 |
+
|
| 177 |
+
"""
|
| 178 |
|
| 179 |
# 📚 HORARIO
|
| 180 |
+
if any(p in mensaje for p in ["horario", "hora", "abren", "cierran", "trabajan"]):
|
| 181 |
+
respuesta += """📚 Nuestro horario es:
|
| 182 |
+
|
| 183 |
+
Campus Tecnológico: Lunes a viernes 7am - 7pm / Sábados 8am - 12m
|
| 184 |
+
Casa Lemaitre: Lunes a jueves 7am - 5pm / Viernes 7am - 6pm / Sábado 8am - 2pm
|
| 185 |
+
|
| 186 |
+
"""
|
| 187 |
|
| 188 |
# 📊 BASES DE DATOS
|
| 189 |
+
if "base de datos" in mensaje or "biblioteca digital" in mensaje:
|
| 190 |
+
respuesta += """📊 Accede a nuestras bases de datos:
|
| 191 |
+
|
| 192 |
+
👉 [Biblioteca digital](https://www.utb.edu.co/biblioteca-utb/biblioteca-digital/)
|
| 193 |
+
|
| 194 |
+
"""
|
| 195 |
|
| 196 |
# 🏛️ REPOSITORIO
|
| 197 |
+
if "repositorio" in mensaje or "tesis" in mensaje:
|
| 198 |
+
respuesta += """🏛️ Consulta el repositorio:
|
| 199 |
+
|
| 200 |
+
👉 [Repositorio UTB](https://repositorio.utb.edu.co/home)
|
| 201 |
+
|
| 202 |
+
"""
|
| 203 |
+
|
| 204 |
+
# 📖 ASISTENTE IA
|
| 205 |
+
if "asistente" in mensaje or "ia" in mensaje:
|
| 206 |
+
respuesta += """📖 Asistente de investigación:
|
| 207 |
+
|
| 208 |
+
👉 [Ir al asistente](https://primo.utb.edu.co/discovery/researchAssistant?vid=57UTB_INST:57UTB_INST)
|
| 209 |
+
|
| 210 |
+
🎥 Video:
|
| 211 |
+
👉 [Ver video](https://www.youtube.com/watch?v=aMJm7gFbCJw&t=1s)
|
| 212 |
+
|
| 213 |
+
"""
|
| 214 |
+
|
| 215 |
# 📖 RENOVACIÓN
|
| 216 |
if "renov" in mensaje:
|
| 217 |
respuesta += """📖 Renovación de libros:
|
| 218 |
|
| 219 |
+
👉 [Renovar en PRIMO](https://primo.utb.edu.co/discovery/account?vid=57UTB_INST:57UTB_INST§ion=loans&lang=es)
|
| 220 |
+
|
| 221 |
+
"""
|
| 222 |
+
|
|
|
|
| 223 |
# 📚 RESERVA
|
| 224 |
if "reserv" in mensaje:
|
| 225 |
respuesta += """📚 Reserva de libros:
|
| 226 |
+
|
| 227 |
+
👉 [Ir al catálogo](https://primo.utb.edu.co/discovery/search?vid=57UTB_INST:57UTB_INST)
|
| 228 |
+
|
| 229 |
+
🎥 Video guía:
|
| 230 |
+
👉 [Ver video](https://www.youtube.com/watch?v=ahmo6iLG2Es&t=141s)
|
| 231 |
+
|
| 232 |
+
"""
|
| 233 |
+
|
|
|
|
| 234 |
# 📄 PAZ Y SALVO
|
| 235 |
+
if "paz y salvo" in mensaje:
|
| 236 |
+
respuesta += """📄 Solicita tu paz y salvo:
|
| 237 |
+
|
| 238 |
+
👉 [Formulario](https://forms.office.com/pages/responsepage.aspx?id=UJ5k6tInGEOcuS_P_hb9QfLUIQI8HudFvLRcZQ9xPDZUOFhFMUkzNlNOWFJXSDNSNTIwSTdRNlc5WC4u&route=shorturl)
|
| 239 |
+
|
| 240 |
+
"""
|
| 241 |
+
|
| 242 |
+
# ✍🏻 TRABAJOS DE GRADO
|
| 243 |
+
if "trabajo de grado" in mensaje or "articulo" in mensaje:
|
| 244 |
+
respuesta += """✍🏻 Envío de trabajos:
|
| 245 |
+
|
| 246 |
+
👉 [Depósitos](https://primo.utb.edu.co/deposit/57UTB_INST&auth=SAML)
|
| 247 |
+
|
| 248 |
+
"""
|
| 249 |
+
|
| 250 |
+
# 📚 PRÉSTAMOS
|
| 251 |
+
if "prest" in mensaje:
|
|
|
|
| 252 |
for item in base_conocimiento:
|
| 253 |
if "prestamo" in item["claves"] or "préstamo" in item["claves"]:
|
| 254 |
+
respuesta += item["respuesta"] + "\n\n"
|
| 255 |
+
|
| 256 |
# 🔎 BÚSQUEDA DE LIBROS
|
| 257 |
if (
|
| 258 |
+
("libro" in mensaje or "autor" in mensaje)
|
| 259 |
+
and not any(p in mensaje for p in ["renov", "prest", "reserv"])
|
| 260 |
):
|
| 261 |
consulta = limpiar_consulta(mensaje).strip()
|
| 262 |
|
| 263 |
if consulta:
|
| 264 |
consultas = separar_consultas(consulta)
|
| 265 |
|
| 266 |
+
texto = "🔎 Encontré esto:\n\n"
|
| 267 |
|
| 268 |
for c in consultas:
|
| 269 |
link = generar_link_primo(c)
|
| 270 |
+
texto += f"📚 **{c.capitalize()}**\n👉 [Ver en PRIMO]({link})\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
+
respuesta += texto
|
|
|
|
| 273 |
|
| 274 |
+
# ❌ SI NO HAY RESPUESTA
|
| 275 |
+
if not respuesta:
|
| 276 |
+
return random.choice([
|
| 277 |
+
"No tengo esa información 😅",
|
| 278 |
+
"Puedes preguntarme sobre libros, horarios, servicios y más 📚"
|
| 279 |
+
])
|
| 280 |
|
| 281 |
+
# ✅ RESPUESTA FINAL
|
| 282 |
+
return saludo + respuesta
|
| 283 |
|
| 284 |
chat = gr.ChatInterface(
|
| 285 |
responder,
|