AIdeaText commited on
Commit
4d7f7d1
1 Parent(s): 5203a97

Update modules/discourse/discourse_process.py

Browse files
modules/discourse/discourse_process.py CHANGED
@@ -1,21 +1,68 @@
1
- from ..text_analysis.discourse_analysis import perform_discourse_analysis, compare_semantic_analysis
2
- import streamlit as st
3
-
4
- def process_discourse_input(user_input, lang_code, nlp_model, file_contents, t):
5
- if user_input.startswith('/analisis_discurso'):
6
- if file_contents is None or len(file_contents) != 2:
7
- return t['no_files_uploaded'], None
8
- text1, text2 = file_contents
9
- result = perform_discourse_analysis(text1, text2, nlp_model, lang_code)
10
- return t['discourse_analysis_completed'], (result['graph1'], result['graph2'])
11
- elif user_input.startswith('/comparar'):
12
- if file_contents is None or len(file_contents) != 2:
13
- return t['no_files_uploaded'], None
14
- text1, text2 = file_contents
15
- comparison_result = compare_semantic_analysis(text1, text2, nlp_model, lang_code)
16
- return t['comparison_completed'], comparison_result
17
- else:
18
- # Procesar otros tipos de inputs del usuario
19
- chatbot = st.session_state.discourse_chatbot
20
- response = chatbot.generate_response(user_input, lang_code, context=str(file_contents))
21
- return response, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ..text_analysis.discourse_analysis import perform_discourse_analysis, compare_semantic_analysis
2
+ import streamlit as st
3
+
4
+ def process_discourse_input(text1, text2, nlp_models, lang_code):
5
+ """
6
+ Procesa la entrada para el análisis del discurso
7
+ Args:
8
+ text1: Texto del primer documento
9
+ text2: Texto del segundo documento
10
+ nlp_models: Diccionario de modelos de spaCy
11
+ lang_code: Código del idioma actual
12
+ Returns:
13
+ dict: Resultados del análisis
14
+ """
15
+ try:
16
+ # Obtener el modelo específico del idioma
17
+ nlp = nlp_models[lang_code]
18
+
19
+ # Realizar el análisis
20
+ analysis_result = perform_discourse_analysis(text1, text2, nlp, lang_code)
21
+
22
+ if analysis_result['success']:
23
+ return {
24
+ 'success': True,
25
+ 'analysis': analysis_result
26
+ }
27
+ else:
28
+ return {
29
+ 'success': False,
30
+ 'error': 'Error en el análisis del discurso'
31
+ }
32
+
33
+ except Exception as e:
34
+ logger.error(f"Error en process_discourse_input: {str(e)}")
35
+ return {
36
+ 'success': False,
37
+ 'error': str(e)
38
+ }
39
+
40
+ def format_discourse_results(result):
41
+ """
42
+ Formatea los resultados del análisis para su visualización
43
+ Args:
44
+ result: Resultado del análisis
45
+ Returns:
46
+ dict: Resultados formateados
47
+ """
48
+ try:
49
+ if not result['success']:
50
+ return result
51
+
52
+ analysis = result['analysis']
53
+ return {
54
+ 'success': True,
55
+ 'graph1': analysis['graph1'],
56
+ 'graph2': analysis['graph2'],
57
+ 'key_concepts1': analysis['key_concepts1'],
58
+ 'key_concepts2': analysis['key_concepts2'],
59
+ 'table1': analysis['table1'],
60
+ 'table2': analysis['table2']
61
+ }
62
+
63
+ except Exception as e:
64
+ logger.error(f"Error en format_discourse_results: {str(e)}")
65
+ return {
66
+ 'success': False,
67
+ 'error': str(e)
68
+ }