AIdeaText commited on
Commit
cf5b64f
verified
1 Parent(s): 53ea8fc

Update modules/morphosyntax/morphosyntax_interface.py

Browse files
modules/morphosyntax/morphosyntax_interface.py CHANGED
@@ -1,5 +1,6 @@
1
  #modules/morphosyntax/morphosyntax_interface.py
2
  import streamlit as st
 
3
  from streamlit_float import *
4
  from streamlit_antd_components import *
5
  from streamlit.components.v1 import html
@@ -20,52 +21,61 @@ def display_morphosyntax_interface(lang_code, nlp_models, t):
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:
27
  st.session_state[input_key] = ""
28
 
29
  sentence_input = st.text_area(
30
- morpho_t.get('morpho_input_label', 'Enter text to analyze:'),
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')):
 
1
  #modules/morphosyntax/morphosyntax_interface.py
2
  import streamlit as st
3
+ import spacy_streamlit
4
  from streamlit_float import *
5
  from streamlit_antd_components import *
6
  from streamlit.components.v1 import html
 
21
  Interfaz para el an谩lisis morfosint谩ctico
22
  """
23
  morpho_t = t.get('MORPHOSYNTACTIC', {})
24
+ #st.title(morpho_t.get('title', 'AIdeaText - Morphological Analysis'))
25
 
26
  input_key = f"morphosyntax_input_{lang_code}"
27
+
28
  if input_key not in st.session_state:
29
  st.session_state[input_key] = ""
30
 
31
  sentence_input = st.text_area(
32
+ t['input_label'],
33
  height=150,
34
+ placeholder=t['input_placeholder'],
35
  value=st.session_state[input_key],
36
+ key=f"text_area_{lang_code}",
37
+ on_change=lambda: setattr(st.session_state, input_key, st.session_state[f"text_area_{lang_code}"])
38
  )
39
 
40
+ if st.button(t['analyze_button'], key=f"analyze_button_{lang_code}"):
41
+ current_input = st.session_state[input_key]
42
+ if current_input:
43
+ doc = nlp_models[lang_code](current_input)
44
+
45
+ # An谩lisis morfosint谩ctico avanzado
46
+ advanced_analysis = perform_advanced_morphosyntactic_analysis(current_input, nlp_models[lang_code])
47
+
48
+ # Guardar el resultado en el estado de la sesi贸n
49
+ st.session_state.morphosyntax_result = {
50
+ 'doc': doc,
51
+ 'advanced_analysis': advanced_analysis
52
+ }
53
+
54
+ # Mostrar resultados
55
+ display_morphosyntax_results(st.session_state.morphosyntax_result, lang_code, t)
56
+
57
+ # Guardar resultados
58
+ if store_morphosyntax_result(
59
+ st.session_state.username,
60
+ current_input,
61
+ get_repeated_words_colors(doc),
62
+ advanced_analysis['arc_diagram'],
63
+ advanced_analysis['pos_analysis'],
64
+ advanced_analysis['morphological_analysis'],
65
+ advanced_analysis['sentence_structure']
66
+ ):
67
+ st.success(t['success_message'])
68
  else:
69
+ st.error(t['error_message'])
70
  else:
71
+ st.warning(t['warning_message'])
72
+ elif 'morphosyntax_result' in st.session_state and st.session_state.morphosyntax_result is not None:
73
+
74
+ # Si hay un resultado guardado, mostrarlo
75
+ display_morphosyntax_results(st.session_state.morphosyntax_result, lang_code, t)
76
+ else:
77
+ st.info(t['initial_message']) # A帽ade esta traducci贸n a tu diccionario
78
+
79
 
80
  # Bot贸n de exportaci贸n
81
  if st.button(morpho_t.get('export_button', 'Export Analysis')):