-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml_api.py
50 lines (41 loc) · 1.15 KB
/
ml_api.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# imports
import uvicorn
from fastapi import FastAPI
from FeaturesNote import FeatureNote
import pickle
import json
import numpy as np
import pandas as pd
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins = ['*'],
allow_credentials = True,
allow_methods = ['*'],
allow_headers = ['*'],
)
pickle_in = open('bike_price_predictor.sav', 'rb')
rf = pickle.load(pickle_in)
params = '''bike_name city kms_driven owner age power brand'''
# index func - route('/')
@app.get('/')
def index():
return {'message': 'This API is for two wheeler'}
@app.post('/bike-predict')
def predict_price(data: FeatureNote):
data = data.dict()
print(data)
bike_name = data['bike_name']
city = data['city']
kms_driven = data['kms_driven']
owner = data['owner']
age = data['age']
power = data['power']
brand = data['age']
bike_price_prediction = rf.predict([[bike_name, city, kms_driven, owner, age, power, brand]])
return {
'bike_price_prediction': bike_price_prediction[0]
}
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port=8000)