Upload 4 files
Browse files- classifier.pkl +3 -0
- main.py +45 -0
- models.py +7 -0
- requirements.txt +7 -0
classifier.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:96623293ecbd08c7b7dd73b1e5bb8985919aea941b024c478f64ffa15c6355df
|
| 3 |
+
size 2590
|
main.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import imghdr
|
| 2 |
+
from os import name
|
| 3 |
+
from fastapi import FastAPI, Response, UploadFile
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
import time
|
| 6 |
+
import pickle
|
| 7 |
+
import numpy as np
|
| 8 |
+
import uvicorn
|
| 9 |
+
from models import classe
|
| 10 |
+
|
| 11 |
+
app = FastAPI()
|
| 12 |
+
|
| 13 |
+
pickle_in = open("classifier.pkl","rb")
|
| 14 |
+
classifier = pickle.load(pickle_in)
|
| 15 |
+
|
| 16 |
+
@app.get("/")
|
| 17 |
+
def index():
|
| 18 |
+
return {"hello": "FastAPI"}
|
| 19 |
+
|
| 20 |
+
@app.get('/{name}')
|
| 21 |
+
def get_name(name: str):
|
| 22 |
+
return {'message': f'hello, {name}'}
|
| 23 |
+
|
| 24 |
+
@app.post('/predict')
|
| 25 |
+
def predict_species(data: classe):
|
| 26 |
+
Sepal_Length = data.Sepal_Length
|
| 27 |
+
Sepal_Width = data.Sepal_Width
|
| 28 |
+
Petal_Length = data.Petal_Length
|
| 29 |
+
Petal_Width = data.Petal_Width
|
| 30 |
+
|
| 31 |
+
prediction = classifier.predict([[Sepal_Length, Sepal_Width, Petal_Length, Petal_Width]])
|
| 32 |
+
|
| 33 |
+
if prediction[0] == 0:
|
| 34 |
+
species = "setosa"
|
| 35 |
+
elif prediction[0] == 1:
|
| 36 |
+
species = "virginica"
|
| 37 |
+
elif prediction[0] == 2:
|
| 38 |
+
species = "versicolor"
|
| 39 |
+
else:
|
| 40 |
+
species = "unknown"
|
| 41 |
+
|
| 42 |
+
return {'prediction': species}
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|
models.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
|
| 3 |
+
class classe(BaseModel):
|
| 4 |
+
Sepal_Length: float
|
| 5 |
+
Sepal_Width: float
|
| 6 |
+
Petal_Length: float
|
| 7 |
+
Petal_Width: float
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
pydantic
|
| 4 |
+
numpy
|
| 5 |
+
scikit-learn==1.2.2
|
| 6 |
+
tensorflow
|
| 7 |
+
h5py
|