Yashk0618 commited on
Commit
d434e45
·
1 Parent(s): 40f7cff

updated files

Browse files
Files changed (3) hide show
  1. Dockerfile +14 -0
  2. main.py +57 -0
  3. requirements.txt +5 -0
Dockerfile CHANGED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Helps with some builds
6
+ RUN pip install --no-cache-dir --upgrade pip
7
+
8
+ COPY requirements.txt .
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ COPY . .
12
+
13
+ EXPOSE 7860
14
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py CHANGED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import joblib
4
+ import numpy as np
5
+ import os
6
+
7
+ app = FastAPI()
8
+
9
+ # -------- Load models once at startup --------
10
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
11
+ MODEL_DIR = os.path.join(BASE_DIR, "models")
12
+
13
+ stockout_model = joblib.load(
14
+ os.path.join(MODEL_DIR, "restaurant_stockout_classifier.joblib")
15
+ )
16
+
17
+ wastage_model = joblib.load(
18
+ os.path.join(MODEL_DIR, "restaurant_wastage_regressor.joblib")
19
+ )
20
+
21
+ # -------- Request schema --------
22
+ class PredictRequest(BaseModel):
23
+ features: list[float]
24
+
25
+ # -------- Health check --------
26
+ @app.get("/")
27
+ def root():
28
+ return {
29
+ "status": "ok",
30
+ "message": "ProjectY Classifier + Regressor API is running"
31
+ }
32
+
33
+ # -------- Stockout classifier --------
34
+ @app.post("/predict/stockout")
35
+ def predict_stockout(req: PredictRequest):
36
+ X = np.array([req.features]) # shape: (1, n_features)
37
+ prediction = stockout_model.predict(X)[0]
38
+
39
+ response = {
40
+ "prediction": int(prediction) if isinstance(prediction, (int, np.integer)) else float(prediction)
41
+ }
42
+
43
+ # Optional probabilities (if supported)
44
+ if hasattr(stockout_model, "predict_proba"):
45
+ response["probabilities"] = stockout_model.predict_proba(X)[0].tolist()
46
+
47
+ return response
48
+
49
+ # -------- Wastage regressor --------
50
+ @app.post("/predict/wastage")
51
+ def predict_wastage(req: PredictRequest):
52
+ X = np.array([req.features])
53
+ prediction = wastage_model.predict(X)[0]
54
+
55
+ return {
56
+ "prediction": float(prediction)
57
+ }
requirements.txt CHANGED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi==0.110.0
2
+ uvicorn[standard]==0.27.1
3
+ joblib==1.3.2
4
+ numpy==1.26.4
5
+ scikit-learn==1.4.2