├── .gitignore ├── Procfile ├── mlapi.py ├── requirements.txt ├── rfmodel.pkl └── runtime.txt /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | fastml 3 | sample.json -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn -w 2 -k uvicorn.workers.UvicornWorker mlapi:app -------------------------------------------------------------------------------- /mlapi.py: -------------------------------------------------------------------------------- 1 | # Bring in lightweight dependencies 2 | from fastapi import FastAPI 3 | from pydantic import BaseModel 4 | import pickle 5 | import pandas as pd 6 | 7 | app = FastAPI() 8 | 9 | class ScoringItem(BaseModel): 10 | YearsAtCompany: float #/ 1, // Float value 11 | EmployeeSatisfaction: float #0.01, // Float value 12 | Position:str # "Non-Manager", # Manager or Non-Manager 13 | Salary: int #4.0 // Ordinal 1,2,3,4,5 14 | 15 | with open('rfmodel.pkl', 'rb') as f: 16 | model = pickle.load(f) 17 | 18 | @app.post('/') 19 | async def scoring_endpoint(item:ScoringItem): 20 | df = pd.DataFrame([item.dict().values()], columns=item.dict().keys()) 21 | yhat = model.predict(df) 22 | return {"prediction":int(yhat)} -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicknochnack/CodeThat-FastML/ad4ed7ada622005a06511c1bfda348dd905cef1b/requirements.txt -------------------------------------------------------------------------------- /rfmodel.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicknochnack/CodeThat-FastML/ad4ed7ada622005a06511c1bfda348dd905cef1b/rfmodel.pkl -------------------------------------------------------------------------------- /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.9.7 --------------------------------------------------------------------------------