cerkut commited on
Commit
e4ace22
1 Parent(s): 89bed0b

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +15 -0
  2. lr_api.pkl +3 -0
  3. lr_api.py +29 -0
  4. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ FROM python:3.8-slim
4
+
5
+ WORKDIR /app
6
+
7
+ ADD . /app
8
+
9
+ RUN apt-get update && apt-get install -y libgomp1
10
+
11
+ RUN pip install -r requirements.txt
12
+
13
+ EXPOSE 8000
14
+
15
+ CMD ["python", "lr_api.py"]
lr_api.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b8456656657111aa1a380cb259b8aa4078cc70ab2aa976ee1653ec53bc21b9ce
3
+ size 7020
lr_api.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import pandas as pd
4
+ from pycaret.classification import load_model, predict_model
5
+ from fastapi import FastAPI
6
+ import uvicorn
7
+ from pydantic import create_model
8
+
9
+ # Create the app
10
+ app = FastAPI()
11
+
12
+ # Load trained Pipeline
13
+ model = load_model("lr_api")
14
+
15
+ # Create input/output pydantic models
16
+ input_model = create_model("lr_api_input", **{'Id': 216, 'WeekofPurchase': 265, 'StoreID': 7, 'PriceCH': 1.8600000143051147, 'PriceMM': 2.130000114440918, 'DiscCH': 0.3700000047683716, 'DiscMM': 0.0, 'SpecialCH': 1, 'SpecialMM': 0, 'LoyalCH': 0.974931001663208, 'SalePriceMM': 2.130000114440918, 'SalePriceCH': 1.4900000095367432, 'PriceDiff': 0.6399999856948853, 'Store7': 'Yes', 'PctDiscMM': 0.0, 'PctDiscCH': 0.19892500340938568, 'ListPriceDiff': 0.27000001072883606, 'STORE': 0})
17
+ output_model = create_model("lr_api_output", prediction='CH')
18
+
19
+
20
+ # Define predict function
21
+ @app.post("/predict", response_model=output_model)
22
+ def predict(data: input_model):
23
+ data = pd.DataFrame([data.dict()])
24
+ predictions = predict_model(model, data=data)
25
+ return {"prediction": predictions["prediction_label"].iloc[0]}
26
+
27
+
28
+ if __name__ == "__main__":
29
+ uvicorn.run(app, host="127.0.0.1", port=8000)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ pycaret
3
+ fastapi
4
+ uvicorn