File size: 868 Bytes
ff5c136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
import pickle
import pandas as pd

app = FastAPI()

class scoring_item(BaseModel):
    battery_power: float
    px_height: float
    px_width: float
    ram: float

with open("model.pkl", "rb") as f:
    model = pickle.load(f)

@app.post('/predict')
def scoring_endpoint(item:scoring_item):
    df = pd.DataFrame([item.dict().values()], columns=item.dict().keys())
    ypred = model.predict(df)
    return int(ypred)

"""@app.get('/Welcome')
def get_name(name: str):
    return {'Brace yourself, ': f'{name}'}"""

"""if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1',port=8000)"""