Update modules/studentact/current_situation_interface.py
Browse files
modules/studentact/current_situation_interface.py
CHANGED
@@ -22,6 +22,81 @@ from .current_situation_analysis import (
|
|
22 |
|
23 |
logger = logging.getLogger(__name__)
|
24 |
####################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def display_current_situation_visual(doc, metrics):
|
26 |
"""
|
27 |
Muestra visualizaciones detalladas del análisis.
|
|
|
22 |
|
23 |
logger = logging.getLogger(__name__)
|
24 |
####################################
|
25 |
+
def display_current_situation_interface(lang_code, nlp_models, t):
|
26 |
+
"""
|
27 |
+
Interfaz simplificada para el análisis inicial, enfocada en recomendaciones directas.
|
28 |
+
"""
|
29 |
+
# Inicializar estados si no existen
|
30 |
+
if 'text_input' not in st.session_state:
|
31 |
+
st.session_state.text_input = ""
|
32 |
+
if 'show_results' not in st.session_state:
|
33 |
+
st.session_state.show_results = False
|
34 |
+
if 'current_doc' not in st.session_state:
|
35 |
+
st.session_state.current_doc = None
|
36 |
+
if 'current_metrics' not in st.session_state:
|
37 |
+
st.session_state.current_metrics = None
|
38 |
+
|
39 |
+
st.markdown("## Análisis Inicial de Escritura")
|
40 |
+
|
41 |
+
# Container principal con dos columnas
|
42 |
+
with st.container():
|
43 |
+
input_col, results_col = st.columns([1,2])
|
44 |
+
|
45 |
+
with input_col:
|
46 |
+
st.markdown("### Ingresa tu texto")
|
47 |
+
|
48 |
+
# Función para manejar cambios en el texto
|
49 |
+
def on_text_change():
|
50 |
+
st.session_state.text_input = st.session_state.text_area
|
51 |
+
st.session_state.show_results = False # Resetear resultados cuando el texto cambia
|
52 |
+
|
53 |
+
# Text area con manejo de estado
|
54 |
+
text_input = st.text_area(
|
55 |
+
t.get('input_prompt', "Escribe o pega tu texto aquí:"),
|
56 |
+
height=400,
|
57 |
+
key="text_area",
|
58 |
+
value=st.session_state.text_input,
|
59 |
+
on_change=on_text_change,
|
60 |
+
help="Este texto será analizado para darte recomendaciones personalizadas"
|
61 |
+
)
|
62 |
+
|
63 |
+
# Botón de análisis
|
64 |
+
if st.button(
|
65 |
+
t.get('analyze_button', "Analizar mi escritura"),
|
66 |
+
type="primary",
|
67 |
+
disabled=not text_input.strip(),
|
68 |
+
use_container_width=True,
|
69 |
+
):
|
70 |
+
try:
|
71 |
+
with st.spinner(t.get('processing', "Analizando...")):
|
72 |
+
# Procesar texto y obtener métricas
|
73 |
+
doc = nlp_models[lang_code](text_input)
|
74 |
+
metrics = analyze_text_dimensions(doc)
|
75 |
+
|
76 |
+
# Actualizar estado con nuevos resultados
|
77 |
+
st.session_state.current_doc = doc
|
78 |
+
st.session_state.current_metrics = metrics
|
79 |
+
st.session_state.show_results = True
|
80 |
+
|
81 |
+
# Mantener el texto en el estado
|
82 |
+
st.session_state.text_input = text_input
|
83 |
+
|
84 |
+
except Exception as e:
|
85 |
+
logger.error(f"Error en análisis: {str(e)}")
|
86 |
+
st.error(t.get('analysis_error', "Error al analizar el texto"))
|
87 |
+
|
88 |
+
# Mostrar resultados en la columna derecha
|
89 |
+
with results_col:
|
90 |
+
if st.session_state.show_results and st.session_state.current_metrics is not None:
|
91 |
+
display_recommendations(st.session_state.current_metrics, t)
|
92 |
+
|
93 |
+
# Opción para ver detalles
|
94 |
+
with st.expander("🔍 Ver análisis detallado", expanded=False):
|
95 |
+
display_current_situation_visual(
|
96 |
+
st.session_state.current_doc,
|
97 |
+
st.session_state.current_metrics
|
98 |
+
)
|
99 |
+
|
100 |
def display_current_situation_visual(doc, metrics):
|
101 |
"""
|
102 |
Muestra visualizaciones detalladas del análisis.
|