File size: 1,068 Bytes
462423e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import imghdr
from os import name
from fastapi import FastAPI, Response, UploadFile
from pydantic import BaseModel 
import time
import pickle 
import numpy as np 
import uvicorn
from models import classe

app = FastAPI()

pickle_in = open("classifier.pkl","rb")
classifier = pickle.load(pickle_in)

@app.get("/")
def index():
    return {"hello": "FastAPI"}

@app.get('/{name}')
def get_name(name: str):
    return {'message': f'hello, {name}'}

@app.post('/predict')
def predict_species(data: classe):
    Sepal_Length = data.Sepal_Length
    Sepal_Width = data.Sepal_Width
    Petal_Length = data.Petal_Length
    Petal_Width = data.Petal_Width

    prediction = classifier.predict([[Sepal_Length, Sepal_Width, Petal_Length, Petal_Width]])

    if prediction[0] == 0:
        species = "setosa"
    elif prediction[0] == 1:
        species = "virginica"
    elif prediction[0] == 2:
        species = "versicolor"
    else:
        species = "unknown"

    return {'prediction': species}

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