AIdeaText commited on
Commit
bb7297c
verified
1 Parent(s): df840e6

Update app.py

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