Spaces:
Sleeping
Sleeping
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -23,7 +23,6 @@ from .morphosyntax_process import (
|
|
| 23 |
|
| 24 |
from ..utils.widget_utils import generate_unique_key
|
| 25 |
|
| 26 |
-
|
| 27 |
from ..database.morphosintax_mongo_db import store_student_morphosyntax_result
|
| 28 |
from ..database.chat_db import store_chat_history
|
| 29 |
from ..database.morphosintaxis_export import export_user_interactions
|
|
@@ -40,7 +39,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 40 |
t: Diccionario de traducciones
|
| 41 |
"""
|
| 42 |
# Obtener el diccionario de traducciones morfosint谩cticas
|
| 43 |
-
morpho_t = t.get('MORPHOSYNTACTIC', {})
|
| 44 |
|
| 45 |
# Inicializar el estado de la entrada
|
| 46 |
input_key = f"morphosyntax_input_{lang_code}"
|
|
@@ -98,6 +97,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
| 98 |
st.error(morpho_t.get('error_processing', f'Error processing text: {str(e)}'))
|
| 99 |
else:
|
| 100 |
st.warning(morpho_t.get('warning_message', 'Please enter a text to analyze'))
|
|
|
|
| 101 |
# Si no se presion贸 el bot贸n, verificar si hay resultados previos
|
| 102 |
elif 'morphosyntax_result' in st.session_state and st.session_state.morphosyntax_result is not None:
|
| 103 |
display_morphosyntax_results(
|
|
@@ -118,7 +118,7 @@ def display_morphosyntax_results(result, lang_code, morpho_t):
|
|
| 118 |
t: Diccionario de traducciones
|
| 119 |
"""
|
| 120 |
# Obtener el diccionario de traducciones morfosint谩cticas
|
| 121 |
-
morpho_t = t.get('MORPHOSYNTACTIC', {})
|
| 122 |
|
| 123 |
if result is None:
|
| 124 |
st.warning(morpho_t.get('no_results', 'No results available'))
|
|
@@ -275,11 +275,9 @@ def display_morphosyntax_results(result, lang_code, morpho_t):
|
|
| 275 |
morphology = morpho_t.get('morphology', 'Morphology')
|
| 276 |
morph_df[morphology] = morph_df[morphology].apply(lambda x: translate_morph(x, lang_code))
|
| 277 |
|
| 278 |
-
# 7. Mostrar el DataFrame
|
| 279 |
st.dataframe(morph_df)
|
| 280 |
|
| 281 |
-
|
| 282 |
-
# Mostrar diagramas de arco (c贸digo existente)
|
| 283 |
with st.expander(morpho_t.get('arc_diagram', 'Syntactic analysis: Arc diagram'), expanded=True):
|
| 284 |
sentences = list(doc.sents)
|
| 285 |
arc_diagrams = []
|
|
@@ -289,11 +287,11 @@ def display_morphosyntax_results(result, lang_code, morpho_t):
|
|
| 289 |
html = displacy.render(sent, style="dep", options={"distance": 100})
|
| 290 |
html = html.replace('height="375"', 'height="200"')
|
| 291 |
html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
|
| 292 |
-
html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"',
|
|
|
|
| 293 |
st.write(html, unsafe_allow_html=True)
|
| 294 |
arc_diagrams.append(html)
|
| 295 |
|
| 296 |
-
|
| 297 |
# Bot贸n de exportaci贸n
|
| 298 |
if st.button(morpho_t.get('export_button', 'Export Analysis')):
|
| 299 |
pdf_buffer = export_user_interactions(st.session_state.username, 'morphosyntax')
|
|
@@ -302,4 +300,4 @@ def display_morphosyntax_results(result, lang_code, morpho_t):
|
|
| 302 |
data=pdf_buffer,
|
| 303 |
file_name="morphosyntax_analysis.pdf",
|
| 304 |
mime="application/pdf"
|
| 305 |
-
)
|
|
|
|
| 23 |
|
| 24 |
from ..utils.widget_utils import generate_unique_key
|
| 25 |
|
|
|
|
| 26 |
from ..database.morphosintax_mongo_db import store_student_morphosyntax_result
|
| 27 |
from ..database.chat_db import store_chat_history
|
| 28 |
from ..database.morphosintaxis_export import export_user_interactions
|
|
|
|
| 39 |
t: Diccionario de traducciones
|
| 40 |
"""
|
| 41 |
# Obtener el diccionario de traducciones morfosint谩cticas
|
| 42 |
+
# morpho_t = t.get('MORPHOSYNTACTIC', {})
|
| 43 |
|
| 44 |
# Inicializar el estado de la entrada
|
| 45 |
input_key = f"morphosyntax_input_{lang_code}"
|
|
|
|
| 97 |
st.error(morpho_t.get('error_processing', f'Error processing text: {str(e)}'))
|
| 98 |
else:
|
| 99 |
st.warning(morpho_t.get('warning_message', 'Please enter a text to analyze'))
|
| 100 |
+
|
| 101 |
# Si no se presion贸 el bot贸n, verificar si hay resultados previos
|
| 102 |
elif 'morphosyntax_result' in st.session_state and st.session_state.morphosyntax_result is not None:
|
| 103 |
display_morphosyntax_results(
|
|
|
|
| 118 |
t: Diccionario de traducciones
|
| 119 |
"""
|
| 120 |
# Obtener el diccionario de traducciones morfosint谩cticas
|
| 121 |
+
# morpho_t = t.get('MORPHOSYNTACTIC', {})
|
| 122 |
|
| 123 |
if result is None:
|
| 124 |
st.warning(morpho_t.get('no_results', 'No results available'))
|
|
|
|
| 275 |
morphology = morpho_t.get('morphology', 'Morphology')
|
| 276 |
morph_df[morphology] = morph_df[morphology].apply(lambda x: translate_morph(x, lang_code))
|
| 277 |
|
|
|
|
| 278 |
st.dataframe(morph_df)
|
| 279 |
|
| 280 |
+
# Mostrar diagramas de arco
|
|
|
|
| 281 |
with st.expander(morpho_t.get('arc_diagram', 'Syntactic analysis: Arc diagram'), expanded=True):
|
| 282 |
sentences = list(doc.sents)
|
| 283 |
arc_diagrams = []
|
|
|
|
| 287 |
html = displacy.render(sent, style="dep", options={"distance": 100})
|
| 288 |
html = html.replace('height="375"', 'height="200"')
|
| 289 |
html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
|
| 290 |
+
html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"',
|
| 291 |
+
lambda m: f'<g transform="translate({m.group(1)},50)"', html)
|
| 292 |
st.write(html, unsafe_allow_html=True)
|
| 293 |
arc_diagrams.append(html)
|
| 294 |
|
|
|
|
| 295 |
# Bot贸n de exportaci贸n
|
| 296 |
if st.button(morpho_t.get('export_button', 'Export Analysis')):
|
| 297 |
pdf_buffer = export_user_interactions(st.session_state.username, 'morphosyntax')
|
|
|
|
| 300 |
data=pdf_buffer,
|
| 301 |
file_name="morphosyntax_analysis.pdf",
|
| 302 |
mime="application/pdf"
|
| 303 |
+
)
|