Update modules/ui.py
Browse files- modules/ui.py +11 -39
modules/ui.py
CHANGED
|
@@ -303,22 +303,22 @@ def display_semantic_analysis_interface(nlp_models, lang_code):
|
|
| 303 |
'title': "AIdeaText - Análisis semántico",
|
| 304 |
'file_uploader': "Cargar archivo de texto",
|
| 305 |
'analyze_button': "Analizar texto",
|
| 306 |
-
'
|
| 307 |
-
'
|
| 308 |
},
|
| 309 |
'en': {
|
| 310 |
'title': "AIdeaText - Semantic Analysis",
|
| 311 |
'file_uploader': "Upload text file",
|
| 312 |
'analyze_button': "Analyze text",
|
| 313 |
-
'
|
| 314 |
-
'
|
| 315 |
},
|
| 316 |
'fr': {
|
| 317 |
'title': "AIdeaText - Analyse sémantique",
|
| 318 |
'file_uploader': "Télécharger le fichier texte",
|
| 319 |
'analyze_button': "Analyser le texte",
|
| 320 |
-
'
|
| 321 |
-
'
|
| 322 |
}
|
| 323 |
}
|
| 324 |
|
|
@@ -332,41 +332,13 @@ def display_semantic_analysis_interface(nlp_models, lang_code):
|
|
| 332 |
text_content = uploaded_file.getvalue().decode('utf-8')
|
| 333 |
|
| 334 |
if st.button(t['analyze_button']):
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
with col1:
|
| 338 |
-
st.subheader(t['entities_list'])
|
| 339 |
-
entities = extract_entities(text_content, nlp_models[lang_code])
|
| 340 |
-
for entity_type, entity_list in entities.items():
|
| 341 |
-
st.write(f"**{entity_type}:**")
|
| 342 |
-
for entity in entity_list:
|
| 343 |
-
st.write(f"- {entity}")
|
| 344 |
-
|
| 345 |
-
with col2:
|
| 346 |
-
st.subheader(t['network_diagram'])
|
| 347 |
-
fig = visualize_semantic_network(text_content, nlp_models[lang_code], lang_code)
|
| 348 |
-
st.pyplot(fig)
|
| 349 |
-
|
| 350 |
-
def extract_entities(text, nlp):
|
| 351 |
-
doc = nlp(text)
|
| 352 |
-
entities = {
|
| 353 |
-
"Personas": [],
|
| 354 |
-
"Conceptos": [],
|
| 355 |
-
"Lugares": [],
|
| 356 |
-
"Fechas": []
|
| 357 |
-
}
|
| 358 |
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
entities["Personas"].append(ent.text)
|
| 362 |
-
elif ent.label_ == "LOC" or ent.label_ == "GPE":
|
| 363 |
-
entities["Lugares"].append(ent.text)
|
| 364 |
-
elif ent.label_ == "DATE":
|
| 365 |
-
entities["Fechas"].append(ent.text)
|
| 366 |
-
else:
|
| 367 |
-
entities["Conceptos"].append(ent.text)
|
| 368 |
|
| 369 |
-
|
|
|
|
| 370 |
|
| 371 |
##################################################################################################
|
| 372 |
def get_chatbot_response(input_text):
|
|
|
|
| 303 |
'title': "AIdeaText - Análisis semántico",
|
| 304 |
'file_uploader': "Cargar archivo de texto",
|
| 305 |
'analyze_button': "Analizar texto",
|
| 306 |
+
'context_analysis': "Análisis de Contexto",
|
| 307 |
+
'semantic_relations': "Análisis de Relaciones Semánticas",
|
| 308 |
},
|
| 309 |
'en': {
|
| 310 |
'title': "AIdeaText - Semantic Analysis",
|
| 311 |
'file_uploader': "Upload text file",
|
| 312 |
'analyze_button': "Analyze text",
|
| 313 |
+
'context_analysis': "Context Analysis",
|
| 314 |
+
'semantic_relations': "Semantic Relations Analysis",
|
| 315 |
},
|
| 316 |
'fr': {
|
| 317 |
'title': "AIdeaText - Analyse sémantique",
|
| 318 |
'file_uploader': "Télécharger le fichier texte",
|
| 319 |
'analyze_button': "Analyser le texte",
|
| 320 |
+
'context_analysis': "Analyse de Contexte",
|
| 321 |
+
'semantic_relations': "Analyse des Relations Sémantiques",
|
| 322 |
}
|
| 323 |
}
|
| 324 |
|
|
|
|
| 332 |
text_content = uploaded_file.getvalue().decode('utf-8')
|
| 333 |
|
| 334 |
if st.button(t['analyze_button']):
|
| 335 |
+
context_graph, relations_graph = perform_semantic_analysis(text_content, nlp_models[lang_code], lang_code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
+
with st.expander(t['context_analysis'], expanded=True):
|
| 338 |
+
st.pyplot(context_graph)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
+
with st.expander(t['semantic_relations'], expanded=True):
|
| 341 |
+
st.pyplot(relations_graph)
|
| 342 |
|
| 343 |
##################################################################################################
|
| 344 |
def get_chatbot_response(input_text):
|