Spaces:
Running
Running
Create semantic_process.py
Browse files
modules/semantic/semantic_process.py
CHANGED
|
@@ -1,51 +0,0 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
import io
|
| 3 |
-
import base64
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
-
from ..text_analysis.semantic_analysis import perform_semantic_analysis
|
| 6 |
-
from .flexible_analysis_handler import FlexibleAnalysisHandler
|
| 7 |
-
|
| 8 |
-
logger = logging.getLogger(__name__)
|
| 9 |
-
|
| 10 |
-
def encode_image_to_base64(image_data):
|
| 11 |
-
return base64.b64encode(image_data).decode('utf-8')
|
| 12 |
-
|
| 13 |
-
def process_semantic_analysis(file_contents, nlp_model, lang_code):
|
| 14 |
-
logger.info(f"Starting semantic analysis processing for language: {lang_code}")
|
| 15 |
-
try:
|
| 16 |
-
result = perform_semantic_analysis(file_contents, nlp_model, lang_code)
|
| 17 |
-
|
| 18 |
-
concept_graph = result['concept_graph']
|
| 19 |
-
entity_graph = result['entity_graph']
|
| 20 |
-
key_concepts = result['key_concepts']
|
| 21 |
-
|
| 22 |
-
# Convertir los gráficos a base64
|
| 23 |
-
concept_graph_base64 = encode_image_to_base64(concept_graph)
|
| 24 |
-
entity_graph_base64 = encode_image_to_base64(entity_graph)
|
| 25 |
-
|
| 26 |
-
logger.info("Semantic analysis processing completed successfully")
|
| 27 |
-
logger.debug(f"Concept graph base64 (first 100 chars): {concept_graph_base64[:100]}")
|
| 28 |
-
return concept_graph_base64, entity_graph_base64, key_concepts
|
| 29 |
-
except Exception as e:
|
| 30 |
-
logger.error(f"Error in semantic analysis processing: {str(e)}")
|
| 31 |
-
return None, None, []
|
| 32 |
-
|
| 33 |
-
'''
|
| 34 |
-
logger = logging.getLogger(__name__)
|
| 35 |
-
logging.basicConfig(level=logging.DEBUG)
|
| 36 |
-
|
| 37 |
-
def process_semantic_analysis(file_contents, nlp_model, lang_code):
|
| 38 |
-
logger.info(f"Starting semantic analysis for language: {lang_code}")
|
| 39 |
-
try:
|
| 40 |
-
logger.debug("Calling perform_semantic_analysis")
|
| 41 |
-
result = perform_semantic_analysis(file_contents, nlp_model, lang_code)
|
| 42 |
-
logger.debug(f"Result keys: {result.keys()}")
|
| 43 |
-
logger.debug(f"Type of concept_graph: {type(result['concept_graph'])}")
|
| 44 |
-
logger.debug(f"Type of entity_graph: {type(result['entity_graph'])}")
|
| 45 |
-
logger.debug(f"Number of key_concepts: {len(result['key_concepts'])}")
|
| 46 |
-
logger.info("Semantic analysis completed successfully")
|
| 47 |
-
return result['concept_graph'], result['entity_graph'], result['key_concepts']
|
| 48 |
-
except Exception as e:
|
| 49 |
-
logger.error(f"Error in semantic analysis: {str(e)}")
|
| 50 |
-
raise
|
| 51 |
-
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|