Update modules/ui.py
Browse files- modules/ui.py +133 -74
modules/ui.py
CHANGED
|
@@ -194,101 +194,160 @@ def display_chat_interface():
|
|
| 194 |
|
| 195 |
################################################################################
|
| 196 |
# Funciones para Cosmos DB MongoDB API (análisis de texto)
|
| 197 |
-
def display_student_progress(username, lang_code='es'):
|
| 198 |
-
logger.info(f"Intentando mostrar progreso para el usuario: {username}")
|
| 199 |
-
student_data = get_student_data(username)
|
| 200 |
|
| 201 |
-
if student_data is None:
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
|
| 207 |
-
logger.info(f"Datos recuperados para {username}: {student_data}")
|
| 208 |
|
| 209 |
-
st.title(f"Progreso de {username}")
|
| 210 |
|
| 211 |
-
if student_data['entries_count'] == 0:
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
|
| 216 |
# Mostrar el conteo de palabras
|
| 217 |
-
if student_data['word_count']:
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
|
| 235 |
-
|
| 236 |
-
|
| 237 |
|
| 238 |
# Mostrar análisis morfosintáctico
|
| 239 |
-
morphosyntax_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'morphosyntax']
|
| 240 |
-
if morphosyntax_entries:
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
|
| 249 |
# Mostrar análisis semántico
|
| 250 |
-
if student_data['semantic_analyses']:
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
|
| 259 |
# Mostrar análisis del discurso
|
| 260 |
-
if student_data['discourse_analyses']:
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
|
| 273 |
# Mostrar conversaciones del chat
|
| 274 |
-
if student_data['chat_history']:
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
else:
|
| 285 |
-
|
| 286 |
-
|
| 287 |
|
| 288 |
# Añadir logs para depuración
|
| 289 |
-
st.write("Datos del estudiante (para depuración):")
|
| 290 |
-
st.json(student_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
##################################################################################################
|
| 294 |
def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
|
|
| 194 |
|
| 195 |
################################################################################
|
| 196 |
# Funciones para Cosmos DB MongoDB API (análisis de texto)
|
| 197 |
+
#def display_student_progress(username, lang_code='es'):
|
| 198 |
+
#logger.info(f"Intentando mostrar progreso para el usuario: {username}")
|
| 199 |
+
#student_data = get_student_data(username)
|
| 200 |
|
| 201 |
+
#if student_data is None:
|
| 202 |
+
# logger.warning(f"No se pudieron recuperar datos para el usuario: {username}")
|
| 203 |
+
# st.warning("No se encontraron datos para este estudiante.")
|
| 204 |
+
# st.info("Intenta realizar algunos análisis de texto primero.")
|
| 205 |
+
# return
|
| 206 |
|
| 207 |
+
#logger.info(f"Datos recuperados para {username}: {student_data}")
|
| 208 |
|
| 209 |
+
#st.title(f"Progreso de {username}")
|
| 210 |
|
| 211 |
+
#if student_data['entries_count'] == 0:
|
| 212 |
+
# st.warning("No se encontraron entradas para este estudiante.")
|
| 213 |
+
# st.info("Intenta realizar algunos análisis de texto primero.")
|
| 214 |
+
# return
|
| 215 |
|
| 216 |
# Mostrar el conteo de palabras
|
| 217 |
+
#if student_data['word_count']:
|
| 218 |
+
# with st.expander("Total de palabras por categoría gramatical", expanded=False):
|
| 219 |
+
# df = pd.DataFrame(list(student_data['word_count'].items()), columns=['category', 'count'])
|
| 220 |
+
# df['label'] = df.apply(lambda x: f"{POS_TRANSLATIONS[lang_code].get(x['category'], x['category'])}", axis=1)
|
| 221 |
+
# df = df.sort_values('count', ascending=False)
|
| 222 |
|
| 223 |
+
# fig, ax = plt.subplots(figsize=(12, 6))
|
| 224 |
+
# bars = ax.bar(df['label'], df['count'], color=df['category'])
|
| 225 |
|
| 226 |
+
# ax.set_xlabel('Categoría Gramatical')
|
| 227 |
+
# ax.set_ylabel('Cantidad de Palabras')
|
| 228 |
+
# ax.set_title('Total de palabras por categoría gramatical')
|
| 229 |
+
# plt.xticks(rotation=45, ha='right')
|
| 230 |
|
| 231 |
+
# for bar in bars:
|
| 232 |
+
# height = bar.get_height()
|
| 233 |
+
# ax.text(bar.get_x() + bar.get_width()/2., height, f'{height}', ha='center', va='bottom')
|
| 234 |
|
| 235 |
+
# plt.tight_layout()
|
| 236 |
+
# st.pyplot(fig)
|
| 237 |
|
| 238 |
# Mostrar análisis morfosintáctico
|
| 239 |
+
#morphosyntax_entries = [entry for entry in student_data['entries'] if entry['analysis_type'] == 'morphosyntax']
|
| 240 |
+
#if morphosyntax_entries:
|
| 241 |
+
# with st.expander("Análisis Morfosintáctico - Diagramas de Arco", expanded=False):
|
| 242 |
+
# for i, entry in enumerate(morphosyntax_entries):
|
| 243 |
+
# st.subheader(f"Análisis {i+1} - {entry['timestamp']}")
|
| 244 |
+
# st.write(entry['text'])
|
| 245 |
+
# for j, diagram in enumerate(entry.get('arc_diagrams', [])):
|
| 246 |
+
# st.subheader(f"Diagrama de Arco {j+1}")
|
| 247 |
+
# st.write(diagram, unsafe_allow_html=True)
|
| 248 |
|
| 249 |
# Mostrar análisis semántico
|
| 250 |
+
#if student_data['semantic_analyses']:
|
| 251 |
+
# with st.expander("Análisis Semántico - Diagramas de Red", expanded=False):
|
| 252 |
+
# for i, entry in enumerate(student_data['semantic_analyses']):
|
| 253 |
+
# st.subheader(f"Análisis Semántico {i+1} - {entry['timestamp']}")
|
| 254 |
+
# st.write(entry['text'])
|
| 255 |
+
# if 'network_diagram' in entry:
|
| 256 |
+
# image_bytes = base64.b64decode(entry['network_diagram'])
|
| 257 |
+
# st.image(image_bytes)
|
| 258 |
|
| 259 |
# Mostrar análisis del discurso
|
| 260 |
+
#if student_data['discourse_analyses']:
|
| 261 |
+
# with st.expander("Análisis del Discurso - Comparación de Grafos", expanded=False):
|
| 262 |
+
# for i, entry in enumerate(student_data['discourse_analyses']):
|
| 263 |
+
# st.subheader(f"Análisis del Discurso {i+1} - {entry['timestamp']}")
|
| 264 |
+
# st.write("Texto del documento patrón:")
|
| 265 |
+
# st.write(entry.get('text1', 'No disponible'))
|
| 266 |
+
# st.write("Texto del documento comparado:")
|
| 267 |
+
# st.write(entry.get('text2', 'No disponible'))
|
| 268 |
+
# if 'graph1' in entry:
|
| 269 |
+
# st.image(base64.b64decode(entry['graph1']))
|
| 270 |
+
# if 'graph2' in entry:
|
| 271 |
+
# st.image(base64.b64decode(entry['graph2']))
|
| 272 |
|
| 273 |
# Mostrar conversaciones del chat
|
| 274 |
+
#if student_data['chat_history']:
|
| 275 |
+
# with st.expander("Historial de Conversaciones del Chat", expanded=False):
|
| 276 |
+
# for i, chat in enumerate(student_data['chat_history']):
|
| 277 |
+
# st.subheader(f"Conversación {i+1} - {chat['timestamp']}")
|
| 278 |
+
# for message in chat['messages']:
|
| 279 |
+
# if message['role'] == 'user':
|
| 280 |
+
# st.write("Usuario: " + message['content'])
|
| 281 |
+
# else:
|
| 282 |
+
# st.write("Asistente: " + message['content'])
|
| 283 |
+
# st.write("---")
|
| 284 |
+
#else:
|
| 285 |
+
# st.warning("No se encontraron entradas para este estudiante.")
|
| 286 |
+
# st.info("Intenta realizar algunos análisis de texto primero.")
|
| 287 |
|
| 288 |
# Añadir logs para depuración
|
| 289 |
+
#st.write("Datos del estudiante (para depuración):")
|
| 290 |
+
#st.json(student_data)
|
| 291 |
+
|
| 292 |
+
def display_student_progress(username, lang_code='es'):
|
| 293 |
+
student_data = get_student_data(username)
|
| 294 |
+
|
| 295 |
+
if student_data is None or len(student_data['entries']) == 0:
|
| 296 |
+
st.warning("No se encontraron datos para este estudiante.")
|
| 297 |
+
st.info("Intenta realizar algunos análisis de texto primero.")
|
| 298 |
+
return
|
| 299 |
+
|
| 300 |
+
st.title(f"Progreso de {username}")
|
| 301 |
+
|
| 302 |
+
# Mostrar resumen de actividades
|
| 303 |
+
st.header("Resumen de actividades")
|
| 304 |
+
total_entries = len(student_data['entries'])
|
| 305 |
+
st.write(f"Total de análisis realizados: {total_entries}")
|
| 306 |
|
| 307 |
+
# Mostrar gráfico de tipos de análisis
|
| 308 |
+
analysis_types = [entry['analysis_type'] for entry in student_data['entries']]
|
| 309 |
+
analysis_counts = pd.Series(analysis_types).value_counts()
|
| 310 |
+
|
| 311 |
+
fig, ax = plt.subplots()
|
| 312 |
+
analysis_counts.plot(kind='bar', ax=ax)
|
| 313 |
+
ax.set_title("Tipos de análisis realizados")
|
| 314 |
+
ax.set_xlabel("Tipo de análisis")
|
| 315 |
+
ax.set_ylabel("Cantidad")
|
| 316 |
+
st.pyplot(fig)
|
| 317 |
+
|
| 318 |
+
# Mostrar últimos análisis
|
| 319 |
+
st.header("Últimos análisis realizados")
|
| 320 |
+
for i, entry in enumerate(student_data['entries'][:5]): # Mostrar los últimos 5 análisis
|
| 321 |
+
with st.expander(f"Análisis {i+1} - {entry['timestamp']}"):
|
| 322 |
+
st.write(f"Tipo: {entry['analysis_type']}")
|
| 323 |
+
st.write(f"Texto: {entry['text']}")
|
| 324 |
+
|
| 325 |
+
if entry['analysis_type'] == 'morphosyntax':
|
| 326 |
+
if entry['word_count']:
|
| 327 |
+
st.subheader("Conteo de palabras por categoría")
|
| 328 |
+
word_count_df = pd.DataFrame.from_dict(entry['word_count'], orient='index', columns=['Cantidad'])
|
| 329 |
+
st.dataframe(word_count_df)
|
| 330 |
+
|
| 331 |
+
if entry['arc_diagrams']:
|
| 332 |
+
st.subheader("Diagrama de arco")
|
| 333 |
+
st.write(entry['arc_diagrams'][0], unsafe_allow_html=True)
|
| 334 |
+
|
| 335 |
+
# Mostrar progreso a lo largo del tiempo
|
| 336 |
+
st.header("Progreso a lo largo del tiempo")
|
| 337 |
+
dates = [datetime.fromisoformat(entry['timestamp']) for entry in student_data['entries']]
|
| 338 |
+
analysis_counts = pd.Series(dates).value_counts().sort_index()
|
| 339 |
+
|
| 340 |
+
fig, ax = plt.subplots()
|
| 341 |
+
analysis_counts.plot(kind='line', ax=ax)
|
| 342 |
+
ax.set_title("Análisis realizados a lo largo del tiempo")
|
| 343 |
+
ax.set_xlabel("Fecha")
|
| 344 |
+
ax.set_ylabel("Cantidad de análisis")
|
| 345 |
+
st.pyplot(fig)
|
| 346 |
+
|
| 347 |
+
# Añadir logs para depuración
|
| 348 |
+
if st.checkbox("Mostrar datos de depuración"):
|
| 349 |
+
st.write("Datos del estudiante (para depuración):")
|
| 350 |
+
st.json(student_data)
|
| 351 |
|
| 352 |
##################################################################################################
|
| 353 |
def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|