Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -31,7 +31,7 @@ from ..database.morphosintaxis_export import export_user_interactions
|
|
31 |
import logging
|
32 |
logger = logging.getLogger(__name__)
|
33 |
|
34 |
-
def display_morphosyntax_interface(lang_code, nlp_models,
|
35 |
"""
|
36 |
Interfaz para el análisis morfosintáctico
|
37 |
Args:
|
@@ -109,7 +109,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, t):
|
|
109 |
st.info(morpho_t.get('morpho_initial_message', 'Enter text to begin analysis'))
|
110 |
|
111 |
############################################################################################################
|
112 |
-
def display_morphosyntax_results(result, lang_code,
|
113 |
"""
|
114 |
Muestra los resultados del análisis morfosintáctico.
|
115 |
Args:
|
@@ -283,6 +283,7 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
283 |
with st.expander(morpho_t.get('arc_diagram', 'Syntactic analysis: Arc diagram'), expanded=True):
|
284 |
sentences = list(doc.sents)
|
285 |
arc_diagrams = []
|
|
|
286 |
for i, sent in enumerate(sentences):
|
287 |
st.subheader(f"{morpho_t.get('sentence', 'Sentence')} {i+1}")
|
288 |
html = displacy.render(sent, style="dep", options={"distance": 100})
|
@@ -302,99 +303,3 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
302 |
file_name="morphosyntax_analysis.pdf",
|
303 |
mime="application/pdf"
|
304 |
)
|
305 |
-
|
306 |
-
'''
|
307 |
-
if user_input:
|
308 |
-
# Añadir el mensaje del usuario al historial
|
309 |
-
st.session_state.morphosyntax_chat_history.append({"role": "user", "content": user_input})
|
310 |
-
|
311 |
-
# Procesar el input del usuario nuevo al 26-9-2024
|
312 |
-
response, visualizations, result = process_morphosyntactic_input(user_input, lang_code, nlp_models, t)
|
313 |
-
|
314 |
-
# Mostrar indicador de carga
|
315 |
-
with st.spinner(t.get('processing', 'Processing...')):
|
316 |
-
try:
|
317 |
-
# Procesar el input del usuario
|
318 |
-
response, visualizations, result = process_morphosyntactic_input(user_input, lang_code, nlp_models, t)
|
319 |
-
|
320 |
-
# Añadir la respuesta al historial
|
321 |
-
message = {
|
322 |
-
"role": "assistant",
|
323 |
-
"content": response
|
324 |
-
}
|
325 |
-
if visualizations:
|
326 |
-
message["visualizations"] = visualizations
|
327 |
-
st.session_state.morphosyntax_chat_history.append(message)
|
328 |
-
|
329 |
-
# Mostrar la respuesta más reciente
|
330 |
-
with st.chat_message("assistant"):
|
331 |
-
st.write(response)
|
332 |
-
if visualizations:
|
333 |
-
for i, viz in enumerate(visualizations):
|
334 |
-
st.markdown(f"**Oración {i+1} del párrafo analizado**")
|
335 |
-
st.components.v1.html(
|
336 |
-
f"""
|
337 |
-
<div style="width: 100%; overflow-x: auto; white-space: nowrap;">
|
338 |
-
<div style="min-width: 1200px;">
|
339 |
-
{viz}
|
340 |
-
</div>
|
341 |
-
</div>
|
342 |
-
""",
|
343 |
-
height=350,
|
344 |
-
scrolling=True
|
345 |
-
)
|
346 |
-
if i < len(visualizations) - 1:
|
347 |
-
st.markdown("---") # Separador entre diagramas
|
348 |
-
|
349 |
-
# Si es un análisis, guardarlo en la base de datos
|
350 |
-
if user_input.startswith('/analisis_morfosintactico') and result:
|
351 |
-
store_morphosyntax_result(
|
352 |
-
st.session_state.username,
|
353 |
-
user_input.split('[', 1)[1].rsplit(']', 1)[0], # texto analizado
|
354 |
-
result.get('repeated_words', {}),
|
355 |
-
visualizations,
|
356 |
-
result.get('pos_analysis', []),
|
357 |
-
result.get('morphological_analysis', []),
|
358 |
-
result.get('sentence_structure', [])
|
359 |
-
)
|
360 |
-
|
361 |
-
|
362 |
-
except Exception as e:
|
363 |
-
st.error(f"{t['error_processing']}: {str(e)}")
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
# Forzar la actualización de la interfaz
|
368 |
-
st.rerun()
|
369 |
-
|
370 |
-
# Botón para limpiar el historial del chat
|
371 |
-
if st.button(t['clear_chat'], key=generate_unique_key('morphosyntax', 'clear_chat')):
|
372 |
-
st.session_state.morphosyntax_chat_history = []
|
373 |
-
st.rerun()
|
374 |
-
'''
|
375 |
-
|
376 |
-
|
377 |
-
'''
|
378 |
-
############ MODULO PARA DEPURACIÓN Y PRUEBAS #####################################################
|
379 |
-
def display_morphosyntax_interface(lang_code, nlp_models, t):
|
380 |
-
st.subheader(t['morpho_title'])
|
381 |
-
|
382 |
-
text_input = st.text_area(
|
383 |
-
t['warning_message'],
|
384 |
-
height=150,
|
385 |
-
key=generate_unique_key("morphosyntax", "text_area")
|
386 |
-
)
|
387 |
-
|
388 |
-
if st.button(
|
389 |
-
t['results_title'],
|
390 |
-
key=generate_unique_key("morphosyntax", "analyze_button")
|
391 |
-
):
|
392 |
-
if text_input:
|
393 |
-
# Aquí iría tu lógica de análisis morfosintáctico
|
394 |
-
# Por ahora, solo mostraremos un mensaje de placeholder
|
395 |
-
st.info(t['analysis_placeholder'])
|
396 |
-
else:
|
397 |
-
st.warning(t['no_text_warning'])
|
398 |
-
###
|
399 |
-
#################################################
|
400 |
-
'''
|
|
|
31 |
import logging
|
32 |
logger = logging.getLogger(__name__)
|
33 |
|
34 |
+
def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
35 |
"""
|
36 |
Interfaz para el análisis morfosintáctico
|
37 |
Args:
|
|
|
109 |
st.info(morpho_t.get('morpho_initial_message', 'Enter text to begin analysis'))
|
110 |
|
111 |
############################################################################################################
|
112 |
+
def display_morphosyntax_results(result, lang_code, morpho_t):
|
113 |
"""
|
114 |
Muestra los resultados del análisis morfosintáctico.
|
115 |
Args:
|
|
|
283 |
with st.expander(morpho_t.get('arc_diagram', 'Syntactic analysis: Arc diagram'), expanded=True):
|
284 |
sentences = list(doc.sents)
|
285 |
arc_diagrams = []
|
286 |
+
|
287 |
for i, sent in enumerate(sentences):
|
288 |
st.subheader(f"{morpho_t.get('sentence', 'Sentence')} {i+1}")
|
289 |
html = displacy.render(sent, style="dep", options={"distance": 100})
|
|
|
303 |
file_name="morphosyntax_analysis.pdf",
|
304 |
mime="application/pdf"
|
305 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|