{"id":22864947,"url":"https://github.com/mohsenim/bentoml-deploy-docker","last_synced_at":"2026-05-01T09:32:14.558Z","repository":{"id":238309932,"uuid":"796292460","full_name":"mohsenim/BentoMl-Deploy-Docker","owner":"mohsenim","description":"Serving and Deploying Machine Learning Models with BentoML","archived":false,"fork":false,"pushed_at":"2024-05-05T14:31:35.000Z","size":1904,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T09:46:02.123Z","etag":null,"topics":["bentoml","deployment","docker","machine-learning","rest-api","xgboost"],"latest_commit_sha":null,"homepage":"","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/mohsenim.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-05T14:18:43.000Z","updated_at":"2024-05-05T14:39:08.000Z","dependencies_parsed_at":"2024-05-05T15:46:43.466Z","dependency_job_id":null,"html_url":"https://github.com/mohsenim/BentoMl-Deploy-Docker","commit_stats":null,"previous_names":["mohsenim/bentoml-deploy-docker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mohsenim/BentoMl-Deploy-Docker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsenim%2FBentoMl-Deploy-Docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsenim%2FBentoMl-Deploy-Docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsenim%2FBentoMl-Deploy-Docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsenim%2FBentoMl-Deploy-Docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohsenim","download_url":"https://codeload.github.com/mohsenim/BentoMl-Deploy-Docker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsenim%2FBentoMl-Deploy-Docker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32492162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bentoml","deployment","docker","machine-learning","rest-api","xgboost"],"created_at":"2024-12-13T11:32:07.978Z","updated_at":"2026-05-01T09:32:14.543Z","avatar_url":"https://github.com/mohsenim.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serving and Deploying Machine Learning Models with BentoML\n\nIn this repository, I explore BentoML, an open-source platform for packaging ML models. BentoML provides a straightforward approach for packaging trained models and their associated code and dependencies into a unified distribution format called \"Bento\". This platform supports various deployment options, including serving models as REST APIs, Docker containers, and batch jobs. \n\nThis project focuses on predicting car prices in Germany as a case study. To accomplish this, I use the [Germany Cars Dataset](https://www.kaggle.com/datasets/ander289386/cars-germany). In the [this](https://medium.com/@mohsenim/tracking-machine-learning-experiments-with-mlflow-and-dockerizing-trained-models-germany-car-price-e539303b6f97) post and [this](https://github.com/mohsenim/MLflow-XGBoost-Docker) GitHub repository, I discussed how the dataset was preprocessed and cleaned. We establish a pipeline comprising a preprocessing stage for data preparation, followed by the implementation of an XGBoost model. It's worth noting that alternative models can be seamlessly integrated. XGBoost was selected as an emxaple and for its efficiency and widespread popularity as a machine learning ensemble algorithm. BentoML is used to serve the model and containerize it as a docker image.\n\n\n### Install Dependencies\nEnsure you have installed the necessary libraries by running:\n```\npip install -r requirements.txt\n```\n\n## Running the Experiment Using XGBoost\nTo train a model, run the following command:\n```\npython train.py\n```\n\nUpon completion of the run, the code prints the following results:\n\n```\n\n    Trained! Mean squared error (MSE) of the model: 0.003412174771345764\n    Model german_car_model.pkl is saved in: 'artifacts'.\n```\n\n## Serve the Model\n\n`service.py` serves the trained model as REST APIs. The following command makes the service accessible at the address `http://127.0.0.1:3000/predict`:\n```\nbentoml serve service:CarPricePrediction\n```\n\nTo test the model, requests can be sent to the REST API using the curl command:\n```\ncurl -X 'POST' \\\n  'http://127.0.0.1:3000/predict' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"input_records\": [\n    {\"make\":\"Skoda\", \"model\": \"Fabia\", \"fuel\": \"Gasoline\" ,\"gear\": \"Automatic\", \"offerType\": \"Used\",\"mileage_log\": 1.929419,\"hp\": 95.0 ,\"age\": 0.0}\n  ]\n}'\n```\n\nwhich returns the following result:\n```\n[4.235708236694336]\n```\n\nAs the model is trained to predict the logarithm of price, the output is in logarithmic scale and should be converted back using `10**prediction`.\n\n## Build the Bento and Deploy the Model as s Docker Image\n\nWe can build the Bento by runing:\n```\nbentoml build\n```\n\n![betnoml-build](./fig/build_image.png)\n\nAfter building the Bento, a docker image can be created from the Bento:\n```\nbentoml containerize service:CarPricePrediction\n```\n\n\n## Running the Docker Image\n\nThe above command creates a docker image like `car_price_prediction:7tfbadqjpkt6coaa`. The image can later be run locally, on a server, or on a cloud. To run the docker image locally, you can use this command:\n```\ndocker run --rm -p 3000:3000 car_price_prediction:7tfbadqjpkt6coaa\n```\n\nFor a more detailed explanation of the code, refer to the accompanying Jupyter notebook file, `bentoml-deploy-docker.ipynb`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohsenim%2Fbentoml-deploy-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohsenim%2Fbentoml-deploy-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohsenim%2Fbentoml-deploy-docker/lists"}