Update modules/ui.py
Browse files- modules/ui.py +52 -8
modules/ui.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
import streamlit as st
|
3 |
import re
|
4 |
import io
|
|
|
5 |
import base64
|
6 |
import matplotlib.pyplot as plt
|
7 |
import pandas as pd
|
@@ -335,12 +336,19 @@ def display_student_progress(username, lang_code='es'):
|
|
335 |
st.write(entry['arc_diagrams'][0], unsafe_allow_html=True)
|
336 |
|
337 |
with st.expander("Hist贸rico de An谩lisis Sem谩nticos"):
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
|
345 |
with st.expander("Hist贸rico de An谩lisis Discursivos"):
|
346 |
discourse_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'discourse']
|
@@ -348,8 +356,44 @@ def display_student_progress(username, lang_code='es'):
|
|
348 |
st.subheader(f"An谩lisis del {entry['timestamp']}")
|
349 |
st.write(f"Archivo patr贸n: {entry.get('filename1', 'Nombre no disponible')}")
|
350 |
st.write(f"Archivo comparado: {entry.get('filename2', 'Nombre no disponible')}")
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
|
354 |
with st.expander("Hist贸rico de Conversaciones con el ChatBot"):
|
355 |
if 'chat_history' in student_data:
|
|
|
2 |
import streamlit as st
|
3 |
import re
|
4 |
import io
|
5 |
+
from io import BytesIO
|
6 |
import base64
|
7 |
import matplotlib.pyplot as plt
|
8 |
import pandas as pd
|
|
|
336 |
st.write(entry['arc_diagrams'][0], unsafe_allow_html=True)
|
337 |
|
338 |
with st.expander("Hist贸rico de An谩lisis Sem谩nticos"):
|
339 |
+
semantic_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'semantic']
|
340 |
+
for entry in semantic_entries:
|
341 |
+
st.subheader(f"An谩lisis del {entry['timestamp']}")
|
342 |
+
st.write(f"Archivo analizado: {entry.get('filename', 'Nombre no disponible')}")
|
343 |
+
if 'network_diagram' in entry:
|
344 |
+
try:
|
345 |
+
# Intentar decodificar la imagen si est谩 en formato base64
|
346 |
+
image_bytes = base64.b64decode(entry['network_diagram'])
|
347 |
+
st.image(image_bytes)
|
348 |
+
except Exception as e:
|
349 |
+
st.error(f"No se pudo mostrar la imagen: {str(e)}")
|
350 |
+
st.write("Datos de la imagen (para depuraci贸n):")
|
351 |
+
st.write(entry['network_diagram'][:100] + "...") #
|
352 |
|
353 |
with st.expander("Hist贸rico de An谩lisis Discursivos"):
|
354 |
discourse_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'discourse']
|
|
|
356 |
st.subheader(f"An谩lisis del {entry['timestamp']}")
|
357 |
st.write(f"Archivo patr贸n: {entry.get('filename1', 'Nombre no disponible')}")
|
358 |
st.write(f"Archivo comparado: {entry.get('filename2', 'Nombre no disponible')}")
|
359 |
+
|
360 |
+
try:
|
361 |
+
# Intentar obtener y combinar las dos im谩genes
|
362 |
+
if 'graph1' in entry and 'graph2' in entry:
|
363 |
+
img1 = Image.open(BytesIO(base64.b64decode(entry['graph1'])))
|
364 |
+
img2 = Image.open(BytesIO(base64.b64decode(entry['graph2'])))
|
365 |
+
|
366 |
+
# Crear una nueva imagen combinada
|
367 |
+
total_width = img1.width + img2.width
|
368 |
+
max_height = max(img1.height, img2.height)
|
369 |
+
combined_img = Image.new('RGB', (total_width, max_height))
|
370 |
+
|
371 |
+
# Pegar las dos im谩genes lado a lado
|
372 |
+
combined_img.paste(img1, (0, 0))
|
373 |
+
combined_img.paste(img2, (img1.width, 0))
|
374 |
+
|
375 |
+
# Convertir la imagen combinada a bytes
|
376 |
+
buffered = BytesIO()
|
377 |
+
combined_img.save(buffered, format="PNG")
|
378 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
379 |
+
|
380 |
+
# Mostrar la imagen combinada
|
381 |
+
st.image(f"data:image/png;base64,{img_str}")
|
382 |
+
elif 'combined_graph' in entry:
|
383 |
+
# Si ya existe una imagen combinada, mostrarla directamente
|
384 |
+
img_bytes = base64.b64decode(entry['combined_graph'])
|
385 |
+
st.image(img_bytes)
|
386 |
+
else:
|
387 |
+
st.write("No se encontraron gr谩ficos para este an谩lisis.")
|
388 |
+
except Exception as e:
|
389 |
+
st.error(f"No se pudieron mostrar los gr谩ficos: {str(e)}")
|
390 |
+
st.write("Datos de los gr谩ficos (para depuraci贸n):")
|
391 |
+
if 'graph1' in entry:
|
392 |
+
st.write("Graph 1:", entry['graph1'][:100] + "...")
|
393 |
+
if 'graph2' in entry:
|
394 |
+
st.write("Graph 2:", entry['graph2'][:100] + "...")
|
395 |
+
if 'combined_graph' in entry:
|
396 |
+
st.write("Combined Graph:", entry['combined_graph'][:100] + "...")
|
397 |
|
398 |
with st.expander("Hist贸rico de Conversaciones con el ChatBot"):
|
399 |
if 'chat_history' in student_data:
|