Update modules/ui.py
Browse files- modules/ui.py +48 -24
modules/ui.py
CHANGED
|
@@ -301,49 +301,73 @@ def display_semantic_analysis_interface(nlp_models, lang_code):
|
|
| 301 |
translations = {
|
| 302 |
'es': {
|
| 303 |
'title': "AIdeaText - Análisis semántico",
|
| 304 |
-
'
|
| 305 |
-
'input_placeholder': "El objetivo de esta aplicación es que mejore sus habilidades de redacción...",
|
| 306 |
'analyze_button': "Analizar texto",
|
| 307 |
-
'
|
|
|
|
| 308 |
},
|
| 309 |
'en': {
|
| 310 |
'title': "AIdeaText - Semantic Analysis",
|
| 311 |
-
'
|
| 312 |
-
'input_placeholder': "The goal of this app is for you to improve your writing skills...",
|
| 313 |
'analyze_button': "Analyze text",
|
| 314 |
-
'
|
|
|
|
| 315 |
},
|
| 316 |
'fr': {
|
| 317 |
'title': "AIdeaText - Analyse sémantique",
|
| 318 |
-
'
|
| 319 |
-
'input_placeholder': "Le but de cette application est d'améliorer vos compétences en rédaction...",
|
| 320 |
'analyze_button': "Analyser le texte",
|
| 321 |
-
'
|
|
|
|
| 322 |
}
|
| 323 |
}
|
| 324 |
|
| 325 |
t = translations[lang_code]
|
| 326 |
|
| 327 |
-
|
| 328 |
-
st.session_state.semantic_input_text = ""
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
value=st.session_state.semantic_input_text,
|
| 335 |
-
key=f"semantic_text_input_{lang_code}"
|
| 336 |
-
)
|
| 337 |
-
st.session_state.semantic_input_text = sentence_input
|
| 338 |
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
doc = nlp_models[lang_code](sentence_input)
|
| 342 |
|
| 343 |
-
with
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
st.pyplot(fig)
|
| 346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
##################################################################################################
|
| 348 |
def get_chatbot_response(input_text):
|
| 349 |
# Esta función debe ser implementada o importada de otro módulo
|
|
|
|
| 301 |
translations = {
|
| 302 |
'es': {
|
| 303 |
'title': "AIdeaText - Análisis semántico",
|
| 304 |
+
'file_uploader': "Cargar archivo de texto",
|
|
|
|
| 305 |
'analyze_button': "Analizar texto",
|
| 306 |
+
'entities_list': "Lista de entidades",
|
| 307 |
+
'network_diagram': "Diagrama de red semántica",
|
| 308 |
},
|
| 309 |
'en': {
|
| 310 |
'title': "AIdeaText - Semantic Analysis",
|
| 311 |
+
'file_uploader': "Upload text file",
|
|
|
|
| 312 |
'analyze_button': "Analyze text",
|
| 313 |
+
'entities_list': "Entities List",
|
| 314 |
+
'network_diagram': "Semantic Network Diagram",
|
| 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 |
+
'entities_list': "Liste des entités",
|
| 321 |
+
'network_diagram': "Diagramme de réseau sémantique",
|
| 322 |
}
|
| 323 |
}
|
| 324 |
|
| 325 |
t = translations[lang_code]
|
| 326 |
|
| 327 |
+
st.header(t['title'])
|
|
|
|
| 328 |
|
| 329 |
+
uploaded_file = st.file_uploader(t['file_uploader'], type=['txt'])
|
| 330 |
+
|
| 331 |
+
if uploaded_file is not None:
|
| 332 |
+
text_content = uploaded_file.getvalue().decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
+
if st.button(t['analyze_button']):
|
| 335 |
+
col1, col2 = st.columns([1, 3])
|
|
|
|
| 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 |
+
for ent in doc.ents:
|
| 360 |
+
if ent.label_ == "PER":
|
| 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 |
+
return entities
|
| 370 |
+
|
| 371 |
##################################################################################################
|
| 372 |
def get_chatbot_response(input_text):
|
| 373 |
# Esta función debe ser implementada o importada de otro módulo
|