Skip to content

Instantly share code, notes, and snippets.

@sahasourav17
Created September 23, 2022 13:25
Show Gist options
  • Save sahasourav17/6caf09cf24131861626bb915d6ce7e72 to your computer and use it in GitHub Desktop.
Save sahasourav17/6caf09cf24131861626bb915d6ce7e72 to your computer and use it in GitHub Desktop.
from typing import Union
import uvicorn
import numpy as np
import pandas as pd
import pickle as pk
from sklearn.linear_model import LogisticRegression
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class ScoringItem(BaseModel):
qs1: int
qs2: int
qs3: int
qs4: int
qs5: int
qs6: int
qs7: int
qs8: int
with open('mlmodel.pkl','rb') as f:
model = pk.load(f)
@app.post("/")
async def func(item:ScoringItem):
X_new = np.array([list(item.dict().values())])
yhat = model.predict(X_new)[0]
return {"prediction":str(yhat)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment