Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Four lecture #1

Merged
merged 15 commits into from
Oct 29, 2022
Prev Previous commit
Next Next commit
added prediction route
  • Loading branch information
renansantosmendes committed Oct 24, 2022
commit 4d70532bd833c414052dc4857c12a757883427be
27 changes: 27 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import os
import pickle
import numpy as np
from fastapi import FastAPI
from pydantic import BaseModel


class Data(BaseModel):
baseline_value: float
accelerations: float
fetal_movement: float
uterine_contractions: float
light_decelerations: float
severe_decelerations: float
prolongued_decelerations: float


def load_models():
Expand All @@ -20,3 +32,18 @@ def load_models():
@app.get('/')
def home():
return {"Hello": "World"}


@app.post('/api/predict')
def predict(request: Data):
received_data = np.array([
request.baseline_value,
request.accelerations,
request.fetal_movement,
request.uterine_contractions,
request.light_decelerations,
request.severe_decelerations,
request.prolongued_decelerations
]).reshape(1, -1)
prediction = model.predict(scaler.transform(received_data))[0]
return {'prediction': prediction}