Spaces:
Running
Running
Update modules/semantic/semantic_live_interface.py
Browse files
modules/semantic/semantic_live_interface.py
CHANGED
|
@@ -20,14 +20,10 @@ from ..database.chat_mongo_db import store_chat_history, get_chat_history
|
|
| 20 |
|
| 21 |
def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
| 22 |
"""
|
| 23 |
-
Interfaz para el an谩lisis sem谩ntico en vivo
|
| 24 |
-
Args:
|
| 25 |
-
lang_code: C贸digo del idioma actual
|
| 26 |
-
nlp_models: Modelos de spaCy cargados
|
| 27 |
-
semantic_t: Diccionario de traducciones sem谩nticas
|
| 28 |
"""
|
| 29 |
try:
|
| 30 |
-
# 1. Inicializar el estado de la sesi贸n
|
| 31 |
if 'semantic_live_state' not in st.session_state:
|
| 32 |
st.session_state.semantic_live_state = {
|
| 33 |
'analysis_count': 0,
|
|
@@ -36,68 +32,35 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
| 36 |
'text_changed': False
|
| 37 |
}
|
| 38 |
|
| 39 |
-
# 2.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
return analysis_result
|
| 69 |
-
|
| 70 |
-
# 4. Crear contenedor principal para mantener el layout estable
|
| 71 |
-
with st.container():
|
| 72 |
-
# Crear dos columnas principales
|
| 73 |
-
input_col, result_col = st.columns(2)
|
| 74 |
-
|
| 75 |
-
# Columna izquierda: Entrada de texto
|
| 76 |
-
with input_col:
|
| 77 |
-
st.subheader(semantic_t.get('enter_text', 'Ingrese su texto'))
|
| 78 |
-
|
| 79 |
-
# 脕rea de texto para input usando session state
|
| 80 |
-
text_input = st.text_area(
|
| 81 |
-
semantic_t.get('text_input_label', 'Escriba o pegue su texto aqu铆'),
|
| 82 |
-
height=400,
|
| 83 |
-
key="semantic_live_text",
|
| 84 |
-
on_change=on_text_change
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
# Bot贸n de an谩lisis
|
| 88 |
-
if st.button(
|
| 89 |
-
semantic_t.get('analyze_button', 'Analizar'),
|
| 90 |
-
key="semantic_live_analyze",
|
| 91 |
-
type="primary",
|
| 92 |
-
icon="馃攳",
|
| 93 |
-
disabled=not text_input,
|
| 94 |
-
use_container_width=True
|
| 95 |
-
):
|
| 96 |
-
analysis_result = analyze_text()
|
| 97 |
-
if analysis_result and not analysis_result.get('success'):
|
| 98 |
-
st.error(analysis_result.get('message', 'Error en el an谩lisis'))
|
| 99 |
-
|
| 100 |
-
# Columna derecha: Visualizaci贸n de resultados
|
| 101 |
with result_col:
|
| 102 |
st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
|
| 103 |
|
|
@@ -109,7 +72,7 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
| 109 |
if 'key_concepts' in analysis and analysis['key_concepts'] and \
|
| 110 |
'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 111 |
|
| 112 |
-
# Estilos
|
| 113 |
st.markdown("""
|
| 114 |
<style>
|
| 115 |
.unified-container {
|
|
@@ -117,26 +80,39 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
| 117 |
border-radius: 10px;
|
| 118 |
overflow: hidden;
|
| 119 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
|
|
| 120 |
}
|
| 121 |
.concept-table {
|
| 122 |
display: flex;
|
| 123 |
flex-wrap: wrap;
|
| 124 |
-
gap:
|
| 125 |
-
padding:
|
| 126 |
background-color: #f8f9fa;
|
| 127 |
}
|
| 128 |
.concept-item {
|
| 129 |
background-color: white;
|
| 130 |
border-radius: 5px;
|
| 131 |
-
padding:
|
| 132 |
display: flex;
|
| 133 |
align-items: center;
|
| 134 |
-
gap:
|
| 135 |
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 136 |
}
|
| 137 |
-
.concept-name {
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
</style>
|
| 141 |
""", unsafe_allow_html=True)
|
| 142 |
|
|
@@ -166,8 +142,8 @@ def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
|
| 166 |
|
| 167 |
st.markdown('</div></div>', unsafe_allow_html=True)
|
| 168 |
|
| 169 |
-
# Botones y controles
|
| 170 |
-
button_col, spacer_col = st.columns([1,
|
| 171 |
with button_col:
|
| 172 |
st.download_button(
|
| 173 |
label="馃摜 " + semantic_t.get('download_graph', "Download"),
|
|
|
|
| 20 |
|
| 21 |
def display_semantic_live_interface(lang_code, nlp_models, semantic_t):
|
| 22 |
"""
|
| 23 |
+
Interfaz para el an谩lisis sem谩ntico en vivo con proporciones de columna ajustadas
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
"""
|
| 25 |
try:
|
| 26 |
+
# 1. Inicializar el estado de la sesi贸n
|
| 27 |
if 'semantic_live_state' not in st.session_state:
|
| 28 |
st.session_state.semantic_live_state = {
|
| 29 |
'analysis_count': 0,
|
|
|
|
| 32 |
'text_changed': False
|
| 33 |
}
|
| 34 |
|
| 35 |
+
# 2. Crear columnas con nueva proporci贸n (1:3)
|
| 36 |
+
input_col, result_col = st.columns([1, 3])
|
| 37 |
+
|
| 38 |
+
# Columna izquierda: Entrada de texto (m谩s compacta)
|
| 39 |
+
with input_col:
|
| 40 |
+
st.subheader(semantic_t.get('enter_text', 'Ingrese su texto'))
|
| 41 |
+
|
| 42 |
+
# 脕rea de texto ajustada al nuevo ancho
|
| 43 |
+
text_input = st.text_area(
|
| 44 |
+
semantic_t.get('text_input_label', 'Escriba o pegue su texto aqu铆'),
|
| 45 |
+
height=500, # Aumentado para compensar el ancho reducido
|
| 46 |
+
key="semantic_live_text",
|
| 47 |
+
value=st.session_state.semantic_live_state.get('current_text', '')
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# Actualizar el texto actual en el estado
|
| 51 |
+
st.session_state.semantic_live_state['current_text'] = text_input
|
| 52 |
+
|
| 53 |
+
# Bot贸n de an谩lisis
|
| 54 |
+
analyze_button = st.button(
|
| 55 |
+
semantic_t.get('analyze_button', 'Analizar'),
|
| 56 |
+
key="semantic_live_analyze",
|
| 57 |
+
type="primary",
|
| 58 |
+
icon="馃攳",
|
| 59 |
+
disabled=not text_input,
|
| 60 |
+
use_container_width=True
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# Columna derecha: Visualizaci贸n de resultados (m谩s amplia)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
with result_col:
|
| 65 |
st.subheader(semantic_t.get('live_results', 'Resultados en vivo'))
|
| 66 |
|
|
|
|
| 72 |
if 'key_concepts' in analysis and analysis['key_concepts'] and \
|
| 73 |
'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
| 74 |
|
| 75 |
+
# Estilos adaptados al nuevo ancho
|
| 76 |
st.markdown("""
|
| 77 |
<style>
|
| 78 |
.unified-container {
|
|
|
|
| 80 |
border-radius: 10px;
|
| 81 |
overflow: hidden;
|
| 82 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 83 |
+
width: 100%;
|
| 84 |
}
|
| 85 |
.concept-table {
|
| 86 |
display: flex;
|
| 87 |
flex-wrap: wrap;
|
| 88 |
+
gap: 8px;
|
| 89 |
+
padding: 12px;
|
| 90 |
background-color: #f8f9fa;
|
| 91 |
}
|
| 92 |
.concept-item {
|
| 93 |
background-color: white;
|
| 94 |
border-radius: 5px;
|
| 95 |
+
padding: 6px 10px;
|
| 96 |
display: flex;
|
| 97 |
align-items: center;
|
| 98 |
+
gap: 6px;
|
| 99 |
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
| 100 |
}
|
| 101 |
+
.concept-name {
|
| 102 |
+
font-weight: 500;
|
| 103 |
+
color: #1f2937;
|
| 104 |
+
font-size: 0.95em;
|
| 105 |
+
}
|
| 106 |
+
.concept-freq {
|
| 107 |
+
color: #6b7280;
|
| 108 |
+
font-size: 0.85em;
|
| 109 |
+
}
|
| 110 |
+
.graph-section {
|
| 111 |
+
padding: 20px;
|
| 112 |
+
display: flex;
|
| 113 |
+
flex-direction: column;
|
| 114 |
+
align-items: center;
|
| 115 |
+
}
|
| 116 |
</style>
|
| 117 |
""", unsafe_allow_html=True)
|
| 118 |
|
|
|
|
| 142 |
|
| 143 |
st.markdown('</div></div>', unsafe_allow_html=True)
|
| 144 |
|
| 145 |
+
# Botones y controles ajustados al nuevo ancho
|
| 146 |
+
button_col, spacer_col = st.columns([1,5]) # Ajustada la proporci贸n
|
| 147 |
with button_col:
|
| 148 |
st.download_button(
|
| 149 |
label="馃摜 " + semantic_t.get('download_graph', "Download"),
|