Omarelrayes commited on
Commit
82ea932
Β·
verified Β·
1 Parent(s): 1a588c0

Update app/configs.py

Browse files
Files changed (1) hide show
  1. app/configs.py +32 -14
app/configs.py CHANGED
@@ -5,6 +5,7 @@ import tensorflow as tf
5
  from pathlib import Path
6
  from typing import Dict, Any, List
7
  import os
 
8
 
9
  # ======================
10
  # πŸ”₯ Set PYTHONPATH for sitecustomize.py
@@ -61,6 +62,29 @@ print("="*60)
61
  _classification_model = None
62
  _segmentation_model = None
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  # ======================
65
  # Classification Model Loader
66
  # ======================
@@ -74,21 +98,18 @@ def get_classification_model():
74
  print("="*60)
75
 
76
  try:
77
- # πŸ”₯ Download artifacts from MLflow (will use HF Hub via plugin)
78
  local_path = mlflow.artifacts.download_artifacts(
79
  run_id=CLASSIFICATION_RUN_ID,
80
- artifact_path="model",
81
  dst_path="/tmp/mlflow_models/classification"
82
  )
83
 
84
  print(f"πŸ“₯ Downloaded to: {local_path}")
85
 
86
- # πŸ”₯ Load model from local path
87
- model_file = os.path.join(local_path, "data", "model.keras")
88
-
89
- if not os.path.exists(model_file):
90
- raise FileNotFoundError(f"Model file not found: {model_file}")
91
 
 
92
  _classification_model = tf.keras.models.load_model(
93
  model_file,
94
  compile=False
@@ -116,21 +137,18 @@ def get_segmentation_model():
116
  print("="*60)
117
 
118
  try:
119
- # πŸ”₯ Download artifacts from MLflow (will use HF Hub via plugin)
120
  local_path = mlflow.artifacts.download_artifacts(
121
  run_id=SEGMENTATION_RUN_ID,
122
- artifact_path="model",
123
  dst_path="/tmp/mlflow_models/segmentation"
124
  )
125
 
126
  print(f"πŸ“₯ Downloaded to: {local_path}")
127
 
128
- # πŸ”₯ Load model from local path
129
- model_file = os.path.join(local_path, "data", "model.keras")
130
-
131
- if not os.path.exists(model_file):
132
- raise FileNotFoundError(f"Model file not found: {model_file}")
133
 
 
134
  _segmentation_model = tf.keras.models.load_model(
135
  model_file,
136
  compile=False
 
5
  from pathlib import Path
6
  from typing import Dict, Any, List
7
  import os
8
+ import glob
9
 
10
  # ======================
11
  # πŸ”₯ Set PYTHONPATH for sitecustomize.py
 
62
  _classification_model = None
63
  _segmentation_model = None
64
 
65
+ # ======================
66
+ # Helper Function: Find model.keras in directory
67
+ # ======================
68
+ def find_model_file(directory):
69
+ """Search for model.keras in directory and subdirectories"""
70
+ print(f"πŸ” Searching for model.keras in {directory}...")
71
+
72
+ # Search recursively
73
+ matches = glob.glob(os.path.join(directory, "**", "model.keras"), recursive=True)
74
+
75
+ if matches:
76
+ model_file = matches[0]
77
+ print(f"βœ… Found model.keras at: {model_file}")
78
+ return model_file
79
+
80
+ # List all files for debugging
81
+ print(f"πŸ“‚ Files in {directory}:")
82
+ for root, dirs, files in os.walk(directory):
83
+ for file in files:
84
+ print(f" - {os.path.join(root, file)}")
85
+
86
+ raise FileNotFoundError(f"model.keras not found in {directory}")
87
+
88
  # ======================
89
  # Classification Model Loader
90
  # ======================
 
98
  print("="*60)
99
 
100
  try:
101
+ # πŸ”₯ Download ALL artifacts from MLflow
102
  local_path = mlflow.artifacts.download_artifacts(
103
  run_id=CLASSIFICATION_RUN_ID,
 
104
  dst_path="/tmp/mlflow_models/classification"
105
  )
106
 
107
  print(f"πŸ“₯ Downloaded to: {local_path}")
108
 
109
+ # πŸ”₯ Find model.keras in the downloaded files
110
+ model_file = find_model_file(local_path)
 
 
 
111
 
112
+ # πŸ”₯ Load model from local path
113
  _classification_model = tf.keras.models.load_model(
114
  model_file,
115
  compile=False
 
137
  print("="*60)
138
 
139
  try:
140
+ # πŸ”₯ Download ALL artifacts from MLflow
141
  local_path = mlflow.artifacts.download_artifacts(
142
  run_id=SEGMENTATION_RUN_ID,
 
143
  dst_path="/tmp/mlflow_models/segmentation"
144
  )
145
 
146
  print(f"πŸ“₯ Downloaded to: {local_path}")
147
 
148
+ # πŸ”₯ Find model.keras in the downloaded files
149
+ model_file = find_model_file(local_path)
 
 
 
150
 
151
+ # πŸ”₯ Load model from local path
152
  _segmentation_model = tf.keras.models.load_model(
153
  model_file,
154
  compile=False