Update modules/ui.py
Browse files- modules/ui.py +19 -68
modules/ui.py
CHANGED
|
@@ -403,14 +403,6 @@ def display_semantic_analysis_interface(nlp_models, lang_code):
|
|
| 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:
|
|
@@ -444,109 +436,68 @@ def display_discourse_analysis_interface(nlp_models, lang_code):
|
|
| 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,
|
| 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
|
| 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
|
| 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 |
-
|
| 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 |
-
|
| 531 |
-
|
| 532 |
-
st.session_state.discourse_text2 = text_content2
|
| 533 |
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
st.pyplot(graph1)
|
| 542 |
-
with col2:
|
| 543 |
-
st.pyplot(graph2)
|
| 544 |
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
|
|
|
|
|
|
| 548 |
else:
|
| 549 |
-
st.
|
| 550 |
|
| 551 |
##################################################################################################
|
| 552 |
|
|
|
|
| 403 |
# Opción para cargar archivo
|
| 404 |
uploaded_file = st.file_uploader(t['file_uploader'], type=['txt'])
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
if st.button(t['analyze_button']):
|
| 407 |
# Priorizar el archivo cargado sobre el texto ingresado
|
| 408 |
if uploaded_file is not None:
|
|
|
|
| 436 |
'title': "AIdeaText - Análisis del discurso",
|
| 437 |
'file_uploader1': "Cargar archivo de texto 1 (Patrón)",
|
| 438 |
'file_uploader2': "Cargar archivo de texto 2 (Comparación)",
|
|
|
|
|
|
|
| 439 |
'analyze_button': "Analizar textos",
|
| 440 |
'comparison': "Comparación de Relaciones Semánticas",
|
| 441 |
'success_message': "Análisis del discurso guardado correctamente.",
|
| 442 |
'error_message': "Hubo un problema al guardar el análisis del discurso. Por favor, inténtelo de nuevo.",
|
| 443 |
+
'warning_message': "Por favor, cargue ambos archivos para analizar."
|
| 444 |
},
|
| 445 |
'en': {
|
| 446 |
'title': "AIdeaText - Discourse Analysis",
|
| 447 |
'file_uploader1': "Upload text file 1 (Pattern)",
|
| 448 |
'file_uploader2': "Upload text file 2 (Comparison)",
|
|
|
|
|
|
|
| 449 |
'analyze_button': "Analyze texts",
|
| 450 |
'comparison': "Comparison of Semantic Relations",
|
| 451 |
'success_message': "Discourse analysis saved successfully.",
|
| 452 |
'error_message': "There was a problem saving the discourse analysis. Please try again.",
|
| 453 |
+
'warning_message': "Please upload both files to analyze."
|
| 454 |
},
|
| 455 |
'fr': {
|
| 456 |
'title': "AIdeaText - Analyse du discours",
|
| 457 |
'file_uploader1': "Télécharger le fichier texte 1 (Modèle)",
|
| 458 |
'file_uploader2': "Télécharger le fichier texte 2 (Comparaison)",
|
|
|
|
|
|
|
| 459 |
'analyze_button': "Analyser les textes",
|
| 460 |
'comparison': "Comparaison des Relations Sémantiques",
|
| 461 |
'success_message': "Analyse du discours enregistrée avec succès.",
|
| 462 |
'error_message': "Un problème est survenu lors de l'enregistrement de l'analyse du discours. Veuillez réessayer.",
|
| 463 |
+
'warning_message': "Veuillez télécharger les deux fichiers à analyser."
|
| 464 |
}
|
| 465 |
}
|
| 466 |
|
| 467 |
t = translations[lang_code]
|
| 468 |
st.header(t['title'])
|
| 469 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
col1, col2 = st.columns(2)
|
| 471 |
|
| 472 |
with col1:
|
| 473 |
uploaded_file1 = st.file_uploader(t['file_uploader1'], type=['txt'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
|
| 475 |
with col2:
|
| 476 |
uploaded_file2 = st.file_uploader(t['file_uploader2'], type=['txt'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
|
| 478 |
if st.button(t['analyze_button']):
|
| 479 |
+
if uploaded_file1 is not None and uploaded_file2 is not None:
|
|
|
|
| 480 |
text_content1 = uploaded_file1.getvalue().decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
text_content2 = uploaded_file2.getvalue().decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
|
| 483 |
+
# Realizar el análisis
|
| 484 |
+
graph1, graph2 = perform_discourse_analysis(text_content1, text_content2, nlp_models[lang_code], lang_code)
|
|
|
|
| 485 |
|
| 486 |
+
# Mostrar los gráficos de comparación
|
| 487 |
+
st.subheader(t['comparison'])
|
| 488 |
+
col1, col2 = st.columns(2)
|
| 489 |
+
with col1:
|
| 490 |
+
st.pyplot(graph1)
|
| 491 |
+
with col2:
|
| 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 |
+
st.success(t['success_message'])
|
| 497 |
+
else:
|
| 498 |
+
st.error(t['error_message'])
|
| 499 |
else:
|
| 500 |
+
st.warning(t['warning_message'])
|
| 501 |
|
| 502 |
##################################################################################################
|
| 503 |
|