Update server.py
Browse files
server.py
CHANGED
@@ -41,17 +41,25 @@ INITIALIZATION_STATUS = {
|
|
41 |
# Global model instance
|
42 |
model = None
|
43 |
|
|
|
44 |
def initialize_model():
|
45 |
-
"""Initialize the model
|
46 |
global model, INITIALIZATION_STATUS
|
47 |
try:
|
48 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
49 |
logger.info(f"Initializing model on device: {device}")
|
50 |
|
51 |
-
|
|
|
|
|
|
|
52 |
if not os.path.exists(model_path):
|
53 |
raise RuntimeError(f"Model path {model_path} does not exist")
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
model = InferenceRecipe(model_path, device=device)
|
56 |
INITIALIZATION_STATUS["model_loaded"] = True
|
57 |
logger.info("Model initialized successfully")
|
@@ -60,7 +68,7 @@ def initialize_model():
|
|
60 |
INITIALIZATION_STATUS["error"] = str(e)
|
61 |
logger.error(f"Failed to initialize model: {e}")
|
62 |
return False
|
63 |
-
|
64 |
@app.on_event("startup")
|
65 |
async def startup_event():
|
66 |
"""Initialize model on startup"""
|
|
|
41 |
# Global model instance
|
42 |
model = None
|
43 |
|
44 |
+
|
45 |
def initialize_model():
|
46 |
+
"""Initialize the model with correct path resolution"""
|
47 |
global model, INITIALIZATION_STATUS
|
48 |
try:
|
49 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
50 |
logger.info(f"Initializing model on device: {device}")
|
51 |
|
52 |
+
# Critical: Use absolute path for model loading
|
53 |
+
model_path = os.path.abspath(os.path.join('/app/src', 'models'))
|
54 |
+
logger.info(f"Loading models from: {model_path}")
|
55 |
+
|
56 |
if not os.path.exists(model_path):
|
57 |
raise RuntimeError(f"Model path {model_path} does not exist")
|
58 |
+
|
59 |
+
# Log available model files for debugging
|
60 |
+
model_files = os.listdir(model_path)
|
61 |
+
logger.info(f"Available model files: {model_files}")
|
62 |
+
|
63 |
model = InferenceRecipe(model_path, device=device)
|
64 |
INITIALIZATION_STATUS["model_loaded"] = True
|
65 |
logger.info("Model initialized successfully")
|
|
|
68 |
INITIALIZATION_STATUS["error"] = str(e)
|
69 |
logger.error(f"Failed to initialize model: {e}")
|
70 |
return False
|
71 |
+
|
72 |
@app.on_event("startup")
|
73 |
async def startup_event():
|
74 |
"""Initialize model on startup"""
|