From a061b78dbf9039221d40c8e87c6fc2225c237328 Mon Sep 17 00:00:00 2001 From: Purnendu Kar <35493977+purnendukar@users.noreply.github.com> Date: Tue, 6 Jul 2021 23:53:17 +0530 Subject: [PATCH 1/5] Create ReadME --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..39eefea7 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# ML-Ops demo using a FastAPI application + +This repository contains code which demonstrates ML-Ops using a `FastAPI` application which predicts the flower class using the IRIS dataset (https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html) + + +## Setup Project +- Create fork from fork button +- Clone the fork using `git clone https://github.com/purnendukar/mlops-iris` +- Install dependency using `pip3 install -r requirements.txt` + +## Running Project +- Run application using `python3 main.py` +- Run test using `pytest` + +## CI/CD +- `build` (test) for all the pull requests +- `build` (test) and `upload_zip` for all pushes + +## Assignment Tasks +1. Change this README to add your name here: Purnendu Kar. Add and commit changes to a new branch and create a pull request ONLY TO YOUR OWN FORK to see the CI/CD build happening. If the build succeeds, merge the pull request with master and see the CI/CD `upload_zip` take place. +2. Add 2 more unit tests of your choice to `test_app.py` and make sure they are passing. +3. Add one more classifier to startup and use only the one with better accuracy. +4. Add the attribute `timestamp` to the response and return the current time with it. From 724fbf16d1ff4214166b18a8f8ef407bf5c7853e Mon Sep 17 00:00:00 2001 From: Purnendu Kar Date: Tue, 6 Jul 2021 23:58:29 +0530 Subject: [PATCH 2/5] update README file --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 39eefea7..90fa236e 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,23 @@ This repository contains code which demonstrates ML-Ops using a `FastAPI` applic ## Setup Project + - Create fork from fork button - Clone the fork using `git clone https://github.com/purnendukar/mlops-iris` - Install dependency using `pip3 install -r requirements.txt` ## Running Project + - Run application using `python3 main.py` - Run test using `pytest` ## CI/CD + - `build` (test) for all the pull requests - `build` (test) and `upload_zip` for all pushes ## Assignment Tasks + 1. Change this README to add your name here: Purnendu Kar. Add and commit changes to a new branch and create a pull request ONLY TO YOUR OWN FORK to see the CI/CD build happening. If the build succeeds, merge the pull request with master and see the CI/CD `upload_zip` take place. 2. Add 2 more unit tests of your choice to `test_app.py` and make sure they are passing. 3. Add one more classifier to startup and use only the one with better accuracy. From c7c6808263e571edef84ccfcadda728b47695058 Mon Sep 17 00:00:00 2001 From: Purnendu Kar <35493977+purnendukar@users.noreply.github.com> Date: Wed, 7 Jul 2021 00:03:15 +0530 Subject: [PATCH 3/5] update --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 90fa236e..14a336d7 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,15 @@ This repository contains code which demonstrates ML-Ops using a `FastAPI` applic ## Setup Project - - Create fork from fork button - Clone the fork using `git clone https://github.com/purnendukar/mlops-iris` - Install dependency using `pip3 install -r requirements.txt` ## Running Project - - Run application using `python3 main.py` - Run test using `pytest` ## CI/CD - - `build` (test) for all the pull requests - `build` (test) and `upload_zip` for all pushes From 00f69f56e28a1bd698941a9909c0e0533102dbde Mon Sep 17 00:00:00 2001 From: Purnendu Kar Date: Wed, 7 Jul 2021 00:07:11 +0530 Subject: [PATCH 4/5] cicd update --- .github/workflows/cicd.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 57c7e0c1..9a53f70f 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -1,10 +1,10 @@ name: ci-cd -on: pull_request, push +on: [pull_request, push] jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-latest steps: - name: Checkout the repository uses: actions/checkout@v2 @@ -18,9 +18,9 @@ jobs: - name: Run pytest run: | pytest - + upload_zip: - runs-on: ubuntu-latest + runs-on: ubuntu-latest needs: build if: ${{ github.event_name == 'push' }} steps: From c64f805e25ee922174e9b48743d5896b13b0c53e Mon Sep 17 00:00:00 2001 From: Purnendu Kar Date: Wed, 7 Jul 2021 00:25:06 +0530 Subject: [PATCH 5/5] Task 2: add 2 unit test --- test_app.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test_app.py b/test_app.py index 44cb822b..8cadd234 100644 --- a/test_app.py +++ b/test_app.py @@ -18,4 +18,30 @@ def test_pred_virginica(): with TestClient(app) as client: response = client.post('/predict_flower', json=payload) assert response.status_code == 200 - assert response.json() == {'flower_class': "Iris Virginica"} \ No newline at end of file + assert response.json() == {'flower_class': "Iris Virginica"} + + +def test_pred_versicolor(): + payload = { + "sepal_length": 5.8, + "sepal_width": 2.7, + "petal_length": 3.9, + "petal_width": 1.2 + } + with TestClient(app) as client: + response = client.post('/predict_flower', json=payload) + assert response.status_code == 200 + assert response.json() == {'flower_class': "Iris Versicolour"} + + +def test_pred_setosa(): + payload = { + "sepal_length": 4.5, + "sepal_width": 2.3, + "petal_length": 1.3, + "petal_width": 0.3 + } + with TestClient(app) as client: + response = client.post('/predict_flower', json=payload) + assert response.status_code == 200 + assert response.json() == {'flower_class': "Iris Setosa"} \ No newline at end of file