shell1809/Asistente_UNEFA
0
1"""2app.py — Interfaz del Asistente de Optimización Administrativa3y Orientación Normativa UNEFA Lara4"""5 6import streamlit as st7from rag import responder8 9st.set_page_config(10 page_title="Asistente UNEFA Lara",11 page_icon="🎓",12 layout="centered",13)14 15st.title("🎓 Asistente de Orientación Normativa")16st.caption("UNEFA Núcleo Lara — Optimización Administrativa")17 18st.markdown(19 "Consulta reglamentos, normativas y procedimientos administrativos "20 "institucionales. Las respuestas se basan únicamente en los documentos "21 "oficiales cargados en el sistema."22)23 24with st.sidebar:25 st.header("Acerca de este asistente")26 st.write(27 "Este asistente responde con base en los documentos normativos "28 "y administrativos oficiales de UNEFA Lara cargados en su índice. "29 "No sustituye la consulta directa con las unidades administrativas "30 "correspondientes para trámites formales."31 )32 st.divider()33 if st.button("🗑️ Borrar historial de conversación"):34 st.session_state.historial = []35 st.rerun()36 37if "historial" not in st.session_state:38 st.session_state.historial = []39 40# Mostrar historial previo41for mensaje in st.session_state.historial:42 with st.chat_message(mensaje["rol"]):43 st.markdown(mensaje["contenido"])44 if mensaje["rol"] == "assistant" and mensaje.get("fuentes"):45 with st.expander("📄 Fuentes consultadas"):46 for f in mensaje["fuentes"]:47 st.markdown(48 f"- **{f['fuente']}** — fragmento {f['chunk_id']} "49 f"(relevancia: {f['similitud']:.2f})"50 )51 52pregunta = st.chat_input(53 "Escribe tu pregunta sobre normativa o trámites administrativos..."54)55 56if pregunta:57 st.session_state.historial.append({"rol": "user", "contenido": pregunta})58 with st.chat_message("user"):59 st.markdown(pregunta)60 61 with st.chat_message("assistant"):62 with st.spinner("Consultando los documentos normativos..."):63 try:64 respuesta, fuentes = responder(pregunta)65 except Exception as e:66 respuesta = (67 "Ocurrió un error al consultar el asistente. "68 f"Detalle técnico: {e}"69 )70 fuentes = []71 72 st.markdown(respuesta)73 if fuentes:74 with st.expander("📄 Fuentes consultadas"):75 for f in fuentes:76 st.markdown(77 f"- **{f['fuente']}** — fragmento {f['chunk_id']} "78 f"(relevancia: {f['similitud']:.2f})"79 )80 81 st.session_state.historial.append(82 {"rol": "assistant", "contenido": respuesta, "fuentes": fuentes}83 )84 