Spaces:
Running
Running
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -4,7 +4,9 @@ from streamlit_float import *
|
|
| 4 |
from streamlit_antd_components import *
|
| 5 |
from streamlit.components.v1 import html
|
| 6 |
import base64
|
|
|
|
| 7 |
from .morphosyntax_process import process_morphosyntactic_input, format_analysis_results
|
|
|
|
| 8 |
from ..utils.widget_utils import generate_unique_key
|
| 9 |
from ..database.morphosintax_mongo_db import store_student_morphosyntax_result
|
| 10 |
from ..database.chat_db import store_chat_history
|
|
@@ -13,19 +15,12 @@ from ..database.morphosintaxis_export import export_user_interactions
|
|
| 13 |
import logging
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
-
|
| 17 |
def display_morphosyntax_interface(lang_code, nlp_models, t):
|
| 18 |
"""
|
| 19 |
Interfaz para el an谩lisis morfosint谩ctico
|
| 20 |
-
Args:
|
| 21 |
-
lang_code: C贸digo del idioma actual
|
| 22 |
-
nlp_models: Modelos de spaCy cargados
|
| 23 |
-
t: Diccionario de traducciones
|
| 24 |
"""
|
| 25 |
-
# Asegurarnos de que estamos accediendo al diccionario MORPHOSYNTACTIC
|
| 26 |
morpho_t = t.get('MORPHOSYNTACTIC', {})
|
| 27 |
-
|
| 28 |
-
st.title(morpho_t.get('title', 'AIdeaText - Morphological and Syntactic Analysis'))
|
| 29 |
|
| 30 |
input_key = f"morphosyntax_input_{lang_code}"
|
| 31 |
if input_key not in st.session_state:
|
|
@@ -36,49 +31,51 @@ def display_morphosyntax_interface(lang_code, nlp_models, t):
|
|
| 36 |
height=150,
|
| 37 |
placeholder=morpho_t.get('morpho_input_placeholder', 'Enter your text here...'),
|
| 38 |
value=st.session_state[input_key],
|
| 39 |
-
key=f"text_area_{lang_code}"
|
| 40 |
-
on_change=lambda: setattr(st.session_state, input_key, st.session_state[f"text_area_{lang_code}"])
|
| 41 |
)
|
| 42 |
|
| 43 |
if st.button(morpho_t.get('analyze_button', 'Analyze'), key=f"analyze_button_{lang_code}"):
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
st.
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
else:
|
| 72 |
-
st.error(
|
| 73 |
else:
|
| 74 |
st.warning(morpho_t.get('warning_message', 'Please enter a text to analyze.'))
|
| 75 |
-
|
| 76 |
-
elif 'morphosyntax_result' in st.session_state and st.session_state.morphosyntax_result is not None:
|
| 77 |
-
# Si hay un resultado guardado, mostrarlo
|
| 78 |
-
display_morphosyntax_results(st.session_state.morphosyntax_result, lang_code, morpho_t)
|
| 79 |
-
else:
|
| 80 |
-
st.info(morpho_t.get('morpho_initial_message', 'Enter text to begin analysis.'))
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
'''
|
| 84 |
if user_input:
|
|
|
|
| 4 |
from streamlit_antd_components import *
|
| 5 |
from streamlit.components.v1 import html
|
| 6 |
import base64
|
| 7 |
+
|
| 8 |
from .morphosyntax_process import process_morphosyntactic_input, format_analysis_results
|
| 9 |
+
|
| 10 |
from ..utils.widget_utils import generate_unique_key
|
| 11 |
from ..database.morphosintax_mongo_db import store_student_morphosyntax_result
|
| 12 |
from ..database.chat_db import store_chat_history
|
|
|
|
| 15 |
import logging
|
| 16 |
logger = logging.getLogger(__name__)
|
| 17 |
|
|
|
|
| 18 |
def display_morphosyntax_interface(lang_code, nlp_models, t):
|
| 19 |
"""
|
| 20 |
Interfaz para el an谩lisis morfosint谩ctico
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
"""
|
|
|
|
| 22 |
morpho_t = t.get('MORPHOSYNTACTIC', {})
|
| 23 |
+
st.title(morpho_t.get('title', 'AIdeaText - Morphological Analysis'))
|
|
|
|
| 24 |
|
| 25 |
input_key = f"morphosyntax_input_{lang_code}"
|
| 26 |
if input_key not in st.session_state:
|
|
|
|
| 31 |
height=150,
|
| 32 |
placeholder=morpho_t.get('morpho_input_placeholder', 'Enter your text here...'),
|
| 33 |
value=st.session_state[input_key],
|
| 34 |
+
key=f"text_area_{lang_code}"
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
if st.button(morpho_t.get('analyze_button', 'Analyze'), key=f"analyze_button_{lang_code}"):
|
| 38 |
+
if sentence_input:
|
| 39 |
+
# Usar el proceso morfosint谩ctico actualizado
|
| 40 |
+
result = process_morphosyntactic_input(
|
| 41 |
+
sentence_input,
|
| 42 |
+
lang_code,
|
| 43 |
+
nlp_models,
|
| 44 |
+
t
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if result['success']:
|
| 48 |
+
# Formatear y mostrar resultados
|
| 49 |
+
formatted_results = format_analysis_results(result, t)
|
| 50 |
+
|
| 51 |
+
# Mostrar texto resaltado si est谩 disponible
|
| 52 |
+
if formatted_results['highlighted_text']:
|
| 53 |
+
st.markdown(formatted_results['highlighted_text'], unsafe_allow_html=True)
|
| 54 |
+
|
| 55 |
+
# Mostrar el an谩lisis formateado
|
| 56 |
+
st.markdown(formatted_results['formatted_text'])
|
| 57 |
+
|
| 58 |
+
# Mostrar visualizaciones
|
| 59 |
+
if formatted_results['visualizations']:
|
| 60 |
+
for i, viz in enumerate(formatted_results['visualizations']):
|
| 61 |
+
st.markdown(f"**{morpho_t.get('sentence', 'Sentence')} {i+1}**")
|
| 62 |
+
st.components.v1.html(viz, height=370, scrolling=True)
|
| 63 |
+
if i < len(formatted_results['visualizations']) - 1:
|
| 64 |
+
st.markdown("---")
|
| 65 |
else:
|
| 66 |
+
st.error(result['message'])
|
| 67 |
else:
|
| 68 |
st.warning(morpho_t.get('warning_message', 'Please enter a text to analyze.'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
# Bot贸n de exportaci贸n
|
| 71 |
+
if st.button(morpho_t.get('export_button', 'Export Analysis')):
|
| 72 |
+
pdf_buffer = export_user_interactions(st.session_state.username, 'morphosyntax')
|
| 73 |
+
st.download_button(
|
| 74 |
+
label=morpho_t.get('download_pdf', 'Download PDF'),
|
| 75 |
+
data=pdf_buffer,
|
| 76 |
+
file_name="morphosyntax_analysis.pdf",
|
| 77 |
+
mime="application/pdf"
|
| 78 |
+
)
|
| 79 |
|
| 80 |
'''
|
| 81 |
if user_input:
|