Update src/app.py
Browse files- src/app.py +21 -11
src/app.py
CHANGED
@@ -1,16 +1,20 @@
|
|
1 |
# AIdeaText v3
|
2 |
# app.py
|
3 |
import os
|
4 |
-
|
5 |
-
torch.classes.__path__ = [os.path.join(torch.__path__[0], torch.classes.__file__)]
|
6 |
|
7 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
8 |
import sys
|
9 |
|
10 |
from dotenv import load_dotenv
|
11 |
from datetime import datetime
|
12 |
from PIL import Image
|
13 |
-
|
14 |
import logging
|
15 |
|
16 |
# Configuraci贸n b谩sica
|
@@ -112,14 +116,6 @@ from modules.admin.admin_ui import admin_page
|
|
112 |
logging.basicConfig(level=logging.INFO)
|
113 |
logger = logging.getLogger(__name__)
|
114 |
|
115 |
-
def torch_operations():
|
116 |
-
print(torch.__version__)
|
117 |
-
print(torch.cuda.is_available())
|
118 |
-
|
119 |
-
if __name__ == '__main__':
|
120 |
-
torch_thread = threading.Thread(target=torch_operations)
|
121 |
-
torch_thread.start()
|
122 |
-
|
123 |
@st.cache_resource(show_spinner=False)
|
124 |
def initialize_nlp_models():
|
125 |
logger.info("Cargando modelos de spaCy")
|
@@ -127,6 +123,20 @@ def initialize_nlp_models():
|
|
127 |
logger.info("Modelos de spaCy cargados exitosamente")
|
128 |
return models
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
def app_main():
|
131 |
try:
|
132 |
logger.info("Entrando en app_main()")
|
|
|
1 |
# AIdeaText v3
|
2 |
# app.py
|
3 |
import os
|
4 |
+
os.environ['TORCH_DISABLE_MLC'] = '1' # Desactiva la carga de componentes conflictivos
|
|
|
5 |
|
6 |
import streamlit as st
|
7 |
+
from streamlit.runtime.scriptrunner import RerunException
|
8 |
+
|
9 |
+
import torch
|
10 |
+
import threading
|
11 |
+
|
12 |
import sys
|
13 |
|
14 |
from dotenv import load_dotenv
|
15 |
from datetime import datetime
|
16 |
from PIL import Image
|
17 |
+
|
18 |
import logging
|
19 |
|
20 |
# Configuraci贸n b谩sica
|
|
|
116 |
logging.basicConfig(level=logging.INFO)
|
117 |
logger = logging.getLogger(__name__)
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
@st.cache_resource(show_spinner=False)
|
120 |
def initialize_nlp_models():
|
121 |
logger.info("Cargando modelos de spaCy")
|
|
|
123 |
logger.info("Modelos de spaCy cargados exitosamente")
|
124 |
return models
|
125 |
|
126 |
+
# Soluci贸n para el error de torch.classes
|
127 |
+
def _patched_get_module_paths(module):
|
128 |
+
if 'torch' in str(module.__file__):
|
129 |
+
return []
|
130 |
+
return original_get_module_paths(module)
|
131 |
+
|
132 |
+
# Aplicar el parche solo si es necesario
|
133 |
+
try:
|
134 |
+
from streamlit.watcher.local_sources_watcher import get_module_paths as original_get_module_paths
|
135 |
+
import streamlit.watcher.local_sources_watcher
|
136 |
+
streamlit.watcher.local_sources_watcher.get_module_paths = _patched_get_module_paths
|
137 |
+
except ImportError:
|
138 |
+
pass
|
139 |
+
|
140 |
def app_main():
|
141 |
try:
|
142 |
logger.info("Entrando en app_main()")
|