AIdeaText commited on
Commit
6e5dd3f
verified
1 Parent(s): 557104f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +150 -149
app.py CHANGED
@@ -1,150 +1,151 @@
1
- #app.py de v3
2
- #app.py
3
- import logging
4
- import streamlit as st
5
- import sys
6
- import os
7
- from dotenv import load_dotenv
8
- from datetime import datetime
9
-
10
- def setup_logging():
11
- log_dir = 'logs'
12
- if not os.path.exists(log_dir):
13
- os.makedirs(log_dir)
14
- current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
15
- log_filename = f'{log_dir}/app_log_{current_time}.txt'
16
- logging.basicConfig(
17
- level=logging.DEBUG,
18
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
19
- filename=log_filename,
20
- filemode='w'
21
- )
22
- console = logging.StreamHandler()
23
- console.setLevel(logging.INFO)
24
- formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
25
- console.setFormatter(formatter)
26
- logging.getLogger('').addHandler(console)
27
- logging.info(f"Logging iniciado. Archivo de log: {log_filename}")
28
-
29
- setup_logging()
30
- load_dotenv()
31
-
32
- st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")
33
-
34
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
35
-
36
- #########IMPORTACIONES LOCALES#######################################
37
- from translations import get_translations
38
-
39
- from session_state import initialize_session_state
40
-
41
- from modules.ui.ui import main as ui_main
42
-
43
- from modules.utils.spacy_utils import load_spacy_models
44
-
45
- from modules.morphosyntax.morphosyntax_interface import (
46
- display_morphosyntax_interface
47
- )
48
-
49
- ###Importaciones de la base de datos###
50
- from modules.database.database_init import (
51
- initialize_database_connections
52
- )
53
-
54
- from modules.database.sql_db import (
55
- create_student_user,
56
- get_student_user,
57
- update_student_user,
58
- delete_student_user,
59
- store_application_request,
60
- store_student_feedback
61
- )
62
-
63
-
64
- from modules.database.mongo_db import (
65
- get_collection,
66
- insert_document,
67
- find_documents,
68
- update_document,
69
- delete_document
70
- )
71
-
72
- from modules.database.morphosintax_mongo_db import (
73
- store_student_morphosyntax_result,
74
- get_student_morphosyntax_analysis
75
- )
76
-
77
- from modules.database.chat_db import (
78
- store_chat_history,
79
- get_chat_history
80
- )
81
-
82
- from modules.studentact.student_activities_v2 import (
83
- display_student_progress
84
- )
85
-
86
- from modules.auth.auth import (
87
- authenticate_student,
88
- register_student,
89
- update_student_info,
90
- delete_student
91
- )
92
-
93
- from modules.admin.admin_ui import admin_page
94
-
95
- from modules.chatbot.chatbot import (
96
- initialize_chatbot,
97
- process_chat_input
98
- )
99
-
100
- print("Configurando p谩gina")
101
- st.cache_data.clear()
102
- st.cache_resource.clear()
103
-
104
- logging.basicConfig(level=logging.INFO)
105
- logger = logging.getLogger(__name__)
106
-
107
- @st.cache_resource
108
- def initialize_nlp_models():
109
- logger.info("Cargando modelos de spaCy")
110
- models = load_spacy_models()
111
- logger.info("Modelos de spaCy cargados exitosamente")
112
- return models
113
-
114
- def app_main():
115
- try:
116
- logger.info("Entrando en app_main()")
117
-
118
- # Inicializar el estado de la sesi贸n
119
- initialize_session_state()
120
-
121
- # Inicializar conexiones a bases de datos si no se ha hecho
122
- if 'db_initialized' not in st.session_state:
123
- st.session_state.db_initialized = initialize_database_connections()
124
-
125
- # Cargar modelos NLP si no se ha hecho
126
- if 'nlp_models' not in st.session_state:
127
- logger.info("Inicializando modelos NLP en la sesi贸n")
128
- st.session_state.nlp_models = initialize_nlp_models()
129
- logger.info("Modelos NLP inicializados y almacenados en la sesi贸n")
130
-
131
- # Configurar la p谩gina inicial si no est谩 configurada
132
- if 'page' not in st.session_state:
133
- st.session_state.page = 'login'
134
-
135
- logger.info(f"P谩gina actual: {st.session_state.page}")
136
- logger.info(f"Rol del usuario: {st.session_state.role}")
137
-
138
- # Dirigir el flujo a la interfaz de usuario principal
139
- logger.info(f"Llamando a ui_main() desde app_main()")
140
- ui_main()
141
-
142
- except Exception as e:
143
- logger.error(f"Error en app_main: {str(e)}", exc_info=True)
144
- st.error("Se ha producido un error en la aplicaci贸n. Por favor, int茅ntelo de nuevo m谩s tarde.")
145
- if st.button("Reiniciar aplicaci贸n"):
146
- st.rerun()
147
-
148
- if __name__ == "__main__":
149
- print("Llamando a app_main()")
 
150
  app_main()
 
