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: diff --git a/README.md b/README.md new file mode 100644 index 00000000..14a336d7 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# 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. 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