Update modules/ui.py
Browse files- modules/ui.py +67 -42
modules/ui.py
CHANGED
|
@@ -199,62 +199,76 @@ def display_student_progress(username, lang_code='es'):
|
|
| 199 |
st.title(f"Progreso de {username}")
|
| 200 |
|
| 201 |
if student_data['entries_count'] > 0:
|
|
|
|
| 202 |
if 'word_count' in student_data and student_data['word_count']:
|
| 203 |
-
st.
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
ha='center', va='bottom')
|
| 223 |
-
|
| 224 |
-
plt.tight_layout()
|
| 225 |
-
|
| 226 |
-
buf = io.BytesIO()
|
| 227 |
-
fig.savefig(buf, format='png')
|
| 228 |
-
buf.seek(0)
|
| 229 |
-
st.image(buf, use_column_width=True)
|
| 230 |
-
else:
|
| 231 |
-
st.info("No hay datos de conteo de palabras disponibles.")
|
| 232 |
|
| 233 |
-
|
| 234 |
-
with st.expander("
|
| 235 |
for i, entry in enumerate(student_data['entries']):
|
| 236 |
-
if '
|
| 237 |
-
st.subheader(f"
|
| 238 |
st.write(entry['arc_diagrams'][0], unsafe_allow_html=True)
|
| 239 |
|
| 240 |
-
|
| 241 |
-
with st.expander("
|
| 242 |
for i, entry in enumerate(student_data['entries']):
|
| 243 |
-
if '
|
| 244 |
-
st.subheader(f"
|
| 245 |
try:
|
| 246 |
image_bytes = base64.b64decode(entry['network_diagram'])
|
| 247 |
st.image(image_bytes)
|
| 248 |
except Exception as e:
|
| 249 |
st.error(f"Error al mostrar el diagrama de red: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
else:
|
| 251 |
st.warning("No se encontraron entradas para este estudiante.")
|
| 252 |
st.info("Intenta realizar algunos análisis de texto primero.")
|
| 253 |
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
##################################################################################################
|
| 259 |
def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
| 260 |
translations = {
|
|
@@ -478,7 +492,8 @@ def display_discourse_analysis_interface(nlp_models, lang_code):
|
|
| 478 |
st.pyplot(graph2)
|
| 479 |
|
| 480 |
# Guardar el resultado del análisis
|
| 481 |
-
if store_discourse_analysis_result(st.session_state.username, text_content1 + "\n\n" + text_content2, graph1, graph2):
|
|
|
|
| 482 |
st.success(t['success_message'])
|
| 483 |
else:
|
| 484 |
st.error(t['error_message'])
|
|
@@ -486,7 +501,17 @@ def display_discourse_analysis_interface(nlp_models, lang_code):
|
|
| 486 |
st.warning(t['warning_message'])
|
| 487 |
|
| 488 |
##################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
|
|
|
|
| 490 |
def display_chatbot_interface(lang_code):
|
| 491 |
translations = {
|
| 492 |
'es': {
|
|
|
|
| 199 |
st.title(f"Progreso de {username}")
|
| 200 |
|
| 201 |
if student_data['entries_count'] > 0:
|
| 202 |
+
# Mostrar el conteo de palabras
|
| 203 |
if 'word_count' in student_data and student_data['word_count']:
|
| 204 |
+
with st.expander("Total de palabras por categoría gramatical", expanded=False):
|
| 205 |
+
df = pd.DataFrame(list(student_data['word_count'].items()), columns=['category', 'count'])
|
| 206 |
+
df['label'] = df.apply(lambda x: f"{POS_TRANSLATIONS[lang_code].get(x['category'], x['category'])}", axis=1)
|
| 207 |
+
df = df.sort_values('count', ascending=False)
|
| 208 |
+
|
| 209 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
| 210 |
+
bars = ax.bar(df['label'], df['count'], color=[POS_COLORS.get(cat, '#CCCCCC') for cat in df['category']])
|
| 211 |
+
|
| 212 |
+
ax.set_xlabel('Categoría Gramatical')
|
| 213 |
+
ax.set_ylabel('Cantidad de Palabras')
|
| 214 |
+
ax.set_title('Total de palabras por categoría gramatical')
|
| 215 |
+
plt.xticks(rotation=45, ha='right')
|
| 216 |
+
|
| 217 |
+
for bar in bars:
|
| 218 |
+
height = bar.get_height()
|
| 219 |
+
ax.text(bar.get_x() + bar.get_width()/2., height, f'{height}', ha='center', va='bottom')
|
| 220 |
+
|
| 221 |
+
plt.tight_layout()
|
| 222 |
+
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
+
# Mostrar análisis morfosintáctico
|
| 225 |
+
with st.expander("Análisis Morfosintáctico - Diagramas de Arco", expanded=False):
|
| 226 |
for i, entry in enumerate(student_data['entries']):
|
| 227 |
+
if entry.get('analysis_type') == 'morphosyntax' and 'arc_diagrams' in entry:
|
| 228 |
+
st.subheader(f"Análisis {i+1} - {entry['timestamp']}")
|
| 229 |
st.write(entry['arc_diagrams'][0], unsafe_allow_html=True)
|
| 230 |
|
| 231 |
+
# Mostrar análisis semántico
|
| 232 |
+
with st.expander("Análisis Semántico - Diagramas de Red", expanded=False):
|
| 233 |
for i, entry in enumerate(student_data['entries']):
|
| 234 |
+
if entry.get('analysis_type') == 'semantic' and 'network_diagram' in entry:
|
| 235 |
+
st.subheader(f"Análisis {i+1} - {entry['timestamp']}")
|
| 236 |
try:
|
| 237 |
image_bytes = base64.b64decode(entry['network_diagram'])
|
| 238 |
st.image(image_bytes)
|
| 239 |
except Exception as e:
|
| 240 |
st.error(f"Error al mostrar el diagrama de red: {str(e)}")
|
| 241 |
+
|
| 242 |
+
# Mostrar análisis del discurso
|
| 243 |
+
with st.expander("Análisis del Discurso - Comparación de Grafos", expanded=False):
|
| 244 |
+
for i, entry in enumerate(student_data['entries']):
|
| 245 |
+
if entry.get('analysis_type') == 'discourse' and 'combined_graph' in entry:
|
| 246 |
+
st.subheader(f"Análisis {i+1} - {entry['timestamp']}")
|
| 247 |
+
try:
|
| 248 |
+
image_bytes = base64.b64decode(entry['combined_graph'])
|
| 249 |
+
st.image(image_bytes)
|
| 250 |
+
st.write("Texto del documento patrón:")
|
| 251 |
+
st.write(entry['text1'])
|
| 252 |
+
st.write("Texto del documento comparado:")
|
| 253 |
+
st.write(entry['text2'])
|
| 254 |
+
except Exception as e:
|
| 255 |
+
st.error(f"Error al mostrar el gráfico combinado: {str(e)}")
|
| 256 |
+
|
| 257 |
+
# Mostrar conversaciones del chat
|
| 258 |
+
if 'chat_history' in student_data and student_data['chat_history']:
|
| 259 |
+
with st.expander("Historial de Conversaciones del Chat", expanded=False):
|
| 260 |
+
for i, chat in enumerate(student_data['chat_history']):
|
| 261 |
+
st.subheader(f"Conversación {i+1} - {chat['timestamp']}")
|
| 262 |
+
for message in chat['messages']:
|
| 263 |
+
if message['role'] == 'user':
|
| 264 |
+
st.write("Usuario: " + message['content'])
|
| 265 |
+
else:
|
| 266 |
+
st.write("Asistente: " + message['content'])
|
| 267 |
+
st.write("---")
|
| 268 |
else:
|
| 269 |
st.warning("No se encontraron entradas para este estudiante.")
|
| 270 |
st.info("Intenta realizar algunos análisis de texto primero.")
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
##################################################################################################
|
| 273 |
def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
| 274 |
translations = {
|
|
|
|
| 492 |
st.pyplot(graph2)
|
| 493 |
|
| 494 |
# Guardar el resultado del análisis
|
| 495 |
+
#if store_discourse_analysis_result(st.session_state.username, text_content1 + "\n\n" + text_content2, graph1, graph2):
|
| 496 |
+
if store_discourse_analysis_result(st.session_state.username, text_content1, text_content2, graph1, graph2):
|
| 497 |
st.success(t['success_message'])
|
| 498 |
else:
|
| 499 |
st.error(t['error_message'])
|
|
|
|
| 501 |
st.warning(t['warning_message'])
|
| 502 |
|
| 503 |
##################################################################################################
|
| 504 |
+
#def display_saved_discourse_analysis(analysis_data):
|
| 505 |
+
# img_bytes = base64.b64decode(analysis_data['combined_graph'])
|
| 506 |
+
# img = plt.imread(io.BytesIO(img_bytes), format='png')
|
| 507 |
+
|
| 508 |
+
# st.image(img, use_column_width=True)
|
| 509 |
+
# st.write("Texto del documento patrón:")
|
| 510 |
+
# st.write(analysis_data['text1'])
|
| 511 |
+
# st.write("Texto del documento comparado:")
|
| 512 |
+
# st.write(analysis_data['text2'])
|
| 513 |
|
| 514 |
+
##################################################################################################
|
| 515 |
def display_chatbot_interface(lang_code):
|
| 516 |
translations = {
|
| 517 |
'es': {
|