Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
@@ -29,7 +29,6 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
29 |
|
30 |
# Container principal con dos columnas
|
31 |
with st.container():
|
32 |
-
# Columnas para entrada y resultados
|
33 |
input_col, results_col = st.columns([1,2])
|
34 |
|
35 |
with input_col:
|
@@ -37,33 +36,50 @@ def display_current_situation_interface(lang_code, nlp_models, t):
|
|
37 |
text_input = st.text_area(
|
38 |
t.get('input_prompt', "Escribe o pega tu texto aquí:"),
|
39 |
height=400,
|
40 |
-
key=
|
41 |
help="Este texto será analizado para darte recomendaciones personalizadas"
|
42 |
)
|
43 |
|
44 |
if st.button(
|
45 |
t.get('analyze_button', "Analizar mi escritura"),
|
46 |
type="primary",
|
47 |
-
disabled=not text_input,
|
48 |
-
use_container_width=True
|
|
|
49 |
):
|
50 |
try:
|
51 |
with st.spinner(t.get('processing', "Analizando...")):
|
|
|
|
|
|
|
|
|
|
|
52 |
# Procesar texto y obtener métricas
|
53 |
doc = nlp_models[lang_code](text_input)
|
54 |
metrics = analyze_text_dimensions(doc)
|
55 |
|
56 |
-
#
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
display_current_situation_visual(doc, metrics)
|
63 |
|
64 |
except Exception as e:
|
65 |
logger.error(f"Error en análisis: {str(e)}")
|
66 |
st.error(t.get('analysis_error', "Error al analizar el texto"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
def display_recommendations(metrics, t):
|
69 |
"""
|
|
|
29 |
|
30 |
# Container principal con dos columnas
|
31 |
with st.container():
|
|
|
32 |
input_col, results_col = st.columns([1,2])
|
33 |
|
34 |
with input_col:
|
|
|
36 |
text_input = st.text_area(
|
37 |
t.get('input_prompt', "Escribe o pega tu texto aquí:"),
|
38 |
height=400,
|
39 |
+
key=f"initial_analysis_input_{st.session_state.get('analysis_count', 0)}", # Key dinámica
|
40 |
help="Este texto será analizado para darte recomendaciones personalizadas"
|
41 |
)
|
42 |
|
43 |
if st.button(
|
44 |
t.get('analyze_button', "Analizar mi escritura"),
|
45 |
type="primary",
|
46 |
+
disabled=not text_input.strip(), # Verificar que no esté vacío
|
47 |
+
use_container_width=True,
|
48 |
+
key=f"analyze_button_{st.session_state.get('analysis_count', 0)}" # Key dinámica
|
49 |
):
|
50 |
try:
|
51 |
with st.spinner(t.get('processing', "Analizando...")):
|
52 |
+
# Incrementar contador de análisis
|
53 |
+
if 'analysis_count' not in st.session_state:
|
54 |
+
st.session_state.analysis_count = 0
|
55 |
+
st.session_state.analysis_count += 1
|
56 |
+
|
57 |
# Procesar texto y obtener métricas
|
58 |
doc = nlp_models[lang_code](text_input)
|
59 |
metrics = analyze_text_dimensions(doc)
|
60 |
|
61 |
+
# Guardar resultados en el estado
|
62 |
+
st.session_state.current_doc = doc
|
63 |
+
st.session_state.current_metrics = metrics
|
64 |
+
|
65 |
+
# Forzar rerun para actualizar visualización
|
66 |
+
st.rerun()
|
|
|
67 |
|
68 |
except Exception as e:
|
69 |
logger.error(f"Error en análisis: {str(e)}")
|
70 |
st.error(t.get('analysis_error', "Error al analizar el texto"))
|
71 |
+
|
72 |
+
# Mostrar resultados si existen
|
73 |
+
with results_col:
|
74 |
+
if hasattr(st.session_state, 'current_metrics'):
|
75 |
+
display_recommendations(st.session_state.current_metrics, t)
|
76 |
+
|
77 |
+
# Opción para ver detalles
|
78 |
+
with st.expander("🔍 Ver análisis detallado", expanded=False):
|
79 |
+
display_current_situation_visual(
|
80 |
+
st.session_state.current_doc,
|
81 |
+
st.session_state.current_metrics
|
82 |
+
)
|
83 |
|
84 |
def display_recommendations(metrics, t):
|
85 |
"""
|