Update app.py
Browse files
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 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
st.
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
logger.info(f"
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
ui_main()
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
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()
|