JunYuanNYP commited on
Commit
0bffd35
·
verified ·
1 Parent(s): e8bcff3

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +9 -0
  2. app.py +54 -0
  3. requirements.txt +5 -0
  4. timePrediction.json +0 -0
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.13
2
+
3
+ COPY . .
4
+
5
+ WORKDIR /
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /requirements.txt
8
+
9
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080"]
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ import xgboost as xgb
5
+ import pandas as pd
6
+
7
+ # Load model
8
+ model = xgb.XGBRegressor()
9
+ model.load_model("timePrediction.json")
10
+
11
+ class InputData(BaseModel):
12
+ Quantity: int
13
+ Product_Type: str
14
+
15
+ app = FastAPI()
16
+
17
+ app.add_middleware(
18
+ CORSMiddleware,
19
+ allow_origins=["*"],
20
+ allow_credentials=True,
21
+ allow_methods=["*"],
22
+ allow_headers=["*"],
23
+ )
24
+
25
+ def encode_product(product_type: str):
26
+ product_map = {
27
+ "Lemon Scent Dishwashing Liquid": [1, 0, 0, 0, 0, 0, 0, 0],
28
+ "Antibacterial Dishwashing Gel": [0, 1, 0, 0, 0, 0, 0, 0],
29
+ "Unbleached Baking Paper": [0, 0, 1, 0, 0, 0, 0, 0],
30
+ "Silicone-coated baking sheet": [0, 0, 0, 1, 0, 0, 0, 0],
31
+ "Disposable plastic bag": [0, 0, 0, 0, 1, 0, 0, 0],
32
+ "Lavender air freshener sachet": [0, 0, 0, 0, 0, 1, 0, 0],
33
+ "Mothballs": [0, 0, 0, 0, 0, 0, 1, 0],
34
+ "Air Fryer Paper": [0, 0, 0, 0, 0, 0, 0, 1],
35
+ }
36
+ return product_map.get(product_type, [0]*8)
37
+
38
+ @app.post("/predict")
39
+ def predict(data: InputData):
40
+ features = [data.Quantity] + encode_product(data.Product_Type)
41
+ columns = ['Quantity',
42
+ 'Lemon Scent Dishwashing Liquid',
43
+ 'Antibacterial Dishwashing Gel',
44
+ 'Unbleached Baking Paper',
45
+ 'Silicone-coated baking sheet',
46
+ 'Disposable plastic bag',
47
+ 'Lavender air freshener sachet',
48
+ 'Mothballs',
49
+ 'Air Fryer Paper']
50
+
51
+ X = pd.DataFrame([features], columns=columns)
52
+ pred = model.predict(X)[0]
53
+ return {"predicted_time": float(round(pred, 8))}
54
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ xgboost
4
+ pandas
5
+ scikit-learn
timePrediction.json ADDED
The diff for this file is too large to render. See raw diff