Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
modules/semantic/semantic_interface.py
CHANGED
@@ -208,11 +208,11 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
208 |
#Colocar aquí el bloque de código
|
209 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
210 |
try:
|
211 |
-
#
|
212 |
st.markdown(
|
213 |
"""
|
214 |
<style>
|
215 |
-
.
|
216 |
background-color: white;
|
217 |
border-radius: 10px;
|
218 |
padding: 20px;
|
@@ -228,18 +228,30 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
228 |
""",
|
229 |
unsafe_allow_html=True
|
230 |
)
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
# Expandible con la interpretación
|
241 |
with st.expander("📊 " + semantic_t.get('semantic_graph_interpretation', "Interpretación del gráfico semántico")):
|
242 |
-
|
243 |
- 🔀 {semantic_t.get('semantic_arrow_meaning', 'Las flechas indican la dirección de la relación entre conceptos')}
|
244 |
- 🎨 {semantic_t.get('semantic_color_meaning', 'Los colores más intensos indican conceptos más centrales en el texto')}
|
245 |
- ⭕ {semantic_t.get('semantic_size_meaning', 'El tamaño de los nodos representa la frecuencia del concepto')}
|
@@ -260,5 +272,5 @@ def display_semantic_results(semantic_result, lang_code, semantic_t):
|
|
260 |
except Exception as e:
|
261 |
logger.error(f"Error displaying graph: {str(e)}")
|
262 |
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
263 |
-
|
264 |
-
|
|
|
208 |
#Colocar aquí el bloque de código
|
209 |
if 'concept_graph' in analysis and analysis['concept_graph'] is not None:
|
210 |
try:
|
211 |
+
# Container para el grafo con estilos mejorados
|
212 |
st.markdown(
|
213 |
"""
|
214 |
<style>
|
215 |
+
.graph-container {
|
216 |
background-color: white;
|
217 |
border-radius: 10px;
|
218 |
padding: 20px;
|
|
|
228 |
""",
|
229 |
unsafe_allow_html=True
|
230 |
)
|
231 |
+
#Colocar aquí el bloque de código
|
232 |
+
|
233 |
+
with st.container():
|
234 |
+
st.markdown('<div class="graph-container">', unsafe_allow_html=True)
|
235 |
+
|
236 |
+
# Mostrar grafo
|
237 |
+
graph_bytes = analysis['concept_graph']
|
238 |
+
graph_base64 = base64.b64encode(graph_bytes).decode()
|
239 |
+
st.markdown(
|
240 |
+
f'<img src="data:image/png;base64,{graph_base64}" alt="Concept Graph" style="width:100%;"/>',
|
241 |
+
unsafe_allow_html=True
|
242 |
+
)
|
243 |
+
|
244 |
+
# Leyenda del grafo
|
245 |
+
#st.caption(semantic_t.get(
|
246 |
+
# 'graph_description',
|
247 |
+
# 'Visualización de relaciones entre conceptos clave identificados en el texto.'
|
248 |
+
#))
|
249 |
+
|
250 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
251 |
+
|
252 |
# Expandible con la interpretación
|
253 |
with st.expander("📊 " + semantic_t.get('semantic_graph_interpretation', "Interpretación del gráfico semántico")):
|
254 |
+
st.markdown(f"""
|
255 |
- 🔀 {semantic_t.get('semantic_arrow_meaning', 'Las flechas indican la dirección de la relación entre conceptos')}
|
256 |
- 🎨 {semantic_t.get('semantic_color_meaning', 'Los colores más intensos indican conceptos más centrales en el texto')}
|
257 |
- ⭕ {semantic_t.get('semantic_size_meaning', 'El tamaño de los nodos representa la frecuencia del concepto')}
|
|
|
272 |
except Exception as e:
|
273 |
logger.error(f"Error displaying graph: {str(e)}")
|
274 |
st.error(semantic_t.get('graph_error', 'Error displaying the graph'))
|
275 |
+
else:
|
276 |
+
st.info(semantic_t.get('no_graph', 'No concept graph available'))
|
modules/semantic/semantic_process.py
CHANGED
@@ -15,22 +15,16 @@ from ..database.semantic_mongo_db import store_student_semantic_result
|
|
15 |
|
16 |
logger = logging.getLogger(__name__)
|
17 |
|
18 |
-
|
19 |
-
def process_semantic_input(text_content, lang_code, nlp_models, semantic_t):
|
20 |
"""
|
21 |
Procesa el texto ingresado para realizar el análisis semántico.
|
22 |
"""
|
23 |
try:
|
24 |
-
logger.info(f"Iniciando análisis semántico para texto de {len(
|
25 |
|
26 |
# Realizar el análisis semántico
|
27 |
nlp = nlp_models[lang_code]
|
28 |
-
analysis_result = perform_semantic_analysis(
|
29 |
-
text_content,
|
30 |
-
nlp,
|
31 |
-
lang_code,
|
32 |
-
semantic_t
|
33 |
-
)
|
34 |
|
35 |
if not analysis_result['success']:
|
36 |
return {
|
@@ -40,12 +34,12 @@ def process_semantic_input(text_content, lang_code, nlp_models, semantic_t):
|
|
40 |
}
|
41 |
|
42 |
logger.info("Análisis semántico completado. Guardando resultados...")
|
43 |
-
|
44 |
# Intentar guardar en la base de datos
|
45 |
try:
|
46 |
store_result = store_student_semantic_result(
|
47 |
st.session_state.username,
|
48 |
-
|
49 |
analysis_result
|
50 |
)
|
51 |
if not store_result:
|
@@ -56,7 +50,7 @@ def process_semantic_input(text_content, lang_code, nlp_models, semantic_t):
|
|
56 |
# Devolver el resultado incluso si falla el guardado
|
57 |
return {
|
58 |
'success': True,
|
59 |
-
'message':
|
60 |
'analysis': {
|
61 |
'key_concepts': analysis_result['key_concepts'],
|
62 |
'concept_graph': analysis_result['concept_graph']
|
@@ -71,7 +65,6 @@ def process_semantic_input(text_content, lang_code, nlp_models, semantic_t):
|
|
71 |
'analysis': None
|
72 |
}
|
73 |
|
74 |
-
########################################################################################
|
75 |
def format_semantic_results(analysis_result, t):
|
76 |
"""
|
77 |
Formatea los resultados del análisis para su visualización.
|
|
|
15 |
|
16 |
logger = logging.getLogger(__name__)
|
17 |
|
18 |
+
def process_semantic_input(text, lang_code, nlp_models, t):
|
|
|
19 |
"""
|
20 |
Procesa el texto ingresado para realizar el análisis semántico.
|
21 |
"""
|
22 |
try:
|
23 |
+
logger.info(f"Iniciando análisis semántico para texto de {len(text)} caracteres")
|
24 |
|
25 |
# Realizar el análisis semántico
|
26 |
nlp = nlp_models[lang_code]
|
27 |
+
analysis_result = perform_semantic_analysis(text, nlp, lang_code)
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
if not analysis_result['success']:
|
30 |
return {
|
|
|
34 |
}
|
35 |
|
36 |
logger.info("Análisis semántico completado. Guardando resultados...")
|
37 |
+
|
38 |
# Intentar guardar en la base de datos
|
39 |
try:
|
40 |
store_result = store_student_semantic_result(
|
41 |
st.session_state.username,
|
42 |
+
text,
|
43 |
analysis_result
|
44 |
)
|
45 |
if not store_result:
|
|
|
50 |
# Devolver el resultado incluso si falla el guardado
|
51 |
return {
|
52 |
'success': True,
|
53 |
+
'message': t.get('success_message', 'Analysis completed successfully'),
|
54 |
'analysis': {
|
55 |
'key_concepts': analysis_result['key_concepts'],
|
56 |
'concept_graph': analysis_result['concept_graph']
|
|
|
65 |
'analysis': None
|
66 |
}
|
67 |
|
|
|
68 |
def format_semantic_results(analysis_result, t):
|
69 |
"""
|
70 |
Formatea los resultados del análisis para su visualización.
|