Update modules/ui.py
Browse files- modules/ui.py +147 -38
modules/ui.py
CHANGED
|
@@ -12,7 +12,16 @@ from spacy import displacy
|
|
| 12 |
#Importaciones locales
|
| 13 |
#Importaciones locales de autenticación y base de datos
|
| 14 |
from .auth import authenticate_user, register_user
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
#Importaciones locales de uiadmin
|
| 18 |
from .admin_ui import admin_page
|
|
@@ -257,7 +266,10 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 257 |
'repeated_words': "Palabras repetidas",
|
| 258 |
'legend': "Leyenda: Categorías gramaticales",
|
| 259 |
'arc_diagram': "Análisis sintáctico: Diagrama de arco",
|
| 260 |
-
'sentence': "Oración"
|
|
|
|
|
|
|
|
|
|
| 261 |
},
|
| 262 |
'en': {
|
| 263 |
'title': "AIdeaText - Morphological and Syntactic Analysis",
|
|
@@ -267,7 +279,10 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 267 |
'repeated_words': "Repeated words",
|
| 268 |
'legend': "Legend: Grammatical categories",
|
| 269 |
'arc_diagram': "Syntactic analysis: Arc diagram",
|
| 270 |
-
'sentence': "Sentence"
|
|
|
|
|
|
|
|
|
|
| 271 |
},
|
| 272 |
'fr': {
|
| 273 |
'title': "AIdeaText - Analyse morphologique et syntaxique",
|
|
@@ -277,7 +292,10 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 277 |
'repeated_words': "Mots répétés",
|
| 278 |
'legend': "Légende : Catégories grammaticales",
|
| 279 |
'arc_diagram': "Analyse syntaxique : Diagramme en arc",
|
| 280 |
-
'sentence': "Phrase"
|
|
|
|
|
|
|
|
|
|
| 281 |
}
|
| 282 |
}
|
| 283 |
|
|
@@ -285,21 +303,16 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 285 |
|
| 286 |
input_key = f"morphosyntax_input_{lang_code}"
|
| 287 |
|
| 288 |
-
# Inicializar la clave en session_state si no existe
|
| 289 |
if input_key not in st.session_state:
|
| 290 |
st.session_state[input_key] = ""
|
| 291 |
|
| 292 |
-
# Función para actualizar el estado del input
|
| 293 |
-
def update_input():
|
| 294 |
-
st.session_state[input_key] = st.session_state[f"text_area_{lang_code}"]
|
| 295 |
-
|
| 296 |
sentence_input = st.text_area(
|
| 297 |
t['input_label'],
|
| 298 |
height=150,
|
| 299 |
placeholder=t['input_placeholder'],
|
| 300 |
value=st.session_state[input_key],
|
| 301 |
key=f"text_area_{lang_code}",
|
| 302 |
-
on_change=
|
| 303 |
)
|
| 304 |
|
| 305 |
if st.button(t['analyze_button'], key=f"analyze_button_{lang_code}"):
|
|
@@ -339,11 +352,11 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 339 |
word_colors,
|
| 340 |
arc_diagrams,
|
| 341 |
):
|
| 342 |
-
st.success(
|
| 343 |
else:
|
| 344 |
-
st.error(
|
| 345 |
else:
|
| 346 |
-
st.warning(
|
| 347 |
|
| 348 |
###############################################################################################################
|
| 349 |
def display_semantic_analysis_interface(nlp_models, lang_code):
|
|
@@ -351,93 +364,189 @@ def display_semantic_analysis_interface(nlp_models, lang_code):
|
|
| 351 |
'es': {
|
| 352 |
'title': "AIdeaText - Análisis semántico",
|
| 353 |
'file_uploader': "Cargar archivo de texto",
|
|
|
|
| 354 |
'analyze_button': "Analizar texto",
|
| 355 |
'semantic_relations': "Relaciones Semánticas Relevantes",
|
|
|
|
|
|
|
|
|
|
| 356 |
},
|
| 357 |
'en': {
|
| 358 |
'title': "AIdeaText - Semantic Analysis",
|
| 359 |
'file_uploader': "Upload text file",
|
|
|
|
| 360 |
'analyze_button': "Analyze text",
|
| 361 |
'semantic_relations': "Relevant Semantic Relations",
|
|
|
|
|
|
|
|
|
|
| 362 |
},
|
| 363 |
'fr': {
|
| 364 |
'title': "AIdeaText - Analyse sémantique",
|
| 365 |
'file_uploader': "Télécharger le fichier texte",
|
|
|
|
| 366 |
'analyze_button': "Analyser le texte",
|
| 367 |
'semantic_relations': "Relations Sémantiques Pertinentes",
|
|
|
|
|
|
|
|
|
|
| 368 |
}
|
| 369 |
}
|
| 370 |
|
| 371 |
t = translations[lang_code]
|
| 372 |
-
|
| 373 |
st.header(t['title'])
|
| 374 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
uploaded_file = st.file_uploader(t['file_uploader'], type=['txt'])
|
| 376 |
|
| 377 |
-
|
| 378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
-
|
| 381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
|
| 383 |
-
|
| 384 |
-
|
| 385 |
|
| 386 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
def display_discourse_analysis_interface(nlp_models, lang_code):
|
| 389 |
translations = {
|
| 390 |
'es': {
|
| 391 |
'title': "AIdeaText - Análisis del discurso",
|
| 392 |
'file_uploader1': "Cargar archivo de texto 1 (Patrón)",
|
| 393 |
'file_uploader2': "Cargar archivo de texto 2 (Comparación)",
|
|
|
|
|
|
|
| 394 |
'analyze_button': "Analizar textos",
|
| 395 |
'comparison': "Comparación de Relaciones Semánticas",
|
|
|
|
|
|
|
|
|
|
| 396 |
},
|
| 397 |
'en': {
|
| 398 |
'title': "AIdeaText - Discourse Analysis",
|
| 399 |
'file_uploader1': "Upload text file 1 (Pattern)",
|
| 400 |
'file_uploader2': "Upload text file 2 (Comparison)",
|
|
|
|
|
|
|
| 401 |
'analyze_button': "Analyze texts",
|
| 402 |
'comparison': "Comparison of Semantic Relations",
|
|
|
|
|
|
|
|
|
|
| 403 |
},
|
| 404 |
'fr': {
|
| 405 |
'title': "AIdeaText - Analyse du discours",
|
| 406 |
'file_uploader1': "Télécharger le fichier texte 1 (Modèle)",
|
| 407 |
'file_uploader2': "Télécharger le fichier texte 2 (Comparaison)",
|
|
|
|
|
|
|
| 408 |
'analyze_button': "Analyser les textes",
|
| 409 |
'comparison': "Comparaison des Relations Sémantiques",
|
|
|
|
|
|
|
|
|
|
| 410 |
}
|
| 411 |
}
|
| 412 |
|
| 413 |
t = translations[lang_code]
|
| 414 |
-
|
| 415 |
st.header(t['title'])
|
| 416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
col1, col2 = st.columns(2)
|
| 418 |
|
| 419 |
with col1:
|
| 420 |
uploaded_file1 = st.file_uploader(t['file_uploader1'], type=['txt'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
|
| 422 |
with col2:
|
| 423 |
uploaded_file2 = st.file_uploader(t['file_uploader2'], type=['txt'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
|
| 442 |
##################################################################################################
|
| 443 |
|
|
|
|
| 12 |
#Importaciones locales
|
| 13 |
#Importaciones locales de autenticación y base de datos
|
| 14 |
from .auth import authenticate_user, register_user
|
| 15 |
+
|
| 16 |
+
from .database import (
|
| 17 |
+
get_student_data,
|
| 18 |
+
store_morphosyntax_result,
|
| 19 |
+
store_semantic_result,
|
| 20 |
+
store_discourse_analysis_result,
|
| 21 |
+
store_chat_history,
|
| 22 |
+
create_admin_user,
|
| 23 |
+
create_student_user
|
| 24 |
+
)
|
| 25 |
|
| 26 |
#Importaciones locales de uiadmin
|
| 27 |
from .admin_ui import admin_page
|
|
|
|
| 266 |
'repeated_words': "Palabras repetidas",
|
| 267 |
'legend': "Leyenda: Categorías gramaticales",
|
| 268 |
'arc_diagram': "Análisis sintáctico: Diagrama de arco",
|
| 269 |
+
'sentence': "Oración",
|
| 270 |
+
'success_message': "Análisis guardado correctamente.",
|
| 271 |
+
'error_message': "Hubo un problema al guardar el análisis. Por favor, inténtelo de nuevo.",
|
| 272 |
+
'warning_message': "Por favor, ingrese un texto para analizar."
|
| 273 |
},
|
| 274 |
'en': {
|
| 275 |
'title': "AIdeaText - Morphological and Syntactic Analysis",
|
|
|
|
| 279 |
'repeated_words': "Repeated words",
|
| 280 |
'legend': "Legend: Grammatical categories",
|
| 281 |
'arc_diagram': "Syntactic analysis: Arc diagram",
|
| 282 |
+
'sentence': "Sentence",
|
| 283 |
+
'success_message': "Analysis saved successfully.",
|
| 284 |
+
'error_message': "There was a problem saving the analysis. Please try again.",
|
| 285 |
+
'warning_message': "Please enter a text to analyze."
|
| 286 |
},
|
| 287 |
'fr': {
|
| 288 |
'title': "AIdeaText - Analyse morphologique et syntaxique",
|
|
|
|
| 292 |
'repeated_words': "Mots répétés",
|
| 293 |
'legend': "Légende : Catégories grammaticales",
|
| 294 |
'arc_diagram': "Analyse syntaxique : Diagramme en arc",
|
| 295 |
+
'sentence': "Phrase",
|
| 296 |
+
'success_message': "Analyse enregistrée avec succès.",
|
| 297 |
+
'error_message': "Un problème est survenu lors de l'enregistrement de l'analyse. Veuillez réessayer.",
|
| 298 |
+
'warning_message': "Veuillez entrer un texte à analyser."
|
| 299 |
}
|
| 300 |
}
|
| 301 |
|
|
|
|
| 303 |
|
| 304 |
input_key = f"morphosyntax_input_{lang_code}"
|
| 305 |
|
|
|
|
| 306 |
if input_key not in st.session_state:
|
| 307 |
st.session_state[input_key] = ""
|
| 308 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
sentence_input = st.text_area(
|
| 310 |
t['input_label'],
|
| 311 |
height=150,
|
| 312 |
placeholder=t['input_placeholder'],
|
| 313 |
value=st.session_state[input_key],
|
| 314 |
key=f"text_area_{lang_code}",
|
| 315 |
+
on_change=lambda: setattr(st.session_state, input_key, st.session_state[f"text_area_{lang_code}"])
|
| 316 |
)
|
| 317 |
|
| 318 |
if st.button(t['analyze_button'], key=f"analyze_button_{lang_code}"):
|
|
|
|
| 352 |
word_colors,
|
| 353 |
arc_diagrams,
|
| 354 |
):
|
| 355 |
+
st.success(t['success_message'])
|
| 356 |
else:
|
| 357 |
+
st.error(t['error_message'])
|
| 358 |
else:
|
| 359 |
+
st.warning(t['warning_message'])
|
| 360 |
|
| 361 |
###############################################################################################################
|
| 362 |
def display_semantic_analysis_interface(nlp_models, lang_code):
|
|
|
|
| 364 |
'es': {
|
| 365 |
'title': "AIdeaText - Análisis semántico",
|
| 366 |
'file_uploader': "Cargar archivo de texto",
|
| 367 |
+
'input_label': "O ingrese el texto aquí:",
|
| 368 |
'analyze_button': "Analizar texto",
|
| 369 |
'semantic_relations': "Relaciones Semánticas Relevantes",
|
| 370 |
+
'success_message': "Análisis semántico guardado correctamente.",
|
| 371 |
+
'error_message': "Hubo un problema al guardar el análisis semántico. Por favor, inténtelo de nuevo.",
|
| 372 |
+
'warning_message': "Por favor, ingrese un texto o cargue un archivo para analizar."
|
| 373 |
},
|
| 374 |
'en': {
|
| 375 |
'title': "AIdeaText - Semantic Analysis",
|
| 376 |
'file_uploader': "Upload text file",
|
| 377 |
+
'input_label': "Or enter the text here:",
|
| 378 |
'analyze_button': "Analyze text",
|
| 379 |
'semantic_relations': "Relevant Semantic Relations",
|
| 380 |
+
'success_message': "Semantic analysis saved successfully.",
|
| 381 |
+
'error_message': "There was a problem saving the semantic analysis. Please try again.",
|
| 382 |
+
'warning_message': "Please enter a text or upload a file to analyze."
|
| 383 |
},
|
| 384 |
'fr': {
|
| 385 |
'title': "AIdeaText - Analyse sémantique",
|
| 386 |
'file_uploader': "Télécharger le fichier texte",
|
| 387 |
+
'input_label': "Ou entrez le texte ici :",
|
| 388 |
'analyze_button': "Analyser le texte",
|
| 389 |
'semantic_relations': "Relations Sémantiques Pertinentes",
|
| 390 |
+
'success_message': "Analyse sémantique enregistrée avec succès.",
|
| 391 |
+
'error_message': "Un problème est survenu lors de l'enregistrement de l'analyse sémantique. Veuillez réessayer.",
|
| 392 |
+
'warning_message': "Veuillez entrer un texte ou télécharger un fichier à analyser."
|
| 393 |
}
|
| 394 |
}
|
| 395 |
|
| 396 |
t = translations[lang_code]
|
|
|
|
| 397 |
st.header(t['title'])
|
| 398 |
|
| 399 |
+
# Inicializar el estado de la sesión para el texto semántico
|
| 400 |
+
if 'semantic_text' not in st.session_state:
|
| 401 |
+
st.session_state.semantic_text = ""
|
| 402 |
+
|
| 403 |
+
# Opción para cargar archivo
|
| 404 |
uploaded_file = st.file_uploader(t['file_uploader'], type=['txt'])
|
| 405 |
|
| 406 |
+
# Opción para ingresar texto directamente
|
| 407 |
+
text_input = st.text_area(
|
| 408 |
+
t['input_label'],
|
| 409 |
+
value=st.session_state.semantic_text,
|
| 410 |
+
height=300,
|
| 411 |
+
key="semantic_text_input"
|
| 412 |
+
)
|
| 413 |
|
| 414 |
+
if st.button(t['analyze_button']):
|
| 415 |
+
# Priorizar el archivo cargado sobre el texto ingresado
|
| 416 |
+
if uploaded_file is not None:
|
| 417 |
+
text_content = uploaded_file.getvalue().decode('utf-8')
|
| 418 |
+
elif text_input:
|
| 419 |
+
text_content = text_input
|
| 420 |
+
else:
|
| 421 |
+
st.warning(t['warning_message'])
|
| 422 |
+
return
|
| 423 |
|
| 424 |
+
# Guardar el texto en el estado de la sesión
|
| 425 |
+
st.session_state.semantic_text = text_content
|
| 426 |
|
| 427 |
+
# Realizar el análisis
|
| 428 |
+
relations_graph = perform_semantic_analysis(text_content, nlp_models[lang_code], lang_code)
|
| 429 |
+
|
| 430 |
+
# Mostrar el gráfico de relaciones semánticas
|
| 431 |
+
with st.expander(t['semantic_relations'], expanded=True):
|
| 432 |
+
st.pyplot(relations_graph)
|
| 433 |
|
| 434 |
+
# Guardar el resultado del análisis
|
| 435 |
+
if store_semantic_result(st.session_state.username, text_content, relations_graph):
|
| 436 |
+
st.success(t['success_message'])
|
| 437 |
+
else:
|
| 438 |
+
st.error(t['error_message'])
|
| 439 |
+
|
| 440 |
+
##################################################################################################
|
| 441 |
def display_discourse_analysis_interface(nlp_models, lang_code):
|
| 442 |
translations = {
|
| 443 |
'es': {
|
| 444 |
'title': "AIdeaText - Análisis del discurso",
|
| 445 |
'file_uploader1': "Cargar archivo de texto 1 (Patrón)",
|
| 446 |
'file_uploader2': "Cargar archivo de texto 2 (Comparación)",
|
| 447 |
+
'input_label1': "O ingrese el texto 1 aquí:",
|
| 448 |
+
'input_label2': "O ingrese el texto 2 aquí:",
|
| 449 |
'analyze_button': "Analizar textos",
|
| 450 |
'comparison': "Comparación de Relaciones Semánticas",
|
| 451 |
+
'success_message': "Análisis del discurso guardado correctamente.",
|
| 452 |
+
'error_message': "Hubo un problema al guardar el análisis del discurso. Por favor, inténtelo de nuevo.",
|
| 453 |
+
'warning_message': "Por favor, ingrese ambos textos o cargue ambos archivos para analizar."
|
| 454 |
},
|
| 455 |
'en': {
|
| 456 |
'title': "AIdeaText - Discourse Analysis",
|
| 457 |
'file_uploader1': "Upload text file 1 (Pattern)",
|
| 458 |
'file_uploader2': "Upload text file 2 (Comparison)",
|
| 459 |
+
'input_label1': "Or enter text 1 here:",
|
| 460 |
+
'input_label2': "Or enter text 2 here:",
|
| 461 |
'analyze_button': "Analyze texts",
|
| 462 |
'comparison': "Comparison of Semantic Relations",
|
| 463 |
+
'success_message': "Discourse analysis saved successfully.",
|
| 464 |
+
'error_message': "There was a problem saving the discourse analysis. Please try again.",
|
| 465 |
+
'warning_message': "Please enter both texts or upload both files to analyze."
|
| 466 |
},
|
| 467 |
'fr': {
|
| 468 |
'title': "AIdeaText - Analyse du discours",
|
| 469 |
'file_uploader1': "Télécharger le fichier texte 1 (Modèle)",
|
| 470 |
'file_uploader2': "Télécharger le fichier texte 2 (Comparaison)",
|
| 471 |
+
'input_label1': "Ou entrez le texte 1 ici :",
|
| 472 |
+
'input_label2': "Ou entrez le texte 2 ici :",
|
| 473 |
'analyze_button': "Analyser les textes",
|
| 474 |
'comparison': "Comparaison des Relations Sémantiques",
|
| 475 |
+
'success_message': "Analyse du discours enregistrée avec succès.",
|
| 476 |
+
'error_message': "Un problème est survenu lors de l'enregistrement de l'analyse du discours. Veuillez réessayer.",
|
| 477 |
+
'warning_message': "Veuillez entrer les deux textes ou télécharger les deux fichiers à analyser."
|
| 478 |
}
|
| 479 |
}
|
| 480 |
|
| 481 |
t = translations[lang_code]
|
|
|
|
| 482 |
st.header(t['title'])
|
| 483 |
|
| 484 |
+
# Inicializar el estado de la sesión para los textos del discurso
|
| 485 |
+
if 'discourse_text1' not in st.session_state:
|
| 486 |
+
st.session_state.discourse_text1 = ""
|
| 487 |
+
if 'discourse_text2' not in st.session_state:
|
| 488 |
+
st.session_state.discourse_text2 = ""
|
| 489 |
+
|
| 490 |
col1, col2 = st.columns(2)
|
| 491 |
|
| 492 |
with col1:
|
| 493 |
uploaded_file1 = st.file_uploader(t['file_uploader1'], type=['txt'])
|
| 494 |
+
text_input1 = st.text_area(
|
| 495 |
+
t['input_label1'],
|
| 496 |
+
value=st.session_state.discourse_text1,
|
| 497 |
+
height=300,
|
| 498 |
+
key="discourse_text_input1"
|
| 499 |
+
)
|
| 500 |
|
| 501 |
with col2:
|
| 502 |
uploaded_file2 = st.file_uploader(t['file_uploader2'], type=['txt'])
|
| 503 |
+
text_input2 = st.text_area(
|
| 504 |
+
t['input_label2'],
|
| 505 |
+
value=st.session_state.discourse_text2,
|
| 506 |
+
height=300,
|
| 507 |
+
key="discourse_text_input2"
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
if st.button(t['analyze_button']):
|
| 511 |
+
# Priorizar los archivos cargados sobre el texto ingresado
|
| 512 |
+
if uploaded_file1 is not None:
|
| 513 |
+
text_content1 = uploaded_file1.getvalue().decode('utf-8')
|
| 514 |
+
elif text_input1:
|
| 515 |
+
text_content1 = text_input1
|
| 516 |
+
else:
|
| 517 |
+
text_content1 = None
|
| 518 |
|
| 519 |
+
if uploaded_file2 is not None:
|
| 520 |
+
text_content2 = uploaded_file2.getvalue().decode('utf-8')
|
| 521 |
+
elif text_input2:
|
| 522 |
+
text_content2 = text_input2
|
| 523 |
+
else:
|
| 524 |
+
text_content2 = None
|
| 525 |
+
|
| 526 |
+
if text_content1 is None or text_content2 is None:
|
| 527 |
+
st.warning(t['warning_message'])
|
| 528 |
+
return
|
| 529 |
+
|
| 530 |
+
# Guardar los textos en el estado de la sesión
|
| 531 |
+
st.session_state.discourse_text1 = text_content1
|
| 532 |
+
st.session_state.discourse_text2 = text_content2
|
| 533 |
+
|
| 534 |
+
# Realizar el análisis
|
| 535 |
+
graph1, graph2 = perform_discourse_analysis(text_content1, text_content2, nlp_models[lang_code], lang_code)
|
| 536 |
+
|
| 537 |
+
# Mostrar los gráficos de comparación
|
| 538 |
+
st.subheader(t['comparison'])
|
| 539 |
+
col1, col2 = st.columns(2)
|
| 540 |
+
with col1:
|
| 541 |
+
st.pyplot(graph1)
|
| 542 |
+
with col2:
|
| 543 |
+
st.pyplot(graph2)
|
| 544 |
+
|
| 545 |
+
# Guardar el resultado del análisis
|
| 546 |
+
if store_discourse_analysis_result(st.session_state.username, text_content1 + "\n\n" + text_content2, graph1, graph2):
|
| 547 |
+
st.success(t['success_message'])
|
| 548 |
+
else:
|
| 549 |
+
st.error(t['error_message'])
|
| 550 |
|
| 551 |
##################################################################################################
|
| 552 |
|