Spaces:
Running
Running
Update modules/studentact/student_activities_v2.py
Browse files
modules/studentact/student_activities_v2.py
CHANGED
|
@@ -552,7 +552,7 @@ def display_discourse_activities(username: str, t: dict):
|
|
| 552 |
for analysis in analyses:
|
| 553 |
try:
|
| 554 |
# Verificar campos mínimos necesarios
|
| 555 |
-
if not all(key in analysis for key in ['timestamp'
|
| 556 |
logger.warning(f"Análisis incompleto: {analysis.keys()}")
|
| 557 |
continue
|
| 558 |
|
|
@@ -561,91 +561,106 @@ def display_discourse_activities(username: str, t: dict):
|
|
| 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 |
-
#
|
| 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 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 605 |
else:
|
| 606 |
st.info(t.get('no_concepts', 'No hay conceptos disponibles'))
|
| 607 |
-
|
| 608 |
-
|
| 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 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 628 |
with col2:
|
| 629 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 630 |
if 'graph2' in analysis:
|
| 631 |
try:
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
""")
|
| 649 |
|
| 650 |
except Exception as e:
|
| 651 |
logger.error(f"Error procesando análisis individual: {str(e)}")
|
|
@@ -658,7 +673,6 @@ def display_discourse_activities(username: str, t: dict):
|
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
-
|
| 662 |
#################################################################################
|
| 663 |
|
| 664 |
def display_discourse_comparison(analysis: dict, t: dict):
|
|
|
|
| 552 |
for analysis in analyses:
|
| 553 |
try:
|
| 554 |
# Verificar campos mínimos necesarios
|
| 555 |
+
if not all(key in analysis for key in ['timestamp']):
|
| 556 |
logger.warning(f"Análisis incompleto: {analysis.keys()}")
|
| 557 |
continue
|
| 558 |
|
|
|
|
| 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 |
+
# Crear dos columnas para mostrar los documentos lado a lado
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 566 |
|
| 567 |
+
# Documento 1 - Columna izquierda
|
| 568 |
+
with col1:
|
| 569 |
+
st.subheader(t.get('doc1_title', 'Documento 1'))
|
| 570 |
+
st.markdown(t.get('key_concepts', 'Conceptos Clave'))
|
| 571 |
+
|
| 572 |
+
# Mostrar conceptos clave en formato de etiquetas
|
| 573 |
+
if 'key_concepts1' in analysis and analysis['key_concepts1']:
|
| 574 |
+
concepts_html = f"""
|
| 575 |
+
<div style="display: flex; flex-wrap: nowrap; gap: 8px; padding: 12px;
|
| 576 |
+
background-color: #f8f9fa; border-radius: 8px; overflow-x: auto;
|
| 577 |
+
margin-bottom: 15px; white-space: nowrap;">
|
| 578 |
+
{''.join([
|
| 579 |
+
f'<div style="background-color: white; border-radius: 4px; padding: 6px 10px; display: inline-flex; align-items: center; gap: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.1); flex-shrink: 0;">'
|
| 580 |
+
f'<span style="font-weight: 500; color: #1f2937; font-size: 0.85em;">{concept}</span>'
|
| 581 |
+
f'<span style="color: #6b7280; font-size: 0.75em;">({freq:.2f})</span></div>'
|
| 582 |
+
for concept, freq in analysis['key_concepts1']
|
| 583 |
+
])}
|
| 584 |
+
</div>
|
| 585 |
+
"""
|
| 586 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 587 |
else:
|
| 588 |
st.info(t.get('no_concepts', 'No hay conceptos disponibles'))
|
| 589 |
+
|
| 590 |
+
# Mostrar grafo 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
if 'graph1' in analysis:
|
| 592 |
try:
|
| 593 |
+
if isinstance(analysis['graph1'], bytes):
|
| 594 |
+
st.image(
|
| 595 |
+
analysis['graph1'],
|
| 596 |
+
use_container_width=True
|
| 597 |
+
)
|
| 598 |
+
else:
|
| 599 |
+
logger.warning(f"graph1 no es bytes: {type(analysis['graph1'])}")
|
| 600 |
+
st.warning(t.get('graph_not_available', 'Gráfico no disponible'))
|
| 601 |
+
except Exception as e:
|
| 602 |
+
logger.error(f"Error mostrando graph1: {str(e)}")
|
| 603 |
st.error(t.get('error_loading_graph', 'Error al cargar el gráfico'))
|
| 604 |
else:
|
| 605 |
st.info(t.get('no_visualization', 'No hay visualización disponible'))
|
| 606 |
+
|
| 607 |
+
# Interpretación del grafo
|
| 608 |
+
st.markdown("**📊 Interpretación del grafo:**")
|
| 609 |
+
st.markdown("""
|
| 610 |
+
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
| 611 |
+
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
| 612 |
+
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
| 613 |
+
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
| 614 |
+
""")
|
| 615 |
|
| 616 |
+
# Documento 2 - Columna derecha
|
| 617 |
with col2:
|
| 618 |
+
st.subheader(t.get('doc2_title', 'Documento 2'))
|
| 619 |
+
st.markdown(t.get('key_concepts', 'Conceptos Clave'))
|
| 620 |
+
|
| 621 |
+
# Mostrar conceptos clave en formato de etiquetas
|
| 622 |
+
if 'key_concepts2' in analysis and analysis['key_concepts2']:
|
| 623 |
+
concepts_html = f"""
|
| 624 |
+
<div style="display: flex; flex-wrap: nowrap; gap: 8px; padding: 12px;
|
| 625 |
+
background-color: #f8f9fa; border-radius: 8px; overflow-x: auto;
|
| 626 |
+
margin-bottom: 15px; white-space: nowrap;">
|
| 627 |
+
{''.join([
|
| 628 |
+
f'<div style="background-color: white; border-radius: 4px; padding: 6px 10px; display: inline-flex; align-items: center; gap: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.1); flex-shrink: 0;">'
|
| 629 |
+
f'<span style="font-weight: 500; color: #1f2937; font-size: 0.85em;">{concept}</span>'
|
| 630 |
+
f'<span style="color: #6b7280; font-size: 0.75em;">({freq:.2f})</span></div>'
|
| 631 |
+
for concept, freq in analysis['key_concepts2']
|
| 632 |
+
])}
|
| 633 |
+
</div>
|
| 634 |
+
"""
|
| 635 |
+
st.markdown(concepts_html, unsafe_allow_html=True)
|
| 636 |
+
else:
|
| 637 |
+
st.info(t.get('no_concepts', 'No hay conceptos disponibles'))
|
| 638 |
+
|
| 639 |
+
# Mostrar grafo 2
|
| 640 |
if 'graph2' in analysis:
|
| 641 |
try:
|
| 642 |
+
if isinstance(analysis['graph2'], bytes):
|
| 643 |
+
st.image(
|
| 644 |
+
analysis['graph2'],
|
| 645 |
+
use_container_width=True
|
| 646 |
+
)
|
| 647 |
+
else:
|
| 648 |
+
logger.warning(f"graph2 no es bytes: {type(analysis['graph2'])}")
|
| 649 |
+
st.warning(t.get('graph_not_available', 'Gráfico no disponible'))
|
| 650 |
+
except Exception as e:
|
| 651 |
+
logger.error(f"Error mostrando graph2: {str(e)}")
|
| 652 |
st.error(t.get('error_loading_graph', 'Error al cargar el gráfico'))
|
| 653 |
else:
|
| 654 |
st.info(t.get('no_visualization', 'No hay visualización disponible'))
|
| 655 |
+
|
| 656 |
+
# Interpretación del grafo
|
| 657 |
+
st.markdown("**📊 Interpretación del grafo:**")
|
| 658 |
+
st.markdown("""
|
| 659 |
+
- 🔀 Las flechas indican la dirección de la relación entre conceptos
|
| 660 |
+
- 🎨 Los colores más intensos indican conceptos más centrales en el texto
|
| 661 |
+
- ⭕ El tamaño de los nodos representa la frecuencia del concepto
|
| 662 |
+
- ↔️ El grosor de las líneas indica la fuerza de la conexión
|
| 663 |
+
""")
|
|
|
|
| 664 |
|
| 665 |
except Exception as e:
|
| 666 |
logger.error(f"Error procesando análisis individual: {str(e)}")
|
|
|
|
| 673 |
|
| 674 |
|
| 675 |
|
|
|
|
| 676 |
#################################################################################
|
| 677 |
|
| 678 |
def display_discourse_comparison(analysis: dict, t: dict):
|