madchavez commited on
Commit
efa4e2a
·
1 Parent(s): 48194a4

Configure FastAPI Docker Space

Browse files
Files changed (3) hide show
  1. Dockerfile +3 -5
  2. README.md +4 -6
  3. serving/api.py +14 -1
Dockerfile CHANGED
@@ -2,14 +2,12 @@ FROM python:3.12-slim
2
 
3
  WORKDIR /app
4
 
5
- COPY pyproject.toml uv.lock ./
6
 
7
  RUN pip install --no-cache-dir uv \
8
  && uv pip install --system . \
9
  && uv pip install --system pytest pytest-cov
10
 
11
- COPY . .
12
-
13
- EXPOSE 8000
14
 
15
- CMD ["uvicorn", "serving.api:app", "--host", "0.0.0.0", "--port", "8000"]
 
2
 
3
  WORKDIR /app
4
 
5
+ COPY . .
6
 
7
  RUN pip install --no-cache-dir uv \
8
  && uv pip install --system . \
9
  && uv pip install --system pytest pytest-cov
10
 
11
+ EXPOSE 7860
 
 
12
 
13
+ CMD ["uvicorn", "serving.api:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,12 +1,10 @@
1
  ---
2
- title: MLOps End2end MSDS2026
3
- emoji: 💻
4
  colorFrom: blue
5
  colorTo: green
6
- sdk: gradio
7
- sdk_version: "4.42.0"
8
- python_version: "3.12"
9
- app_file: app.py
10
  pinned: false
11
  ---
12
 
 
1
  ---
2
+ title: MLOps End2end API
3
+ emoji: 🚀
4
  colorFrom: blue
5
  colorTo: green
6
+ sdk: docker
7
+ app_port: 7860
 
 
8
  pinned: false
9
  ---
10
 
serving/api.py CHANGED
@@ -43,7 +43,10 @@ def _load_artifacts() -> None:
43
  if META_PATH.exists():
44
  meta = json.loads(META_PATH.read_text())
45
  _feature_cols = meta["feature_cols"]
46
- _scaler = joblib.load(meta["scaler_path"])
 
 
 
47
  else:
48
  raise RuntimeError("feature_meta.json not found — run the Dagster pipeline first.")
49
 
@@ -88,6 +91,16 @@ def health() -> dict:
88
  return {"status": "ok", "model_loaded": _model is not None}
89
 
90
 
 
 
 
 
 
 
 
 
 
 
91
  @app.get("/info")
92
  def model_info() -> dict:
93
  if INFO_PATH.exists():
 
43
  if META_PATH.exists():
44
  meta = json.loads(META_PATH.read_text())
45
  _feature_cols = meta["feature_cols"]
46
+ scaler_path = Path(meta["scaler_path"])
47
+ if not scaler_path.exists():
48
+ scaler_path = MODELS_DIR / scaler_path.name
49
+ _scaler = joblib.load(scaler_path)
50
  else:
51
  raise RuntimeError("feature_meta.json not found — run the Dagster pipeline first.")
52
 
 
91
  return {"status": "ok", "model_loaded": _model is not None}
92
 
93
 
94
+ @app.get("/")
95
+ def root() -> dict:
96
+ return {
97
+ "service": "Computer Durability Classifier API",
98
+ "health": "/health",
99
+ "docs": "/docs",
100
+ "predict": "/predict",
101
+ }
102
+
103
+
104
  @app.get("/info")
105
  def model_info() -> dict:
106
  if INFO_PATH.exists():