Spaces:
Sleeping
Sleeping
Update src/st.py
Browse files
src/st.py
CHANGED
|
@@ -1,105 +1,105 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
|
| 3 |
-
def interfaz():
|
| 4 |
-
|
| 5 |
-
# Configuración de la página
|
| 6 |
-
st.set_page_config(
|
| 7 |
-
page_title="MathQA - Asistente de Matemáticas",
|
| 8 |
-
page_icon="🧮",
|
| 9 |
-
layout="centered",
|
| 10 |
-
initial_sidebar_state="expanded"
|
| 11 |
-
)
|
| 12 |
-
|
| 13 |
-
# Paleta de colores neutra
|
| 14 |
-
primary_color = "#010001"
|
| 15 |
-
secondary_color = "#E7E6E7"
|
| 16 |
-
background_color = "#FBFBFA"
|
| 17 |
-
|
| 18 |
-
# Estilos CSS
|
| 19 |
-
st.markdown(
|
| 20 |
-
f"""
|
| 21 |
-
<style>
|
| 22 |
-
.stApp {{ background-color: {background_color}; }}
|
| 23 |
-
.stTextInput>div>div>input {{
|
| 24 |
-
color: {primary_color};
|
| 25 |
-
background-color: {secondary_color};
|
| 26 |
-
border-radius: 8px;
|
| 27 |
-
}}
|
| 28 |
-
.stButton>button {{
|
| 29 |
-
color: {primary_color};
|
| 30 |
-
background-color: {secondary_color};
|
| 31 |
-
border-radius: 8px;
|
| 32 |
-
transition: all 0.3s;
|
| 33 |
-
}}
|
| 34 |
-
.history-box {{
|
| 35 |
-
border-left: 4px solid {secondary_color};
|
| 36 |
-
padding: 1rem;
|
| 37 |
-
margin: 1rem 0;
|
| 38 |
-
background-color: {secondary_color
|
| 39 |
-
};
|
| 40 |
-
border-radius: 8px;
|
| 41 |
-
}}
|
| 42 |
-
</style>
|
| 43 |
-
""",
|
| 44 |
-
unsafe_allow_html=True
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
# Inicializar historial
|
| 48 |
-
if 'history' not in st.session_state:
|
| 49 |
-
st.session_state.history = []
|
| 50 |
-
|
| 51 |
-
# Variable auxiliar para gestionar el input
|
| 52 |
-
if 'temp_input' not in st.session_state:
|
| 53 |
-
st.session_state.temp_input = ""
|
| 54 |
-
|
| 55 |
-
# Título de la aplicación
|
| 56 |
-
st.title("🧮 MathQA - Asistente de Matemáticas")
|
| 57 |
-
st.markdown("")
|
| 58 |
-
|
| 59 |
-
# Widget de entrada con variable auxiliar
|
| 60 |
-
user_input = st.text_input(
|
| 61 |
-
"Escribe tu pregunta matemática aquí:",
|
| 62 |
-
value=st.session_state.temp_input,
|
| 63 |
-
key="user_input",
|
| 64 |
-
placeholder="Ej: ¿Que es una integral?"
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
# Botón de acción
|
| 68 |
-
col1, col2, col3 = st.columns([5, 4, 4]) # Columnas vacías a los lados para centrar
|
| 69 |
-
with col2:
|
| 70 |
-
if st.button("Resolver pregunta"):
|
| 71 |
-
if user_input: # Accedemos al valor ingresado
|
| 72 |
-
# Simular respuesta
|
| 73 |
-
mock_answer = ask(user_input,retriever)
|
| 74 |
-
|
| 75 |
-
# Agregar al historial
|
| 76 |
-
st.session_state.history.insert(0, (user_input, mock_answer))
|
| 77 |
-
|
| 78 |
-
# Limpiar la variable auxiliar
|
| 79 |
-
st.session_state.temp_input = ""
|
| 80 |
-
|
| 81 |
-
# Forzar actualización
|
| 82 |
-
st.rerun()
|
| 83 |
-
|
| 84 |
-
# Mostrar historial
|
| 85 |
-
if st.session_state.history:
|
| 86 |
-
st.markdown("---")
|
| 87 |
-
st.subheader("Historial de Consultas")
|
| 88 |
-
|
| 89 |
-
for idx, (pregunta, respuesta) in enumerate(st.session_state.history):
|
| 90 |
-
with st.container():
|
| 91 |
-
st.markdown(
|
| 92 |
-
f"""
|
| 93 |
-
<div class="history-box">
|
| 94 |
-
<strong>Pregunta {len(st.session_state.history)-idx}:</strong>
|
| 95 |
-
<p>{pregunta}</p>
|
| 96 |
-
<strong>Respuesta:</strong>
|
| 97 |
-
<p>{respuesta}</p>
|
| 98 |
-
</div>
|
| 99 |
-
""",
|
| 100 |
-
unsafe_allow_html=True
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
# Pie de página
|
| 104 |
-
st.markdown("---")
|
| 105 |
-
st.markdown("🔍 ¿Necesitas ayuda con álgebra, cálculo o geometría? ¡Estoy aquí para ayudarte!")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from model_load import ask
|
| 3 |
+
def interfaz():
|
| 4 |
+
|
| 5 |
+
# Configuración de la página
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="MathQA - Asistente de Matemáticas",
|
| 8 |
+
page_icon="🧮",
|
| 9 |
+
layout="centered",
|
| 10 |
+
initial_sidebar_state="expanded"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Paleta de colores neutra
|
| 14 |
+
primary_color = "#010001"
|
| 15 |
+
secondary_color = "#E7E6E7"
|
| 16 |
+
background_color = "#FBFBFA"
|
| 17 |
+
|
| 18 |
+
# Estilos CSS
|
| 19 |
+
st.markdown(
|
| 20 |
+
f"""
|
| 21 |
+
<style>
|
| 22 |
+
.stApp {{ background-color: {background_color}; }}
|
| 23 |
+
.stTextInput>div>div>input {{
|
| 24 |
+
color: {primary_color};
|
| 25 |
+
background-color: {secondary_color};
|
| 26 |
+
border-radius: 8px;
|
| 27 |
+
}}
|
| 28 |
+
.stButton>button {{
|
| 29 |
+
color: {primary_color};
|
| 30 |
+
background-color: {secondary_color};
|
| 31 |
+
border-radius: 8px;
|
| 32 |
+
transition: all 0.3s;
|
| 33 |
+
}}
|
| 34 |
+
.history-box {{
|
| 35 |
+
border-left: 4px solid {secondary_color};
|
| 36 |
+
padding: 1rem;
|
| 37 |
+
margin: 1rem 0;
|
| 38 |
+
background-color: {secondary_color
|
| 39 |
+
};
|
| 40 |
+
border-radius: 8px;
|
| 41 |
+
}}
|
| 42 |
+
</style>
|
| 43 |
+
""",
|
| 44 |
+
unsafe_allow_html=True
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# Inicializar historial
|
| 48 |
+
if 'history' not in st.session_state:
|
| 49 |
+
st.session_state.history = []
|
| 50 |
+
|
| 51 |
+
# Variable auxiliar para gestionar el input
|
| 52 |
+
if 'temp_input' not in st.session_state:
|
| 53 |
+
st.session_state.temp_input = ""
|
| 54 |
+
|
| 55 |
+
# Título de la aplicación
|
| 56 |
+
st.title("🧮 MathQA - Asistente de Matemáticas")
|
| 57 |
+
st.markdown("")
|
| 58 |
+
|
| 59 |
+
# Widget de entrada con variable auxiliar
|
| 60 |
+
user_input = st.text_input(
|
| 61 |
+
"Escribe tu pregunta matemática aquí:",
|
| 62 |
+
value=st.session_state.temp_input,
|
| 63 |
+
key="user_input",
|
| 64 |
+
placeholder="Ej: ¿Que es una integral?"
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Botón de acción
|
| 68 |
+
col1, col2, col3 = st.columns([5, 4, 4]) # Columnas vacías a los lados para centrar
|
| 69 |
+
with col2:
|
| 70 |
+
if st.button("Resolver pregunta"):
|
| 71 |
+
if user_input: # Accedemos al valor ingresado
|
| 72 |
+
# Simular respuesta
|
| 73 |
+
mock_answer = ask(user_input,retriever)
|
| 74 |
+
|
| 75 |
+
# Agregar al historial
|
| 76 |
+
st.session_state.history.insert(0, (user_input, mock_answer))
|
| 77 |
+
|
| 78 |
+
# Limpiar la variable auxiliar
|
| 79 |
+
st.session_state.temp_input = ""
|
| 80 |
+
|
| 81 |
+
# Forzar actualización
|
| 82 |
+
st.rerun()
|
| 83 |
+
|
| 84 |
+
# Mostrar historial
|
| 85 |
+
if st.session_state.history:
|
| 86 |
+
st.markdown("---")
|
| 87 |
+
st.subheader("Historial de Consultas")
|
| 88 |
+
|
| 89 |
+
for idx, (pregunta, respuesta) in enumerate(st.session_state.history):
|
| 90 |
+
with st.container():
|
| 91 |
+
st.markdown(
|
| 92 |
+
f"""
|
| 93 |
+
<div class="history-box">
|
| 94 |
+
<strong>Pregunta {len(st.session_state.history)-idx}:</strong>
|
| 95 |
+
<p>{pregunta}</p>
|
| 96 |
+
<strong>Respuesta:</strong>
|
| 97 |
+
<p>{respuesta}</p>
|
| 98 |
+
</div>
|
| 99 |
+
""",
|
| 100 |
+
unsafe_allow_html=True
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
# Pie de página
|
| 104 |
+
st.markdown("---")
|
| 105 |
+
st.markdown("🔍 ¿Necesitas ayuda con álgebra, cálculo o geometría? ¡Estoy aquí para ayudarte!")
|