Spaces:
Sleeping
Sleeping
Create urrent_situation_interface.py
Browse files
modules/studentact/urrent_situation_interface.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# modules/studentact/current_situation_interface.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import logging
|
| 5 |
+
from ..utils.widget_utils import generate_unique_key
|
| 6 |
+
|
| 7 |
+
logger = logging.getLogger(__name__)
|
| 8 |
+
|
| 9 |
+
def display_current_situation_interface(lang_code, nlp_models, t):
|
| 10 |
+
"""
|
| 11 |
+
Interfaz modular para el an谩lisis de la situaci贸n actual del estudiante.
|
| 12 |
+
Esta funci贸n maneja la presentaci贸n y la interacci贸n con el usuario.
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
lang_code: C贸digo del idioma actual
|
| 16 |
+
nlp_models: Diccionario de modelos de spaCy cargados
|
| 17 |
+
t: Diccionario de traducciones
|
| 18 |
+
"""
|
| 19 |
+
try:
|
| 20 |
+
st.markdown("## Mi Situaci贸n Actual de Escritura")
|
| 21 |
+
|
| 22 |
+
# Container principal para mejor organizaci贸n visual
|
| 23 |
+
with st.container():
|
| 24 |
+
# Columnas para entrada y visualizaci贸n
|
| 25 |
+
text_col, visual_col = st.columns([1,2])
|
| 26 |
+
|
| 27 |
+
with text_col:
|
| 28 |
+
# 脕rea de entrada de texto
|
| 29 |
+
text_input = st.text_area(
|
| 30 |
+
t.get('current_situation_input', "Ingresa tu texto para analizar:"),
|
| 31 |
+
height=400,
|
| 32 |
+
key=generate_unique_key("current_situation", "input")
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Bot贸n de an谩lisis
|
| 36 |
+
if st.button(
|
| 37 |
+
t.get('analyze_button', "Explorar mi escritura"),
|
| 38 |
+
type="primary",
|
| 39 |
+
disabled=not text_input,
|
| 40 |
+
key=generate_unique_key("current_situation", "analyze")
|
| 41 |
+
):
|
| 42 |
+
with st.spinner(t.get('processing', "Analizando texto...")):
|
| 43 |
+
try:
|
| 44 |
+
# 1. Procesar el texto
|
| 45 |
+
doc = nlp_models[lang_code](text_input)
|
| 46 |
+
metrics = analyze_text_dimensions(doc)
|
| 47 |
+
|
| 48 |
+
# 2. Mostrar visualizaciones en la columna derecha
|
| 49 |
+
with visual_col:
|
| 50 |
+
from .current_situation_analysis import display_current_situation_visual
|
| 51 |
+
display_current_situation_visual(doc, metrics)
|
| 52 |
+
|
| 53 |
+
# 3. Obtener retroalimentaci贸n de Claude
|
| 54 |
+
feedback = get_claude_feedback(metrics, text_input)
|
| 55 |
+
|
| 56 |
+
# 4. Guardar los resultados
|
| 57 |
+
from ..database.current_situation_mongo_db import store_current_situation_result
|
| 58 |
+
|
| 59 |
+
if store_current_situation_result(
|
| 60 |
+
st.session_state.username,
|
| 61 |
+
text_input,
|
| 62 |
+
metrics,
|
| 63 |
+
feedback
|
| 64 |
+
):
|
| 65 |
+
st.success(t.get('save_success', "An谩lisis guardado exitosamente"))
|
| 66 |
+
|
| 67 |
+
# 5. Mostrar recomendaciones
|
| 68 |
+
show_recommendations(feedback, t)
|
| 69 |
+
|
| 70 |
+
except Exception as e:
|
| 71 |
+
logger.error(f"Error en an谩lisis de situaci贸n actual: {str(e)}")
|
| 72 |
+
st.error(t.get('analysis_error', "Error al procesar el an谩lisis"))
|
| 73 |
+
|
| 74 |
+
def show_recommendations(feedback, t):
|
| 75 |
+
"""
|
| 76 |
+
Muestra las recomendaciones y ejercicios sugeridos.
|
| 77 |
+
"""
|
| 78 |
+
st.markdown("### " + t.get('recommendations_title', "Recomendaciones para mejorar"))
|
| 79 |
+
|
| 80 |
+
for area, exercises in feedback['recommendations'].items():
|
| 81 |
+
with st.expander(f"馃挕 {area}"):
|
| 82 |
+
st.markdown(exercises['description'])
|
| 83 |
+
st.markdown("**Ejercicio sugerido:**")
|
| 84 |
+
st.markdown(exercises['activity'])
|
| 85 |
+
|
| 86 |
+
# Bot贸n para marcar ejercicio como completado
|
| 87 |
+
if st.button(
|
| 88 |
+
t.get('mark_complete', "Marcar como completado"),
|
| 89 |
+
key=generate_unique_key("exercise", area)
|
| 90 |
+
):
|
| 91 |
+
update_exercise_status(
|
| 92 |
+
st.session_state.username,
|
| 93 |
+
area,
|
| 94 |
+
exercises['activity']
|
| 95 |
+
)
|