Commit
·
fce85c0
1
Parent(s):
2795ce6
fix circular call
Browse files
main.py
CHANGED
@@ -16,6 +16,7 @@ import queue
|
|
16 |
import time
|
17 |
from contextlib import contextmanager
|
18 |
import torch
|
|
|
19 |
|
20 |
# Load environment variables
|
21 |
load_dotenv()
|
@@ -34,7 +35,6 @@ log_file = os.path.join(log_dir, 'app.log') # Add log file path
|
|
34 |
# Global variables for model caching and initialization status
|
35 |
global_models = {}
|
36 |
initialization_complete = Event()
|
37 |
-
notification_queue = queue.Queue()
|
38 |
|
39 |
def ensure_directory(path):
|
40 |
"""Create directory and ensure full permissions with better error handling"""
|
@@ -77,14 +77,6 @@ logging.basicConfig(
|
|
77 |
)
|
78 |
logger = logging.getLogger(__name__)
|
79 |
|
80 |
-
def log_print(message, level="INFO"):
|
81 |
-
if level == "INFO":
|
82 |
-
logger.info(message)
|
83 |
-
elif level == "ERROR":
|
84 |
-
logger.error(message)
|
85 |
-
elif level == "WARNING":
|
86 |
-
logger.warning(message)
|
87 |
-
|
88 |
def initialize_resources():
|
89 |
"""Initialize all required resources"""
|
90 |
try:
|
@@ -638,11 +630,9 @@ def get_or_load_model(model_name):
|
|
638 |
raise
|
639 |
return global_models.get(model_name)
|
640 |
|
641 |
-
def wait_for_initialization(
|
642 |
-
"""Wait for initialization to complete
|
643 |
-
|
644 |
-
log_print("Warning: Initialization timed out", "WARNING")
|
645 |
-
return False
|
646 |
return True
|
647 |
|
648 |
# Add this to the compute_marks route before processing files
|
@@ -707,21 +697,14 @@ if __name__ == '__main__':
|
|
707 |
for directory in essential_dirs:
|
708 |
ensure_directory(directory)
|
709 |
|
710 |
-
# Configure server
|
711 |
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
712 |
-
app.config['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024 # 50MB max file size
|
713 |
-
|
714 |
-
# Add additional server configurations
|
715 |
-
app.config['PERMANENT_SESSION_LIFETIME'] = 3600 # 1 hour session lifetime
|
716 |
-
app.config['SESSION_COOKIE_SECURE'] = True
|
717 |
-
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
718 |
|
719 |
-
# Start the Flask app
|
720 |
port = int(os.environ.get('PORT', 7860))
|
721 |
|
722 |
log_print(f"Starting server on port {port}")
|
723 |
log_print("Server configuration:")
|
724 |
-
log_print(f"- Max content length: {app.config['MAX_CONTENT_LENGTH'] / 1024 / 1024}MB")
|
725 |
log_print(f"- Threaded: True")
|
726 |
log_print(f"- Debug mode: False")
|
727 |
|
|
|
16 |
import time
|
17 |
from contextlib import contextmanager
|
18 |
import torch
|
19 |
+
from utils import notification_queue, log_print
|
20 |
|
21 |
# Load environment variables
|
22 |
load_dotenv()
|
|
|
35 |
# Global variables for model caching and initialization status
|
36 |
global_models = {}
|
37 |
initialization_complete = Event()
|
|
|
38 |
|
39 |
def ensure_directory(path):
|
40 |
"""Create directory and ensure full permissions with better error handling"""
|
|
|
77 |
)
|
78 |
logger = logging.getLogger(__name__)
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
def initialize_resources():
|
81 |
"""Initialize all required resources"""
|
82 |
try:
|
|
|
630 |
raise
|
631 |
return global_models.get(model_name)
|
632 |
|
633 |
+
def wait_for_initialization():
|
634 |
+
"""Wait for initialization to complete"""
|
635 |
+
initialization_complete.wait()
|
|
|
|
|
636 |
return True
|
637 |
|
638 |
# Add this to the compute_marks route before processing files
|
|
|
697 |
for directory in essential_dirs:
|
698 |
ensure_directory(directory)
|
699 |
|
700 |
+
# Configure server
|
701 |
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
702 |
|
703 |
+
# Start the Flask app
|
704 |
port = int(os.environ.get('PORT', 7860))
|
705 |
|
706 |
log_print(f"Starting server on port {port}")
|
707 |
log_print("Server configuration:")
|
|
|
708 |
log_print(f"- Threaded: True")
|
709 |
log_print(f"- Debug mode: False")
|
710 |
|
utils.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import queue
|
2 |
+
import logging
|
3 |
+
import sys
|
4 |
+
|
5 |
+
# Create notification queue
|
6 |
+
notification_queue = queue.Queue()
|
7 |
+
|
8 |
+
# Setup logging
|
9 |
+
logging.basicConfig(
|
10 |
+
level=logging.INFO,
|
11 |
+
format='%(asctime)s - %(levelname)s - %(message)s',
|
12 |
+
handlers=[logging.StreamHandler(sys.stdout)]
|
13 |
+
)
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
+
|
16 |
+
def log_print(message, level="INFO"):
|
17 |
+
if level == "INFO":
|
18 |
+
logger.info(message)
|
19 |
+
elif level == "ERROR":
|
20 |
+
logger.error(message)
|
21 |
+
elif level == "WARNING":
|
22 |
+
logger.warning(message)
|