{"id":14957606,"url":"https://github.com/sashido/content-moderation-image-api","last_synced_at":"2025-05-02T07:32:12.639Z","repository":{"id":49291923,"uuid":"267060254","full_name":"SashiDo/content-moderation-image-api","owner":"SashiDo","description":"An NSFW Image Classification REST API for effortless Content Moderation built with Node.js, Tensorflow, and Parse Server","archived":false,"fork":false,"pushed_at":"2021-06-19T19:28:21.000Z","size":129,"stargazers_count":70,"open_issues_count":2,"forks_count":21,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-11-12T16:02:41.300Z","etag":null,"topics":["api","express","express-js","node","node-api","node-js","nodejs","nsfw","nsfw-app","nsfw-classifier","nsfw-detection","nsfw-recognition","parse-community","parse-platform","parse-sdk","parse-server","tensorflow","tensorflow-examples","tensorflow-js","tensorflow-tutorials"],"latest_commit_sha":null,"homepage":"https://blog.sashido.io/content-moderation-service-with-nodejs-tensorflowjs-and-reactjs-part-1-restful-api-service/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SashiDo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-26T14:08:24.000Z","updated_at":"2024-11-10T04:59:43.000Z","dependencies_parsed_at":"2022-09-14T17:23:28.851Z","dependency_job_id":null,"html_url":"https://github.com/SashiDo/content-moderation-image-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SashiDo%2Fcontent-moderation-image-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SashiDo%2Fcontent-moderation-image-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SashiDo%2Fcontent-moderation-image-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SashiDo%2Fcontent-moderation-image-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SashiDo","download_url":"https://codeload.github.com/SashiDo/content-moderation-image-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224305847,"owners_count":17289446,"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":["api","express","express-js","node","node-api","node-js","nodejs","nsfw","nsfw-app","nsfw-classifier","nsfw-detection","nsfw-recognition","parse-community","parse-platform","parse-sdk","parse-server","tensorflow","tensorflow-examples","tensorflow-js","tensorflow-tutorials"],"created_at":"2024-09-24T13:15:13.909Z","updated_at":"2024-11-12T16:04:02.089Z","avatar_url":"https://github.com/SashiDo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Ready-to-use Node.JS REST API for classification of indecent images.\n\nMachine Learning has already matured to the point where it should be a vital part of projects of all sizes. Advances in computer processing power, storage, data tools, web, etc made machine learning technologies to become more and more affordable. This and the constant strive for innovation, led SashiDo's team to create a **fully-functional Content Moderation Service with React based Admin Panel** built with Open-Source tools and libraries only. The result is a simple and elegant product, which is easy to maintain, can be integrated into any Node.JS project and hosted anywhere. One at a time, we will share all three layers of the Content moderation service - API, Automation Engine and beautiful Admin Panel. The content moderation REST API is just the first chunk.\n\u003cbr /\u003e\n\n## Examples \u0026 Demos\n\nThese are the examples and the demos of what you'll have in your tools set after you deploy and integrate this repo in your projects. We've prepared examples only for some of the classes. For the other classes we think you should experiment by yourself ... `you know what I mean ;)`.\n\n\u003ctable align=\"center\"\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth align=\"center\"\u003eImage Source\u003c/th\u003e\n      \u003cth align=\"center\"\u003eImage Source\u003c/th\u003e\n      \u003cth align=\"center\"\u003eImage Source\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003ca\n          href=\"https://nsfw-demo.sashido.io/api/image/classify?url=https://nsfw-demo.sashido.io/neutral.png\"\u003e\n          \u003cimage\n            src=\"https://nsfw-demo.sashido.io/neutral.png\" /\u003e\n        \u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003ca\n          href=\"https://nsfw-demo.sashido.io/api/image/classify?url=https://nsfw-demo.sashido.io/sexy.png\"\u003e\n          \u003cimage\n            src=\"https://nsfw-demo.sashido.io/sexy.png\" /\u003e\n        \u003c/a\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003ca\n          href=\"https://nsfw-demo.sashido.io/api/image/classify?url=https://nsfw-demo.sashido.io/drawing.png\"\u003e\n          \u003cimage\n            src=\"https://nsfw-demo.sashido.io/drawing.png\" /\u003e\n        \u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003cth align=\"center\"\u003eClassification Result\u003c/th\u003e\n      \u003cth align=\"center\"\u003eClassification Result\u003c/th\u003e\n      \u003cth align=\"center\"\u003eClassification Result\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n\u003cpre\u003e[{\n  \"className\": \"Neutral\",\n  \"probability\": 0.93821\n}, {\n  \"className\": \"Drawing\",\n  \"probability\": 0.05473\n}, {\n  \"className\": \"Sexy\",\n  \"probability\": 0.00532\n}, {\n  \"className\": \"Hentai\",\n  \"probability\": 0.00087\n}, {\n  \"className\": \"Porn\",\n  \"probability\": 0.00085\n}]\u003c/pre\u003e\n      \u003c/td\u003e\n      \u003ctd\u003e\n\u003cpre\u003e[{\n  \"className\": \"Sexy\",\n  \"probability\": 0.99394\n}, {\n  \"className\": \"Neutral\",\n  \"probability\": 0.00432\n}, {\n  \"className\": \"Porn\",\n  \"probability\": 0.00164\n}, {\n  \"className\": \"Drawing\",\n  \"probability\": 0.00006\n}, {\n  \"className\": \"Hentai\",\n  \"probability\": 0.00001\n}]\u003c/pre\u003e\n      \u003c/td\u003e\n      \u003ctd\u003e\n\u003cpre\u003e[{\n  \"className\": \"Drawing\",\n  \"probability\": 0.96063\n}, {\n  \"className\": \"Neutral\",\n  \"probability\": 0.03902\n}, {\n  \"className\": \"Hentai\",\n  \"probability\": 0.00032\n}, {\n  \"className\": \"Sexy\",\n  \"probability\": 0.00001\n}, {\n  \"className\": \"Porn\",\n  \"probability\": 0.00005\n}]\u003c/pre\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://nsfw-demo.sashido.io/api/image/classify?url=https://nsfw-demo.sashido.io/neutral.png\"\u003eNeutral Demo\u003c/\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://nsfw-demo.sashido.io/api/image/classify?url=https://nsfw-demo.sashido.io/sexy.png\"\u003eSexy Demo\u003c/\u003e\n      \u003c/td\u003e\n      \u003ctd align=\"center\"\u003e\u003ca href=\"https://nsfw-demo.sashido.io/api/image/classify?url=https://nsfw-demo.sashido.io/drawing.png\"\u003eDrawing Demo\u003c/\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\u003cbr /\u003e\n\n## How it works\nThis REST API is built in Node.JS with Mongo DB and Parse Server. Classifying images may be invoked from an Express route or a Cloud Code function ( Parse Server lovers, you're welcome :) )\n\nWe have implemented [NSFW.JS](https://github.com/infinitered/nsfwjs) classification, which uses [TensorFlowJS](https://www.tensorflow.org/js) pretrained models.\n\n## Classification map\n\nPass the API an image and receive a JSON response, which holds the predictions on how likely this image falls into each of the following classes:\n\n   *Drawing* - Harmless art, or picture of art\u003cbr/\u003e\n   *Hentai* - Pornographic art, unsuitable for most work environments\u003cbr/\u003e\n   *Neutral* - General, inoffensive content\u003cbr/\u003e\n   *Porn* - Indecent content and actions, often involving genitalia\u003cbr/\u003e\n   *Sexy* - Unseemly provocative content, can include nipples\u003cbr/\u003e\n\n\n# File Structure\n\n   The REST API is built on top of Parse Server. You can use it in a standard Express app, but keep in mind that the file structure of the repo is Parse specific. The code is organized in a ```src``` folder and ```src/cloud/main.js``` is the root file for the service. For more information about how the project is building on the Local env and in Production, take a look at the [package.json](https://github.com/SashiDo/content-moderation-image-api/blob/master/package.json#L14-L20)\n\n# Installation \u0026 Configuration\n\n### Requirements:\n\n- Node.JS \u003e= 10.2.1\n\n- Mongo DB\n\n### Download the project\n\nClone the repo:\n\n```\ngit clone https://github.com/SashiDo/content-moderation-image-api.git\ncd content-moderation-image-api\n```\n\n### Set Environment Variables\n\nCopy the env.example to .env file and set the environment variables for your local environment with your favorite editor:\n\n```\ncp env.example .env\n```\n\nPlace your MongoDB URI. If your app is hosted at SashiDo, you can use the database URI of your SashiDo project. Find the connection string from the app's `Dashboard -\u003e App -\u003e App Settings -\u003e Security \u0026 Keys`\n\n### Install Dependencies\n\nAs this is a full-featured example, all dependencies are present to the packege.json. You only need to run:\n```\nnpm install\n```\n\n### Start the project\n\n```\nnpm run dev\n```\n\n**If everything is okay you should see an output similar to this one**:\n\n```\n[nodemon] 2.0.4\n...\n[nodemon] starting `node index index.js`\n✨  Built in 2.55s.\nnode-pre-gyp ...\n...\nRunning on http://localhost:1337\n⠙ Building index.js...The NSFW Model was loaded successfuly!\n✨  Built in 16.41s.\n```\n\nIf you see the output above, you are ready to play with the API :)\n\n# API Usage Examples\n\nThe project contains two approaches for classifying images - for direct communication through the Parse SDK using Cloud Code and from an Express route.\n\n## Classify from the Express endpoint\n\n```bash\ncurl http://localhost:1337/api/image/classify?url=https://nsfw-demo.sashido.io/sexy.png\n```\n\n## Classify from a Cloud Code function via Parse SDKs\n\nYou can invoke the **nsfwImageClassify function** from the client-side or using the Parse Server REST API:\n\n### Android SDK Example\n\n```Java\nHashMap\u003cString, String\u003e params = new HashMap\u003cString, String\u003e();\nparams.put(\"url\", \"https://nsfw-demo.sashido.io/sexy.png\");\nParseCloud.callFunctionInBackground(\"nsfwImageClassify\", params, new FunctionCallback\u003cObject\u003e() {\n  void done(Object predictions, ParseException e) {\n    if (e == null) {\n      // prediction\n    }\n  }\n});\n```\n\nMore information about how to work with the Android SDK can be found in the [official docs](https://docs.parseplatform.org/android/guide/#use-cloud-code).\n\n\n\n### iOS SDK Example\n\n```Swift\nPFCloud.callFunctionInBackground(\"nsfwImageClassify\", withParameters: [\"url\":\"https://nsfw-demo.sashido.io/sexy.png\"]) {\n  (predictions, error) in\n  if !error {\n    // prediction\n  }\n}\n```\n\nMore information about how to work with the Parse iOS SDK can be found in the [official docs](https://docs.parseplatform.org/ios/guide/#use-cloud-code).\n\n\n### REST API Example\n\n```\ncurl -X POST \\\n  -H \"X-Parse-Application-Id: myAppId\" \\\n  -H \"X-Parse-REST-API-Key: myRestKey\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{ \"url\": \"https://nsfw-demo.sashido.io/sexy.png\" }' \\\n  http://localhost:1337/1/functions/nsfwImageClassify\n```\n\nMore information about how to work with the Parse REST API can be found in the [official docs](http://docs.parseplatform.org/rest/guide/#cloud-code).\n\n\n   SashiDo users can test all Cloud Code functions from our super-friendly [API Console](https://blog.sashido.io/introducing-the-api-console/) that’s built in the Dashboard. Moreover, it gives you the option to      export ay request to cURL.\n\n\n# Deployment on Production\n\n## 1. Environment Variables Setup\n\nFor production, you need to set the **NSFW model URL** and the **NSFW Model Shape size**. SashiDo stores three NSFW models, each one you can set easily using the following URLs:\n\n\n| Model URL                                                   | Size   | Shape Size | Accuracy |\n| :---------------------------------------------------------- | :----: | :--------: | :------: |\n| https://ml.files-sashido.cloud/models/nsfw_inception_v3/    | Huge   | 299        | 93%      |\n| https://ml.files-sashido.cloud/models/nsfw_mobilenet_v2/90/ | 2.6 MB | 224        | 90%      |\n| https://ml.files-sashido.cloud/models/nsfw_mobilenet_v2/93/ | 4.2 MB | 224        | 93%      |\n\n**Please note** *the Inception_v3 model used for this projects has high RAM/CPU consumption. While the two mobilenet models are far more lightweight.*\n\n### Choose the model and set the following environment variables for your live server:\n\n```sh\nTF_MODEL_URL = MODEL_URL\nTF_MODEL_INPUT_SHAPE_SIZE = MODEL_SHAPE_SIZE\n\n# Example\nTF_MODEL_URL=\"https://ml.files-sashido.cloud/models/nsfw_mobilenet_v2/93/\"\nTF_MODEL_INPUT_SHAPE_SIZE=224\n```\n\n## 2. Code Deployment\n\n### Deployment on SashiDo\n\nThis is probably the simplest way to deploy the code in production. At SashiDo we have implemented an automatic git deployment process following the [The Twelve Factor App](https://12factor.net/) principle.\n\nConnect your SashiDo app with GitHub, check [here](https://blog.sashido.io/how-to-start-using-github-with-sashido-for-beginners/) for more details how to start using GitHub with SashiDo.\n\nNext, the code can be easily deployed with two simple commands for adding a remote branch and pushing the code.\n\n```sh\ngit remote add production git@github.com:parsegroundapps/\u003cyour-pg-app-your-app-repo\u003e.git\ngit push -f production master\n```\n\n### Deployment on other providers\n\nBasically, you need to follow the same steps as for SashiDo Deployment. Simply follow the requirements of your hosting provider when setting environment variables for production and deploying the code.\n\n# What's next?\n\n   To get a further insight into the project and what inspired us to build this service, check out our blog post on the topic here.\n\n   The REST API is a part of the Content Moderation service, which also offers:\n\n   - [**Automation Engine**](https://github.com/SashiDo/content-moderation-automations) that will automatically delete inappropriate images. Set the params and reduce manual work to the    bare minimum. - Coming Soon!\n\n   - [**Admin Panel**](https://github.com/SashiDo/content-moderation-application) where all images in need of moderation are stacked up in a beautiful interface, which allows you to make decisions with just a click. - Coming Soon!\n# Contribution\n\n   Thanks for looking at this section. We’re open to any cool ideas, so if you have one and are willing to share - fork the repo, apply changes and open a pull request. :)\n\n# License\n\nCopyright © 2020, CloudStrap AD. See [LICENSE](https://github.com/SashiDo/content-moderation-image-api/blob/master/LICENSE) for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsashido%2Fcontent-moderation-image-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsashido%2Fcontent-moderation-image-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsashido%2Fcontent-moderation-image-api/lists"}