Skip to content

Commit d524914

Browse files
author
arianatan
committed
Fix flake8 warnings (newlines, line wraps, spacing)
1 parent 0869202 commit d524914

23 files changed

+692
-74
lines changed

.DS_Store

8 KB
Binary file not shown.

.flake8

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
max-line-length = 100
3+
extend-ignore = E203, W503
4+
exclude =
5+
.git,
6+
__pycache__,
7+
build,
8+
dist,
9+
.venv,
10+
venv,
11+
fastapi,
12+
env,
13+
model/*.pkl

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/Deploying-a-Scalable-ML-Pipeline-with-FastAPI.iml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

local_api.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import json
2-
31
import requests
42

53
# TODO: send a GET using the URL http://127.0.0.1:8000
6-
r = None # Your code here
4+
r = requests.get("http://127.0.0.1:8000")
75

86
# TODO: print the status code
9-
# print()
7+
print("Status Code:", r.status_code)
108
# TODO: print the welcome message
11-
# print()
12-
13-
9+
print("Result:", r.json().get("message"))
1410

1511
data = {
1612
"age": 37,
@@ -30,9 +26,9 @@
3026
}
3127

3228
# TODO: send a POST using the data above
33-
r = None # Your code here
29+
r = requests.post("http://127.0.0.1:8000/data/", json=data)
3430

3531
# TODO: print the status code
36-
# print()
32+
print("Status Code:", r.status_code)
3733
# TODO: print the result
38-
# print()
34+
print("Result:", r.json().get("result"))

main.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ml.data import apply_label, process_data
88
from ml.model import inference, load_model
99

10+
1011
# DO NOT MODIFY
1112
class Data(BaseModel):
1213
age: int = Field(..., example=37)
@@ -26,21 +27,24 @@ class Data(BaseModel):
2627
hours_per_week: int = Field(..., example=40, alias="hours-per-week")
2728
native_country: str = Field(..., example="United-States", alias="native-country")
2829

29-
path = None # TODO: enter the path for the saved encoder
30+
31+
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
32+
MODEL_DIR = os.path.join(PROJECT_PATH, "model")
33+
34+
path = os.path.join(MODEL_DIR, "encoder.pkl")
3035
encoder = load_model(path)
3136

32-
path = None # TODO: enter the path for the saved model
37+
path = os.path.join(MODEL_DIR, "model.pkl")
3338
model = load_model(path)
3439

35-
# TODO: create a RESTful API using FastAPI
36-
app = None # your code here
40+
app = FastAPI(title="Census Income Inference API", version="1.0.0")
41+
3742

3843
# TODO: create a GET on the root giving a welcome message
3944
@app.get("/")
4045
async def get_root():
4146
""" Say hello!"""
42-
# your code here
43-
pass
47+
return {"message": "Hello from the API!"}
4448

4549

4650
# TODO: create a POST on a different path that does model inference
@@ -65,10 +69,15 @@ async def post_inference(data: Data):
6569
"native-country",
6670
]
6771
data_processed, _, _, _ = process_data(
68-
# your code here
72+
data,
73+
categorical_features=cat_features,
74+
label=None,
75+
training=False,
76+
encoder=encoder,
77+
lb=None,
6978
# use data as data input
7079
# use training = False
7180
# do not need to pass lb as input
7281
)
73-
_inference = None # your code here to predict the result using data_processed
82+
_inference = inference(model, data_processed)
7483
return {"result": apply_label(_inference)}

0 commit comments

Comments
 (0)