-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
69 lines (58 loc) · 1.82 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
@author: Mbaka JohnPaul
"""
import uvicorn
from fastapi import FastAPI
from Darb import Darb
import numpy as np
import pickle
# starteted modifying
import pandas as pd
from sklearn.model_selection import train_test_split
app = FastAPI()
# # model = joblib.load("random_mod.joblib")
# model_file_path = "random_model-1.pkl"
# # pickle_in = open("random_model-1.pkl","rb")
# # classifier = pickle.load(pickle_in)
# try:
# with open(model_file_path, "rb") as pickle_file:
# classifier = pickle.load(pickle_file,dtype='float64')
# except Exception as e:
# print("Error loading pickled object:", e)
# Started modifying
df = pd.read_csv('diabete.csv')
X = df.drop('class',axis = 1)
y = df['class']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3,random_state=0)
from sklearn.ensemble import RandomForestClassifier
rfc = RandomForestClassifier(n_estimators = 100)
rfc.fit(X_train,y_train)
# Set the check_input parameter to False to suppress the warning during prediction
rfc.check_input = False
@app.get('/')
def index():
return {'message': 'Hello, welcome to Darb-API'}
@app.head("/items/{item_id}")
async def get_item_headers(item_id: int):
# Do whatever processing you need for HEAD requests
# In this example, we're just returning an empty response
return {}
@app.post('/predict')
def predict_diabetes(data:Darb):
data = data.dict()
preg = data['preg']
plas = data['plas']
pres = data['pres']
skin = data['skin']
insu = data['insu']
mass = data['mass']
pedi = data['pedi']
age = data['age']
prediction = rfc.predict([[preg,plas,pres,skin,insu,mass,pedi,age]])
return{
'prediction': str(prediction)
}
if __name__ == '__main__':
uvicorn.run(app, host='127.0.0.1', port= 8000)
else:
uvicorn.run(app, host="0.0.0.0", port=8000)