Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
@@ -71,47 +71,35 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
71 |
# Inicializar estados si no existen
|
72 |
if 'text_input' not in st.session_state:
|
73 |
st.session_state.text_input = ""
|
|
|
|
|
74 |
if 'show_results' not in st.session_state:
|
75 |
st.session_state.show_results = False
|
76 |
if 'current_doc' not in st.session_state:
|
77 |
st.session_state.current_doc = None
|
78 |
if 'current_metrics' not in st.session_state:
|
79 |
st.session_state.current_metrics = None
|
80 |
-
|
81 |
-
# st.markdown("## An谩lisis Inicial de Escritura")
|
82 |
-
|
83 |
-
# A帽adir selector de tipo de texto
|
84 |
-
text_type = st.selectbox(
|
85 |
-
"Tipo de texto a analizar:",
|
86 |
-
options=list(TEXT_TYPES.keys()),
|
87 |
-
format_func=lambda x: TEXT_TYPES[x]['name'],
|
88 |
-
help="Selecciona el tipo de texto para ajustar los criterios de evaluaci贸n"
|
89 |
-
)
|
90 |
-
|
91 |
-
# Guardar el tipo seleccionado en session_state
|
92 |
-
st.session_state.current_text_type = text_type
|
93 |
-
|
94 |
try:
|
95 |
# Container principal con dos columnas
|
96 |
with st.container():
|
97 |
input_col, results_col = st.columns([1,2])
|
98 |
|
99 |
with input_col:
|
100 |
-
# Definir funci贸n para manejar cambios de texto
|
101 |
-
def on_text_change():
|
102 |
-
st.session_state.text_input = st.session_state.text_area
|
103 |
-
st.session_state.show_results = False
|
104 |
-
|
105 |
# Text area con manejo de estado
|
106 |
text_input = st.text_area(
|
107 |
t.get('input_prompt', "Escribe o pega tu texto aqu铆:"),
|
108 |
height=400,
|
109 |
key="text_area",
|
110 |
value=st.session_state.text_input,
|
111 |
-
on_change=on_text_change,
|
112 |
help="Este texto ser谩 analizado para darte recomendaciones personalizadas"
|
113 |
)
|
114 |
|
|
|
|
|
|
|
|
|
|
|
115 |
if st.button(
|
116 |
t.get('analyze_button', "Analizar mi escritura"),
|
117 |
type="primary",
|
@@ -136,7 +124,6 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
136 |
st.session_state.current_doc = doc
|
137 |
st.session_state.current_metrics = metrics
|
138 |
st.session_state.show_results = True
|
139 |
-
st.session_state.text_input = text_input
|
140 |
|
141 |
except Exception as e:
|
142 |
logger.error(f"Error en an谩lisis: {str(e)}")
|
@@ -145,9 +132,23 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
145 |
# Mostrar resultados en la columna derecha
|
146 |
with results_col:
|
147 |
if st.session_state.show_results and st.session_state.current_metrics is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
display_results(
|
149 |
metrics=st.session_state.current_metrics,
|
150 |
-
text_type=
|
151 |
)
|
152 |
|
153 |
except Exception as e:
|
|
|
71 |
# Inicializar estados si no existen
|
72 |
if 'text_input' not in st.session_state:
|
73 |
st.session_state.text_input = ""
|
74 |
+
if 'text_area' not in st.session_state: # A帽adir inicializaci贸n de text_area
|
75 |
+
st.session_state.text_area = ""
|
76 |
if 'show_results' not in st.session_state:
|
77 |
st.session_state.show_results = False
|
78 |
if 'current_doc' not in st.session_state:
|
79 |
st.session_state.current_doc = None
|
80 |
if 'current_metrics' not in st.session_state:
|
81 |
st.session_state.current_metrics = None
|
82 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
try:
|
84 |
# Container principal con dos columnas
|
85 |
with st.container():
|
86 |
input_col, results_col = st.columns([1,2])
|
87 |
|
88 |
with input_col:
|
|
|
|
|
|
|
|
|
|
|
89 |
# Text area con manejo de estado
|
90 |
text_input = st.text_area(
|
91 |
t.get('input_prompt', "Escribe o pega tu texto aqu铆:"),
|
92 |
height=400,
|
93 |
key="text_area",
|
94 |
value=st.session_state.text_input,
|
|
|
95 |
help="Este texto ser谩 analizado para darte recomendaciones personalizadas"
|
96 |
)
|
97 |
|
98 |
+
# Funci贸n para manejar cambios de texto
|
99 |
+
if text_input != st.session_state.text_input:
|
100 |
+
st.session_state.text_input = text_input
|
101 |
+
st.session_state.show_results = False
|
102 |
+
|
103 |
if st.button(
|
104 |
t.get('analyze_button', "Analizar mi escritura"),
|
105 |
type="primary",
|
|
|
124 |
st.session_state.current_doc = doc
|
125 |
st.session_state.current_metrics = metrics
|
126 |
st.session_state.show_results = True
|
|
|
127 |
|
128 |
except Exception as e:
|
129 |
logger.error(f"Error en an谩lisis: {str(e)}")
|
|
|
132 |
# Mostrar resultados en la columna derecha
|
133 |
with results_col:
|
134 |
if st.session_state.show_results and st.session_state.current_metrics is not None:
|
135 |
+
# Primero los radio buttons para tipo de texto
|
136 |
+
st.markdown("### Tipo de texto")
|
137 |
+
text_type = st.radio(
|
138 |
+
"",
|
139 |
+
options=list(TEXT_TYPES.keys()),
|
140 |
+
format_func=lambda x: TEXT_TYPES[x]['name'],
|
141 |
+
horizontal=True,
|
142 |
+
key="text_type_radio",
|
143 |
+
help="Selecciona el tipo de texto para ajustar los criterios de evaluaci贸n"
|
144 |
+
)
|
145 |
+
|
146 |
+
st.session_state.current_text_type = text_type
|
147 |
+
|
148 |
+
# Luego mostrar los resultados
|
149 |
display_results(
|
150 |
metrics=st.session_state.current_metrics,
|
151 |
+
text_type=text_type
|
152 |
)
|
153 |
|
154 |
except Exception as e:
|