flokabukie
commited on
Commit
•
7bbc3ed
1
Parent(s):
52229d0
Update main.py
Browse files
main.py
CHANGED
@@ -8,18 +8,16 @@ import os
|
|
8 |
from sklearn.preprocessing import StandardScaler
|
9 |
import joblib
|
10 |
|
11 |
-
|
12 |
-
""" Creating the FastAPI Instance. i.e. foundation for our API,
|
13 |
-
which will be the main part of our project"""
|
14 |
|
15 |
app = FastAPI(title="API")
|
16 |
|
17 |
|
18 |
"""We load a machine learning model and a scaler that help us make predictions based on data."""
|
19 |
-
model = joblib.load('
|
20 |
scaler = joblib.load('scaler.pkl',mmap_mode='r')
|
21 |
|
22 |
-
|
23 |
def predict(df, endpoint='simple'):
|
24 |
# Scaling
|
25 |
scaled_df = scaler.transform(df)
|
@@ -39,17 +37,8 @@ def predict(df, endpoint='simple'):
|
|
39 |
return response
|
40 |
|
41 |
|
42 |
-
"""We create models for the data that our API will work with.
|
43 |
-
We define what kind of information the data will have.
|
44 |
-
It's like deciding what information we need to collect and how it should be organized."""
|
45 |
|
46 |
|
47 |
-
"""These classes define the data models used for API endpoints.
|
48 |
-
The 'Patient' class represents a single patient's data,
|
49 |
-
and the 'Patients' class represents a list of patients' data.
|
50 |
-
The Patients class also includes a class method return_list_of_dict()
|
51 |
-
that converts the Patients object into a list of dictionaries"""
|
52 |
-
|
53 |
class Patient(BaseModel):
|
54 |
Blood_Work_R1: float
|
55 |
Blood_Pressure: float
|
@@ -59,10 +48,7 @@ class Patient(BaseModel):
|
|
59 |
Patient_age: int
|
60 |
|
61 |
|
62 |
-
|
63 |
-
It sets up a main page with a specific message, provides a checkup endpoint to receive
|
64 |
-
optional parameters, and sets up prediction endpoints to receive medical data for making predictions,
|
65 |
-
either for a single patient or multiple patients."""
|
66 |
|
67 |
@app.get("/")
|
68 |
def root():
|
|
|
8 |
from sklearn.preprocessing import StandardScaler
|
9 |
import joblib
|
10 |
|
11 |
+
|
|
|
|
|
12 |
|
13 |
app = FastAPI(title="API")
|
14 |
|
15 |
|
16 |
"""We load a machine learning model and a scaler that help us make predictions based on data."""
|
17 |
+
model = joblib.load('model.pkl',mmap_mode='r')
|
18 |
scaler = joblib.load('scaler.pkl',mmap_mode='r')
|
19 |
|
20 |
+
|
21 |
def predict(df, endpoint='simple'):
|
22 |
# Scaling
|
23 |
scaled_df = scaler.transform(df)
|
|
|
37 |
return response
|
38 |
|
39 |
|
|
|
|
|
|
|
40 |
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
class Patient(BaseModel):
|
43 |
Blood_Work_R1: float
|
44 |
Blood_Pressure: float
|
|
|
48 |
Patient_age: int
|
49 |
|
50 |
|
51 |
+
|
|
|
|
|
|
|
52 |
|
53 |
@app.get("/")
|
54 |
def root():
|