Код: Выделить всё
Basemodel
Код: Выделить всё
from fastapi import FastAPI
import uvicorn
from pydantic import BaseModel
import pandas as pd
from typing import List
class Inputs(BaseModel):
f1: float,
f2: float,
f3: str
@app.post('/predict')
def predict(features: List[Inputs]):
output = []
# loop the list of input features
for data in features:
result = {}
# Convert data into dict() and then into a DataFrame
data = data.dict()
df = pd.DataFrame([data])
# get predictions
prediction = classifier.predict(df)[0]
# get probability
probability = classifier.predict_proba(df).max()
# assign to dictionary
result["prediction"] = prediction
result["probability"] = probability
# append dictionary to list (many outputs)
output.append(result)
return output
Подробнее здесь: https://stackoverflow.com/questions/718 ... -using-fas