Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 27 additions & 1 deletion test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
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"}