Skip to content

Commit 328a7d6

Browse files
fix: Docker build issues with model loading
- Remove mlruns dependency from Dockerfile - Add fallback model loading for Docker environment - Create simple pickle models for container deployment
1 parent 6822ea4 commit 328a7d6

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

Dockerfile.azure

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ ENV PATH=/root/.local/bin:$PATH
3636
# Copy application code
3737
COPY src/ ./src/
3838
COPY data/ ./data/
39-
COPY mlruns/ ./mlruns/
39+
COPY models/ ./models/
4040

41-
# Create monitoring directory
42-
RUN mkdir -p monitoring
41+
# Create necessary directories
42+
RUN mkdir -p monitoring mlruns
4343

4444
# Set environment variables for Azure
4545
ENV PYTHONPATH=/app

src/api/model_loader.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ def load_best_model(self) -> bool:
9292

9393
except Exception as e:
9494
print(f"❌ Failed to load model: {e}")
95+
96+
# Fallback: Try to load simple pickle models (for Docker)
97+
print("🔄 Attempting simple pickle model loading...")
98+
try:
99+
with open("models/model.pkl", 'rb') as f:
100+
self.model = pickle.load(f)
101+
102+
# Set default values
103+
self.model_name = "iris_simple_model"
104+
self.model_version = "1"
105+
self.class_names = ["setosa", "versicolor", "virginica"]
106+
107+
print("✅ Simple pickle model loaded successfully")
108+
return True
109+
except Exception as simple_error:
110+
print(f"❌ Simple pickle loading also failed: {simple_error}")
111+
95112
return False
96113

97114
def _load_scaler(self) -> None:
@@ -106,6 +123,14 @@ def _load_scaler(self) -> None:
106123
print("⚠️ Scaler not found, predictions may be inaccurate")
107124
except Exception as e:
108125
print(f"⚠️ Failed to load scaler: {e}")
126+
127+
# Fallback: Try to load simple scaler (for Docker)
128+
try:
129+
with open("models/scaler.pkl", 'rb') as f:
130+
self.scaler = pickle.load(f)
131+
print("✅ Simple scaler loaded successfully")
132+
except Exception as scaler_error:
133+
print(f"⚠️ Simple scaler loading also failed: {scaler_error}")
109134

110135
def predict(self, features: List[List[float]]) -> Tuple[List[str], List[List[float]]]:
111136
"""

0 commit comments

Comments
 (0)