Spaces:
Running
Running
Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
|
@@ -537,13 +537,14 @@ def display_semantic_activities(username: str, t: dict):
|
|
| 537 |
###################################################################################################
|
| 538 |
|
| 539 |
def display_discourse_activities(username: str, t: dict):
|
| 540 |
-
"""Muestra actividades de análisis del discurso"""
|
| 541 |
try:
|
| 542 |
logger.info(f"Recuperando análisis del discurso para {username}")
|
| 543 |
analyses = get_student_discourse_analysis(username)
|
| 544 |
|
| 545 |
if not analyses:
|
| 546 |
logger.info("No se encontraron análisis del discurso")
|
|
|
|
| 547 |
st.info(t.get('no_discourse_analyses', 'No hay análisis comparados de textos registrados'))
|
| 548 |
return
|
| 549 |
|
|
@@ -551,8 +552,8 @@ def display_discourse_activities(username: str, t: dict):
|
|
| 551 |
for analysis in analyses:
|
| 552 |
try:
|
| 553 |
# Verificar campos mínimos necesarios
|
| 554 |
-
if 'timestamp'
|
| 555 |
-
logger.warning(f"Análisis
|
| 556 |
continue
|
| 557 |
|
| 558 |
# Formatear fecha
|
|
@@ -560,63 +561,91 @@ def display_discourse_activities(username: str, t: dict):
|
|
| 560 |
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
|
| 561 |
|
| 562 |
with st.expander(f"{t.get('analysis_date', 'Fecha')}: {formatted_date}", expanded=False):
|
| 563 |
-
# Mostrar
|
| 564 |
-
if '
|
| 565 |
-
st.
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
|
| 583 |
-
|
| 584 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
|
| 586 |
-
#
|
| 587 |
-
|
| 588 |
-
has_graphs = False
|
| 589 |
|
| 590 |
-
|
| 591 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
try:
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
st.image(analysis['graph1'],
|
| 596 |
-
caption="Documento 1",
|
| 597 |
-
use_container_width=True) # Usar use_container_width en lugar de use_column_width
|
| 598 |
-
has_graphs = True
|
| 599 |
-
else:
|
| 600 |
-
logger.warning(f"graph1 no es bytes: {type(analysis['graph1'])}")
|
| 601 |
except Exception as img_error:
|
| 602 |
-
logger.error(f"Error
|
|
|
|
|
|
|
|
|
|
| 603 |
|
| 604 |
-
|
| 605 |
-
|
|
|
|
|
|
|
| 606 |
try:
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
st.image(analysis['graph2'],
|
| 610 |
-
caption="Documento 2",
|
| 611 |
-
use_container_width=True) # Usar use_container_width en lugar de use_column_width
|
| 612 |
-
has_graphs = True
|
| 613 |
-
else:
|
| 614 |
-
logger.warning(f"graph2 no es bytes: {type(analysis['graph2'])}")
|
| 615 |
except Exception as img_error:
|
| 616 |
-
logger.error(f"Error
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
|
| 618 |
-
|
| 619 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 620 |
|
| 621 |
except Exception as e:
|
| 622 |
logger.error(f"Error procesando análisis individual: {str(e)}")
|
|
@@ -624,8 +653,12 @@ def display_discourse_activities(username: str, t: dict):
|
|
| 624 |
|
| 625 |
except Exception as e:
|
| 626 |
logger.error(f"Error mostrando análisis del discurso: {str(e)}")
|
|
|
|
| 627 |
st.error(t.get('error_discourse', 'Error al mostrar análisis comparado de textos'))
|
| 628 |
|
|
|
|
|
|
|
|
|
|
| 629 |
#################################################################################
|
| 630 |
|
| 631 |
def display_discourse_comparison(analysis: dict, t: dict):
|
|
|
|
| 537 |
###################################################################################################
|
| 538 |
|
| 539 |
def display_discourse_activities(username: str, t: dict):
|
| 540 |
+
"""Muestra actividades de análisis del discurso (mostrado como 'Análisis comparado de textos' en la UI)"""
|
| 541 |
try:
|
| 542 |
logger.info(f"Recuperando análisis del discurso para {username}")
|
| 543 |
analyses = get_student_discourse_analysis(username)
|
| 544 |
|
| 545 |
if not analyses:
|
| 546 |
logger.info("No se encontraron análisis del discurso")
|
| 547 |
+
# Usamos el término "análisis comparado de textos" en la UI
|
| 548 |
st.info(t.get('no_discourse_analyses', 'No hay análisis comparados de textos registrados'))
|
| 549 |
return
|
| 550 |
|
|
|
|
| 552 |
for analysis in analyses:
|
| 553 |
try:
|
| 554 |
# Verificar campos mínimos necesarios
|
| 555 |
+
if not all(key in analysis for key in ['timestamp', 'graph1', 'graph2']):
|
| 556 |
+
logger.warning(f"Análisis incompleto: {analysis.keys()}")
|
| 557 |
continue
|
| 558 |
|
| 559 |
# Formatear fecha
|
|
|
|
| 561 |
formatted_date = timestamp.strftime("%d/%m/%Y %H:%M:%S")
|
| 562 |
|
| 563 |
with st.expander(f"{t.get('analysis_date', 'Fecha')}: {formatted_date}", expanded=False):
|
| 564 |
+
# Mostrar textos originales si están disponibles
|
| 565 |
+
if 'text1' in analysis and 'text2' in analysis:
|
| 566 |
+
st.subheader(t.get('analyzed_texts', 'Textos analizados'))
|
| 567 |
+
col1, col2 = st.columns(2)
|
| 568 |
+
with col1:
|
| 569 |
+
st.markdown(f"**{t.get('doc1_title', 'Documento 1')}**")
|
| 570 |
+
st.text_area(
|
| 571 |
+
"Text Content 1",
|
| 572 |
+
value=analysis['text1'],
|
| 573 |
+
height=100,
|
| 574 |
+
disabled=True,
|
| 575 |
+
label_visibility="collapsed",
|
| 576 |
+
key=f"text_area_1_{timestamp}"
|
| 577 |
+
)
|
| 578 |
+
with col2:
|
| 579 |
+
st.markdown(f"**{t.get('doc2_title', 'Documento 2')}**")
|
| 580 |
+
st.text_area(
|
| 581 |
+
"Text Content 2",
|
| 582 |
+
value=analysis['text2'],
|
| 583 |
+
height=100,
|
| 584 |
+
disabled=True,
|
| 585 |
+
label_visibility="collapsed",
|
| 586 |
+
key=f"text_area_2_{timestamp}"
|
| 587 |
+
)
|
| 588 |
+
|
| 589 |
+
# Mostrar conceptos clave
|
| 590 |
+
st.subheader(t.get('key_concepts', 'Conceptos clave'))
|
| 591 |
+
col1, col2 = st.columns(2)
|
| 592 |
+
with col1:
|
| 593 |
+
st.markdown(f"**{t.get('doc1_title', 'Documento 1')}**")
|
| 594 |
+
if 'key_concepts1' in analysis:
|
| 595 |
+
concepts1 = ", ".join([concept for concept, _ in analysis['key_concepts1']])
|
| 596 |
+
st.markdown(concepts1)
|
| 597 |
+
else:
|
| 598 |
+
st.info(t.get('no_concepts', 'No hay conceptos disponibles'))
|
| 599 |
|
| 600 |
+
with col2:
|
| 601 |
+
st.markdown(f"**{t.get('doc2_title', 'Documento 2')}**")
|
| 602 |
+
if 'key_concepts2' in analysis:
|
| 603 |
+
concepts2 = ", ".join([concept for concept, _ in analysis['key_concepts2']])
|
| 604 |
+
st.markdown(concepts2)
|
| 605 |
+
else:
|
| 606 |
+
st.info(t.get('no_concepts', 'No hay conceptos disponibles'))
|
| 607 |
|
| 608 |
+
# Mostrar visualizaciones
|
| 609 |
+
st.subheader(t.get('comparison_visualization', 'Visualización comparativa'))
|
|
|
|
| 610 |
|
| 611 |
+
# Mostrar los gráficos lado a lado
|
| 612 |
+
col1, col2 = st.columns(2)
|
| 613 |
+
|
| 614 |
+
# Gráfico 1
|
| 615 |
+
with col1:
|
| 616 |
+
st.markdown(f"**{t.get('analysis_doc1', 'Análisis del primer texto')}**")
|
| 617 |
+
if 'graph1' in analysis:
|
| 618 |
try:
|
| 619 |
+
image_bytes1 = base64.b64decode(analysis['graph1'])
|
| 620 |
+
st.image(image_bytes1, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
except Exception as img_error:
|
| 622 |
+
logger.error(f"Error decodificando imagen 1: {str(img_error)}")
|
| 623 |
+
st.error(t.get('error_loading_graph', 'Error al cargar el gráfico'))
|
| 624 |
+
else:
|
| 625 |
+
st.info(t.get('no_visualization', 'No hay visualización disponible'))
|
| 626 |
|
| 627 |
+
# Gráfico 2
|
| 628 |
+
with col2:
|
| 629 |
+
st.markdown(f"**{t.get('analysis_doc2', 'Análisis del segundo texto')}**")
|
| 630 |
+
if 'graph2' in analysis:
|
| 631 |
try:
|
| 632 |
+
image_bytes2 = base64.b64decode(analysis['graph2'])
|
| 633 |
+
st.image(image_bytes2, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
except Exception as img_error:
|
| 635 |
+
logger.error(f"Error decodificando imagen 2: {str(img_error)}")
|
| 636 |
+
st.error(t.get('error_loading_graph', 'Error al cargar el gráfico'))
|
| 637 |
+
else:
|
| 638 |
+
st.info(t.get('no_visualization', 'No hay visualización disponible'))
|
| 639 |
+
|
| 640 |
+
# Añadir leyenda de interpretación
|
| 641 |
+
st.markdown("### 📊 " + t.get('graph_interpretation', 'Interpretación del grafo:'))
|
| 642 |
|
| 643 |
+
st.markdown("""
|
| 644 |
+
* 🔀 Las flechas indican la dirección de la relación entre conceptos
|
| 645 |
+
* 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
| 646 |
+
* ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
| 647 |
+
* ↔️ El grosor de las líneas indica la fuerza de la conexión
|
| 648 |
+
""")
|
| 649 |
|
| 650 |
except Exception as e:
|
| 651 |
logger.error(f"Error procesando análisis individual: {str(e)}")
|
|
|
|
| 653 |
|
| 654 |
except Exception as e:
|
| 655 |
logger.error(f"Error mostrando análisis del discurso: {str(e)}")
|
| 656 |
+
# Usamos el término "análisis comparado de textos" en la UI
|
| 657 |
st.error(t.get('error_discourse', 'Error al mostrar análisis comparado de textos'))
|
| 658 |
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
|
| 662 |
#################################################################################
|
| 663 |
|
| 664 |
def display_discourse_comparison(analysis: dict, t: dict):
|