Spaces:
Sleeping
Sleeping
Prueba poniendo la interfaz
Browse files
app.py
CHANGED
@@ -59,4 +59,104 @@ if __name__=="__main__":
|
|
59 |
# Carga del modelo y ejecución de la interfaz
|
60 |
src.model_load.load_model()
|
61 |
print("Lanzando interfaz")
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# Carga del modelo y ejecución de la interfaz
|
60 |
src.model_load.load_model()
|
61 |
print("Lanzando interfaz")
|
62 |
+
# Configuración de la página
|
63 |
+
st.set_page_config(
|
64 |
+
page_title="MathQA - Asistente de Matemáticas",
|
65 |
+
page_icon="🧮",
|
66 |
+
layout="centered",
|
67 |
+
initial_sidebar_state="expanded"
|
68 |
+
)
|
69 |
+
|
70 |
+
# Paleta de colores neutra
|
71 |
+
primary_color = "#010001"
|
72 |
+
secondary_color = "#E7E6E7"
|
73 |
+
background_color = "#FBFBFA"
|
74 |
+
|
75 |
+
# Estilos CSS
|
76 |
+
st.markdown(
|
77 |
+
f"""
|
78 |
+
<style>
|
79 |
+
.stApp {{ background-color: {background_color}; }}
|
80 |
+
.stTextInput>div>div>input {{
|
81 |
+
color: {primary_color};
|
82 |
+
background-color: {secondary_color};
|
83 |
+
border-radius: 8px;
|
84 |
+
}}
|
85 |
+
.stButton>button {{
|
86 |
+
color: {primary_color};
|
87 |
+
background-color: {secondary_color};
|
88 |
+
border-radius: 8px;
|
89 |
+
transition: all 0.3s;
|
90 |
+
}}
|
91 |
+
.history-box {{
|
92 |
+
border-left: 4px solid {secondary_color};
|
93 |
+
padding: 1rem;
|
94 |
+
margin: 1rem 0;
|
95 |
+
background-color: {secondary_color};
|
96 |
+
border-radius: 8px;
|
97 |
+
}}
|
98 |
+
</style>
|
99 |
+
""",
|
100 |
+
unsafe_allow_html=True
|
101 |
+
)
|
102 |
+
|
103 |
+
# Inicializar historial
|
104 |
+
if 'history' not in st.session_state:
|
105 |
+
st.session_state.history = []
|
106 |
+
|
107 |
+
# Variable auxiliar para gestionar el input
|
108 |
+
if 'temp_input' not in st.session_state:
|
109 |
+
st.session_state.temp_input = ""
|
110 |
+
|
111 |
+
# Título de la aplicación
|
112 |
+
st.title("🧮 MathQA - Asistente de Matemáticas")
|
113 |
+
st.markdown("")
|
114 |
+
|
115 |
+
# Widget de entrada con variable auxiliar
|
116 |
+
user_input = st.text_input(
|
117 |
+
"Escribe tu pregunta matemática aquí:",
|
118 |
+
value=st.session_state.temp_input,
|
119 |
+
key="user_input",
|
120 |
+
placeholder="Ej: ¿Que es una integral?"
|
121 |
+
)
|
122 |
+
|
123 |
+
# Botón de acción
|
124 |
+
col1, col2, col3 = st.columns([5, 4, 4]) # Columnas vacías a los lados para centrar
|
125 |
+
with col2:
|
126 |
+
if st.button("Resolver pregunta"):
|
127 |
+
if user_input: # Accedemos al valor ingresado
|
128 |
+
# Simular respuesta
|
129 |
+
mock_answer = ask(user_input, retriever)
|
130 |
+
|
131 |
+
# Agregar al historial
|
132 |
+
st.session_state.history.insert(0, (user_input, mock_answer))
|
133 |
+
|
134 |
+
# Limpiar la variable auxiliar
|
135 |
+
st.session_state.temp_input = ""
|
136 |
+
|
137 |
+
# Forzar actualización
|
138 |
+
st.rerun()
|
139 |
+
|
140 |
+
# Mostrar historial
|
141 |
+
if st.session_state.history:
|
142 |
+
st.markdown("---")
|
143 |
+
st.subheader("Historial de Consultas")
|
144 |
+
|
145 |
+
for idx, (pregunta, respuesta) in enumerate(st.session_state.history):
|
146 |
+
with st.container():
|
147 |
+
st.markdown(
|
148 |
+
f"""
|
149 |
+
<div class="history-box">
|
150 |
+
<strong>Pregunta {len(st.session_state.history) - idx}:</strong>
|
151 |
+
<p>{pregunta}</p>
|
152 |
+
<strong>Respuesta:</strong>
|
153 |
+
<p>{respuesta}</p>
|
154 |
+
</div>
|
155 |
+
""",
|
156 |
+
unsafe_allow_html=True
|
157 |
+
)
|
158 |
+
|
159 |
+
# Pie de página
|
160 |
+
st.markdown("---")
|
161 |
+
st.markdown("🔍 ¿Necesitas ayuda con álgebra, cálculo o geometría? ¡Estoy aquí para ayudarte!")
|
162 |
+
|