1
+ #app.py de v3
2
+ #app.py
3
+ import logging
4
+ import streamlit as st
5
+ import sys
6
+ import os
7
+ from dotenv import load_dotenv
8
+ from datetime import datetime
9
+
10
+ def setup_logging():
11
+ log_dir = 'logs'
12
+ if not os.path.exists(log_dir):
13
+ os.makedirs(log_dir)
14
+ current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
15
+ log_filename = f'{log_dir}/app_log_{current_time}.txt'
16
+ logging.basicConfig(
17
+ level=logging.DEBUG,
18
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
19
+ filename=log_filename,
20
+ filemode='w'
21
+ )
22
+ console = logging.StreamHandler()
23
+ console.setLevel(logging.INFO)
24
+ formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
25
+ console.setFormatter(formatter)
26
+ logging.getLogger('').addHandler(console)
27
+ logging.info(f"Logging iniciado. Archivo de log: {log_filename}")
28
+
29
+ setup_logging()
30
+ load_dotenv()
31
+
32
+ st.set_page_config(page_title="AIdeaText", layout="wide", page_icon="random")
33
+
34
+ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
35
+
36
+ #########IMPORTACIONES LOCALES#######################################
37
+ from translations import get_translations
38
+
39
+ from session_state import initialize_session_state
40
+
41
+ from modules.ui.ui import main as ui_main
42
+
43
+ from modules.utils.spacy_utils import load_spacy_models
44
+
45
+ from modules.morphosyntax.morphosyntax_interface import (
46
+ display_morphosyntax_interface,
47
+ display_morphosyntax_results
48
+ )
49
+
50
+ ###Importaciones de la base de datos###
51
+ from modules.database.database_init import (
52
+ initialize_database_connections
53
+ )
54
+
55
+ from modules.database.sql_db import (
56
+ create_student_user,
57
+ get_student_user,
58
+ update_student_user,
59
+ delete_student_user,
60
+ store_application_request,
61
+ store_student_feedback
62
+ )
63
+
64
+
65
+ from modules.database.mongo_db import (
66
+ get_collection,
67
+ insert_document,
68
+ find_documents,
69
+ update_document,
70
+ delete_document
71
+ )
72
+
73
+ from modules.database.morphosintax_mongo_db import (
74
+ store_student_morphosyntax_result,
75
+ get_student_morphosyntax_analysis
76
+ )
77
+
78
+ from modules.database.chat_db import (
79
+ store_chat_history,
80
+ get_chat_history
81
+ )
82
+
83
+ from modules.studentact.student_activities_v2 import (
84
+ display_student_progress
85
+ )
86
+
87
+ from modules.auth.auth import (
88
+ authenticate_student,
89
+ register_student,
90
+ update_student_info,
91
+ delete_student
92
+ )
93
+
94
+ from modules.admin.admin_ui import admin_page
95
+
96
+ from modules.chatbot.chatbot import (
97
+ initialize_chatbot,
98
+ process_chat_input
99
+ )
100
+
101
+ print("Configurando p谩gina")
102
+ st.cache_data.clear()
103
+ st.cache_resource.clear()
104
+
105
+ logging.basicConfig(level=logging.INFO)
106
+ logger = logging.getLogger(__name__)
107
+
108
+ @st.cache_resource
109
+ def initialize_nlp_models():
110
+ logger.info("Cargando modelos de spaCy")
111
+ models = load_spacy_models()
112
+ logger.info("Modelos de spaCy cargados exitosamente")
113
+ return models
114
+
115
+ def app_main():
116
+ try:
117
+ logger.info("Entrando en app_main()")
118
+
119
+ # Inicializar el estado de la sesi贸n
120
+ initialize_session_state()
121
+
122
+ # Inicializar conexiones a bases de datos si no se ha hecho
123
+ if 'db_initialized' not in st.session_state:
124
+ st.session_state.db_initialized = initialize_database_connections()
125
+
126
+ # Cargar modelos NLP si no se ha hecho
127
+ if 'nlp_models' not in st.session_state:
128
+ logger.info("Inicializando modelos NLP en la sesi贸n")
129
+ st.session_state.nlp_models = initialize_nlp_models()
130
+ logger.info("Modelos NLP inicializados y almacenados en la sesi贸n")
131
+
132
+ # Configurar la p谩gina inicial si no est谩 configurada
133
+ if 'page' not in st.session_state:
134
+ st.session_state.page = 'login'
135
+
136
+ logger.info(f"P谩gina actual: {st.session_state.page}")
137
+ logger.info(f"Rol del usuario: {st.session_state.role}")
138
+
139
+ # Dirigir el flujo a la interfaz de usuario principal
140
+ logger.info(f"Llamando a ui_main() desde app_main()")
141
+ ui_main()
142
+
143
+ except Exception as e:
144
+ logger.error(f"Error en app_main: {str(e)}", exc_info=True)
145
+ st.error("Se ha producido un error en la aplicaci贸n. Por favor, int茅ntelo de nuevo m谩s tarde.")
146
+ if st.button("Reiniciar aplicaci贸n"):
147
+ st.rerun()
148
+
149
+ if __name__ == "__main__":
150
+ print("Llamando a app_main()")
151
  app_main()