Skip to content

Commit a88c89c

Browse files
authored
Merge pull request #25 from IloBe/10-api-deployment-to-a-cloud-application-platform
Feat: deploy api code and test script
2 parents 4a6fe6f + b3973ae commit a88c89c

9 files changed

Lines changed: 27 additions & 17 deletions

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[//]: # (Image References)
22
[image0]: ./screenshots/MLOps_proj3_tree.PNG "proj3 structure"
3-
[image1]: ./screenshots/MLOps_proj3_FastAPI_gitHubPrecommitHook.PNG "github action"
3+
[image1]: ./screenshots/continuous_deployment.png "github action"
44
[image2]: ./plots/numFeats_outlierDist_sex_boxplot.png "feat dist by sex plot"
55
[image3]: ./plots/general_dist_age-hoursPerWeek_boxplot.png "hours-per-week by age boxplots"
66
[image4]: ./plots/salary_dist_hoursPerWeek-age-sex_plot.png "salary dist by age sex plot"
77
[image5]: ./plots/capitalGain_dist_age-hoursPerWeek-sex_plot.png "capital gain dist by hours-per-week sex"
88
[image6]: ./plots/sex_plot.png "sex plot"
99
[image7]: ./screenshots/education-group_people-count.PNG "education people count"
1010
[image8]: ./plots/eduLevel_dist_age-race_plot.png "education level grouping by age race"
11-
[image9]: ./screenshots/MLOps_proj3_FastAPI_docsPredictPersonIncomeNegativeExample.PNG "fastapi income negative"
11+
[image9]: ./screenshots/example.PNG "fastapi income negative"
1212
[image10]: ./screenshots/MLOps_proj3_FastAPI_docsPredictPersonIncomeNegativeExample_ResponseCode.PNG "fastapi income negative response"
13-
[image11]: ./screenshots/render_createNewWebService.PNG "render web service"
14-
[image12]: ./
15-
[image13]: ./
16-
[image14]: ./
13+
[image11]: ./screenshots/MLOps_proj3_Render_createNewWebService.PNG "render web service"
14+
[image12]: ./screenshots/MLOps_proj3_Render_webservice_live.PNG "render web service life"
15+
[image13]: ./screenshots/MLOps_proj3_Render_webservice_live_test_status.PNG "render web service test"
16+
[image14]: ./screenshots/live_post.png "render web service script result"
1717

1818

1919
# US Census Data - Creating and Deploying a Classifier Pipeline as Web Service
@@ -123,9 +123,9 @@ There in "__main__" it calls
123123
```
124124

125125
Remember, this code is for development purpose, in production the reload option shall be set to False resp. not used. In other words, the start command e.g. on our render deployment web service (see below) is:<br>
126-
uvicorn src.main:app
126+
uvicorn src.main:app --host 0.0.0.0 --port 8000
127127

128-
* So , we start the browser web application with
128+
* So, locally we start our implemented browser web application with
129129

130130
```
131131
http://127.0.0.1:8000/docs
@@ -156,6 +156,13 @@ As an examples regarding the use case of having a person earning <=50K as income
156156
* 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.
157157
* 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.
158158

159+
On the Render web service site,
160+
![render web service life][image12]
161+
<br>
162+
![render web service test][image13]
163+
<br>
164+
![render web service script result][image14]
165+
159166

160167
## License
161168
This project coding is released under the [MIT](https://github.com/IloBe/US_CensusData_Classifier_PipelineWithDeployment/blob/master/LICENSE.txt) license.
File renamed without changes.
15.8 KB
Loading
4.57 KB
Loading
File renamed without changes.

screenshots/MLOps_proj3_FastAPI_docsPredictPersonIncomeNegativeExample.PNG renamed to screenshots/example.PNG

File renamed without changes.

screenshots/live_post.png

11.8 KB
Loading

src/httpx_render.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
}
2323

2424
# GET, check first feature attribute
25-
response = httpx.get('https://census-project-xki0.onrender.com/feature_info/age')
26-
print(response.status_code)
27-
print(response.json())
25+
response = httpx.get('https://census-project-xki0.onrender.com/feature_labels/age')
26+
print('--- Render census-project feature GET life service test ---')
27+
print(f'response status code: {response.status_code}')
28+
print(f'response json value: {response.json()}\n')
2829

2930
# POST, check given sample
30-
response = httpx.post('https://census-project-xki0.onrender.com/predict/', data=sample)
31-
print(response.status_code)
32-
print(response.content)
31+
print('--- Render census-project person data POST life service test ---')
32+
response = httpx.post('https://census-project-xki0.onrender.com/predict/',
33+
json=sample)
34+
print(f'response status code: {response.status_code}')
35+
print(f'response content:\n{response.content}')

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def raw_test_data() -> pd.DataFrame:
4646
4747
Returns:
4848
Subset dataframe with 1500 rows loaded from original csv file
49-
"""
49+
"""
5050
try:
5151
# data = './df_test_1500raw.csv'
5252
ROOT = os.getcwd()
53-
filepath = os.path.join(ROOT, config_file['etl']['test_data_orig_census'])
53+
filepath = os.path.join(ROOT, config_file['etl']['test_data_orig_census'])
5454
return pd.read_csv(filepath)
5555
except Exception as e:
5656
pytest.fail(f"Fixture with 1500 orig rows: exc: {e}")
@@ -67,7 +67,7 @@ def cleaned_test_data() -> pd.DataFrame:
6767
try:
6868
# data = './df_test_1500raw.csv'
6969
ROOT = os.getcwd()
70-
filepath = os.path.join(ROOT, config_file['etl']['test_data_orig_census'])
70+
filepath = os.path.join(ROOT, config_file['etl']['test_data_orig_census'])
7171
return clean_data(pd.read_csv(filepath)[:200], config_file)
7272
except Exception as e:
7373
pytest.fail(f"Fixture with 200 cleaned rows: exc: {e}")

0 commit comments

Comments
 (0)