{"id":16597959,"url":"https://github.com/alexioannides/pycaret-mlops","last_synced_at":"2025-10-29T13:30:32.233Z","repository":{"id":37448909,"uuid":"401645479","full_name":"AlexIoannides/pycaret-mlops","owner":"AlexIoannides","description":"Using PyCaret with Bodywork to deploy ML pipelines to Kuberentes","archived":true,"fork":false,"pushed_at":"2022-06-21T12:30:36.000Z","size":2134,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T07:44:08.237Z","etag":null,"topics":["bodywork","fastapi","kubernetes","machine-learning","mlops","pycaret"],"latest_commit_sha":null,"homepage":"https://www.bodyworkml.com","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexIoannides.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-31T09:28:05.000Z","updated_at":"2024-07-02T19:16:08.000Z","dependencies_parsed_at":"2022-08-19T19:40:06.102Z","dependency_job_id":null,"html_url":"https://github.com/AlexIoannides/pycaret-mlops","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"bodywork-ml/bodywork-serve-model-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIoannides%2Fpycaret-mlops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIoannides%2Fpycaret-mlops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIoannides%2Fpycaret-mlops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexIoannides%2Fpycaret-mlops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexIoannides","download_url":"https://codeload.github.com/AlexIoannides/pycaret-mlops/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238825815,"owners_count":19537133,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bodywork","fastapi","kubernetes","machine-learning","mlops","pycaret"],"created_at":"2024-10-12T00:07:11.391Z","updated_at":"2025-10-29T13:30:26.731Z","avatar_url":"https://github.com/AlexIoannides.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Build with PyCaret, Deploy to Kubernetes with FastAPI and Bodywork\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://bodywork-media.s3.eu-west-2.amazonaws.com/pycaret-mlops/pycaret_with_bodywork.png\"/\u003e\n\u003c/div\u003e\n\nThis short post follows-on from [Moez Ali's tutorial](https://towardsdatascience.com/build-with-pycaret-deploy-with-fastapi-333c710dc786) on how to train a model with [PyCaret](https://pycaret.org) and serve predictions using [FastAPI](https://fastapi.tiangolo.com). We're going to take this one step further and add some MLOps magic by deploying the FastAPI prediction service to a [Kubernetes](https://kubernetes.io) cluster using [Bodywork](https://github.com/bodywork-ml/bodywork-core).\n\n[Bodywork](https://github.com/bodywork-ml/bodywork-core) is a Python package that exposes a CLI for configuring Kubernetes to orchestrate your ML pipelines and deploy your prediction services, without having to build Docker images or learn how to configure Kubernetes.\n\n## 👉🏼 Create a GitHub Repo for the Project\n\nIn the [original post](https://towardsdatascience.com/build-with-pycaret-deploy-with-fastapi-333c710dc786) Moez Ali guides us through the process of training and saving a model using PyCaret and then demonstrates how to use FastAPI to develop a Python module that serves predictions from the model. If you work through the post you should end-up with a project directory that looks something like this,\n\n```text\n|-- pycaret-mlops/\n    |-- diamond-pipeline.pkl\n    |-- serve_predictions.py\n```\n\nCreate a GitHub repo and commit **all** of these file to it. We've worked through this for you and you can find our project repo at [https://github.com/AlexIoannides/pycaret-mlops](https://github.com/AlexIoannides/pycaret-mlops), where we've reproduced all of the training code in the [train_model.ipynb](https://github.com/AlexIoannides/pycaret-mlops/blob/master/train_model.ipynb) notebook, to make life simpler.\n\n## 👉🏼 Install Bodywork\n\n[Bodywork](https://github.com/bodywork-ml/bodywork-core) is a Python package that exposes a CLI for configuring Kubernetes to orchestrate your ML pipelines and deploy your prediction services. Install it using Pip,\n\n```text\n$ pip install bodywork\n```\n\n## 👉🏼 Configure the Kubernetes Deployment\n\nCreate a file called `bodywork.yaml` and add the following,\n\n```yaml\nversion: \"1.1\"\npipeline:\n  name: pycaret-diamond-prices\n  docker_image: bodyworkml/bodywork-core:3.0\n  DAG: serve-predictions\nstages:\n  serve-predictions:\n    executable_module_path: serve_predictions.py\n    requirements:\n      - fastapi==0.68.1\n      - uvicorn==0.15.0\n      - pycaret==2.3.3\n    cpu_request: 1.0\n    memory_request_mb: 500\n    service:\n      max_startup_time_seconds: 600\n      replicas: 1\n      port: 8000\n      ingress: true\nlogging:\n  log_level: INFO\n```\n\nThis requests that two containers (or replicas) running the FastAPI prediction service are created, with automatic load-balancing between them - nice! For more info on what this all these configuration parameters mean, head to the [Bodywork docs](https://bodywork.readthedocs.io/en/latest/).\n\nCommit this file to your Git repo and push to GitHub,\n\n```text\n$ git add bodywork.yaml\n$ git commit -m \"Add bodywork deployment config\"\n$ git push origin master\n```\n\n## 👉🏼 Start a Kubernetes Cluster\n\nIf you don't have a Kubernetes cluster handy, then [download Minikube](https://minikube.sigs.k8s.io/docs/start/) so you can test locally. Then, start and configure a cluster as follows,\n\n```text\n$ minikube start --kubernetes-version=v1.22.6 --addons=ingress --cpus=2 --memory=4g\n```\n\n## 👉🏼 Deploy the Prediction Service to Kubernetes\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://bodywork-media.s3.eu-west-2.amazonaws.com/pycaret-mlops/deploy_pycaret_service.png\"/\u003e\n\u003c/div\u003e\n\n```text\n$ bodywork create deployment https://github.com/AlexIoannides/pycaret-mlops.git\n```\n\nThis will stream the logs to your terminal so you can keep track of progress.\n\n## 👉🏼 Test the Service\n\nFirst create a route to your cluster,\n\n```text\n$ minikube kubectl -- -n ingress-nginx port-forward service/ingress-nginx-controller 8080:80\n```\n\nAnd then use the [test_prediction_service.ipynb](https://github.com/AlexIoannides/pycaret-mlops/blob/master/train_model.ipynb) notebook to test the service using Python.\n\n![jupyter](https://bodywork-media.s3.eu-west-2.amazonaws.com/pycaret-mlops/test_service.png)\n\n## 👉🏼 Where to go from Here\n\n- [Continuous training pipelines with Bodywork](https://bodywork.readthedocs.io/en/latest/quickstart_ml_pipeline/)\n- [Bodywork + MLflow](https://github.com/bodywork-ml/bodywork-pipeline-with-mlflow)\n- [Best practices for engineering ML pipelines](https://github.com/bodywork-ml/ml-pipeline-engineering)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexioannides%2Fpycaret-mlops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexioannides%2Fpycaret-mlops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexioannides%2Fpycaret-mlops/lists"}