{"id":26270749,"url":"https://github.com/emapco/digitclassificationapi","last_synced_at":"2026-04-07T23:31:22.836Z","repository":{"id":184166258,"uuid":"495504494","full_name":"emapco/DigitClassificationAPI","owner":"emapco","description":"Digit classification model deployed on a flask API.","archived":false,"fork":false,"pushed_at":"2022-05-25T17:52:02.000Z","size":259,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T06:17:01.962Z","etag":null,"topics":["flask","flask-api","jupyter-notebook","machine-learning","python","typescript","vue"],"latest_commit_sha":null,"homepage":"","language":"Python","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/emapco.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}},"created_at":"2022-05-23T17:14:08.000Z","updated_at":"2022-05-25T17:52:05.000Z","dependencies_parsed_at":"2023-07-27T10:40:48.831Z","dependency_job_id":null,"html_url":"https://github.com/emapco/DigitClassificationAPI","commit_stats":null,"previous_names":["emapco/digitclassificationapi"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/emapco/DigitClassificationAPI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emapco%2FDigitClassificationAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emapco%2FDigitClassificationAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emapco%2FDigitClassificationAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emapco%2FDigitClassificationAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emapco","download_url":"https://codeload.github.com/emapco/DigitClassificationAPI/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emapco%2FDigitClassificationAPI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31533823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["flask","flask-api","jupyter-notebook","machine-learning","python","typescript","vue"],"created_at":"2025-03-14T06:17:03.851Z","updated_at":"2026-04-07T23:31:22.813Z","avatar_url":"https://github.com/emapco.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Single Digit Machine Learning Model API\nK nearest neighbors classification and random forest classification models were trained using the MNIST digits classification dataset.\n\nThe models were implemented in python 3 using the scikit-learn library. In \nparticular, the `KNeighborsClassifier` and `RandomForestClassifier` classes were used.\n\nThese two models were chosen since they were the best performing (the highest \nscores against the test dataset) out of the four models tested. Afterwards, \nthe two models' hyperparameters were fined tuned using the `GridSearchCV` class.\n\n- KNeighborsClassifier optimized hyperparameters\n  - algorithm='kd_tree'\n  - leaf_size=10\n  - n_neighbors=4\n  - weights='distance'\n\n- RandomForestClassifier optimized hyperparameters\n  -  class_weight='balanced'\n  - criterion='gini'\n  - max_features='sqrt'\n  - n_estimators=700\n\nThe application's frontend client codebase (written with Vue.js) is located in \nthe `/client` subdirectory. The machine learning model source code is located \nin the `/model` subdirectory. The api codebase is in the root `/` directory.\n\n![client](https://user-images.githubusercontent.com/4152448/169880815-70fb81f2-2902-42c9-a74b-1fde0714e69f.png)\n\n\n## Start the flask API\nIn the terminal while in the root project directory run:\n```sh\npython3 -m flask run\n```\n\n\n## API Documentation\n\n### API endpoint: POST `/api/file`\n  Send a request with a `\u003cform\u003e` marked with\n  `enctype=\"multipart/form-data\"`.\n  Within the form, include a `\u003cinput type=file\n  name=image\u003e` tag that contains the binary image file. The\n  response is encoded in JSON.\n\n#### Python 3\n```python\nimport requests\n\nURL = 'http://127.0.0.1:5000/api/file'\nwith open('img.png', 'rb') as file:\n    files = {'image': file}\n    response = requests.post(URL, files=files)\n```\n\n#### JavaScript/TypeScript\n```javascript\nURL = 'http://127.0.0.1:5000/api/file'\nasync function uploadFile(form: HTMLFormElement) {\n   const data = new FormData(form);\n   const response = await fetch(FILE_URL, {\n     method: \"POST\",\n     mode: \"cors\",\n     body: data\n   });\n   return response.json();\n}\n```\n\n\n### API endpoint: POST \u003ccode\u003e/api/data\u003c/code\u003e\nSend a request with a base64 encoded image in the payload data. The response is encoded in JSON.\n\n#### Python 3\n```python\nimport base64\nimport requests\n\nURL = 'http://127.0.0.1:5000/api/data'\nwith open('img.png', 'rb') as file:\n    b64_img_str = base64.b64encode(file.read())\n    response = requests.post(url, data=b64_img_str)\n```\n\n#### JavaScript/TypeScript\n```javascript\nURL = 'http://127.0.0.1:5000/api/data'\nasync function uploadImageData(b64EncodedImage: string) {\n   const response = await fetch(URL, {\n     method: \"POST\",\n     mode: \"cors\",\n     body: b64EncodedString\n   });\nreturn response.json();\n}\n```\n\n### Example JSON Response\n```json\n{\n  \"models\": [\n    {\n      \"name\": \"K Neighbors\",\n      \"prediction\": 3,\n      \"probabilities\": {\n        \"0\": 0.0,\n        \"1\": 0.0,\n        \"2\": 0.0,\n        \"3\": 1.0,\n        \"4\": 0.0,\n        \"5\": 0.0,\n        \"6\": 0.0,\n        \"7\": 0.0,\n        \"8\": 0.0,\n        \"9\": 0.0\n      }\n    },\n    {\n      \"name\": \"Random Forest\",\n      \"prediction\": 3,\n      \"probabilities\": {\n        \"0\": 0.03,\n        \"1\": 0.06,\n        \"2\": 0.11,\n        \"3\": 0.35,\n        \"4\": 0.07,\n        \"5\": 0.18,\n        \"6\": 0.02,\n        \"7\": 0.04,\n        \"8\": 0.07,\n        \"9\": 0.06\n      }\n    }\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femapco%2Fdigitclassificationapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femapco%2Fdigitclassificationapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femapco%2Fdigitclassificationapi/lists"}