-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.py
37 lines (25 loc) · 1019 Bytes
/
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
# This is the app.py file created using FastApi!!
# Run this file using uvicorn app:app --reload
from fastapi import FastAPI, File, UploadFile
import uvicorn
import pandas as pd
import pickle
app = FastAPI()
PATH = 'classifier.pkl'
with open(PATH, 'rb') as file:
classifier = pickle.load(file)
@app.post("/predict/{variance,skewness,curtosis,entropy}")
def predict(variance: float, skewness: float, curtosis: float, entropy: float):
labels = [variance, skewness, curtosis, entropy]
features = [[variance, skewness, curtosis, entropy]]
to_predict = pd.DataFrame(features, columns=labels)
prediction = classifier.predict(to_predict)
return {"predicted value:": int(prediction)}
@app.post("/predict_file")
async def predict_file(file: UploadFile = File(...)):
dataframe = pd.read_csv(file.file)
prediction = classifier.predict(dataframe)
print(prediction)
return {"prediction": str(prediction)}
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=8000)