Skip to content

Commit 5be02aa

Browse files
authored
Merge pull request #32 from IloBe/27-improve-basemodel-handling-of-underscores
27 improve basemodel handling of underscores
2 parents ddb2154 + 5886c40 commit 5be02aa

2 files changed

Lines changed: 46 additions & 16 deletions

File tree

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
[image12]: ./screenshots/MLOps_proj3_Render_webservice_live.PNG "render web service life"
1515
[image13]: ./screenshots/MLOps_proj3_Render_webservice_live_test_status.PNG "render web service test"
1616
[image14]: ./screenshots/live_post.png "render web service script result"
17+
[image15]: ./screenshots/render_auto-deploy_settings.PNG "render deploy settings"
18+
[image16]: ./screenshots/render_deployed_censusproject.PNG "render app deployed"
19+
[image17]: ./screenshots/render_deployed-app_browser-homepage.PNG "render app welcome"
1720

1821

1922
# US Census Data - Creating and Deploying a Classifier Pipeline as Web Service
@@ -152,7 +155,27 @@ As an examples regarding the use case of having a person earning <=50K as income
152155

153156
* Because default render Python version is 3.7 and this version has issues with dvc, the environment variable PYTHON_VERSION has to be configured being version 3.10.9.
154157
* After selection, render starts its advanced deployment configuation, some parameters are already set, some have to be set manually appropriately. Render guides you through with easy to handle UI's.
155-
* That's it. Implement coding changes, push to the GitHub repository, and the app will automatically redeploy each time, but it will only deploy if your continuous integration action passes.
158+
159+
![render deploy settings][image15]
160+
161+
<br>
162+
163+
* That's it. Implement coding changes, push to the GitHub repository, and the app will automatically redeploy each time, but it will only deploy if your continuous integration action passes.
164+
165+
![render app deployed][image16]
166+
167+
<br>
168+
169+
* Regarding the automatically created render census-project app link used as browser link
170+
```
171+
https://census-project-xki0.onrender.com
172+
```
173+
we get the welcome page message
174+
175+
![render app welcome][image17]
176+
177+
<br>
178+
156179
* Have in mind: if you rely on your CI/CD to fail before fixing an issue, it slows down your deployment. Fix issues early, e.g. by running an ensemble linter like flake8 locally before committing changes.
157180
* For checking the render deployment, a python file exists that uses the httpx module to do one GET and POST on the live render web service and prints its results.
158181

src/app/schemas.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Imports
1111
###################
1212

13-
from pydantic import BaseModel
13+
from pydantic import BaseModel, Field
1414
from typing import Optional
1515
from enum import Enum
1616

@@ -19,6 +19,9 @@
1919
# Coding
2020
###################
2121

22+
def hyphen_to_underscore(field_name):
23+
return f"{field_name}".replace("_", "-")
24+
2225
class FeatureLabels(str, Enum):
2326
''' Delivers the feature names as needed in Python '''
2427
age = "age"
@@ -39,17 +42,21 @@ class FeatureLabels(str, Enum):
3942

4043
class Person(BaseModel):
4144
''' Delivers the type hints for feature attributes '''
42-
age: int
43-
workclass: Optional[str] = None
44-
fnlgt: int
45-
education: Optional[str] = None
46-
education_num: int
47-
marital_status: Optional[str] = None
48-
occupation: Optional[str] = None
49-
relationship: Optional[str] = None
50-
race: Optional[str] = None
51-
sex: Optional[str] = None
52-
capital_gain: int
53-
capital_loss: int
54-
hours_per_week: int
55-
native_country: Optional[str] = None
45+
age: int = Field(..., example=45)
46+
capital_gain: int = Field(..., example=2174)
47+
capital_loss: int = Field(..., example=0)
48+
education: str = Field(..., example="Bachelors")
49+
education_num: int = Field(..., example=13)
50+
fnlgt: int = Field(..., example=2334)
51+
hours_per_week: int = Field(..., example=60)
52+
marital_status: str = Field(..., example="Never-married")
53+
native_country: str = Field(..., example="Cuba")
54+
occupation: str = Field(..., example="Prof-specialty")
55+
race: str = Field(..., example="Black")
56+
relationship: str = Field(..., example="Wife")
57+
sex: str = Field(..., example="Female")
58+
workclass: str = Field(..., example="State-gov")
59+
60+
class Config:
61+
alias_generator = hyphen_to_underscore
62+
allow_population_by_field_name = True

0 commit comments

Comments
 (0)