Purity Vision is a project that utilizes the Google Vision API to auto-filter images from web pages that are detected to have gore, nudity, or other explicit content. The filter is user-configurable and can be disabled with the click of a button. Browse the web with peace in mind.
This repository serves as the backend for the web extension. It interfaces with the Google Vision API and has a database that caches image requests in order to avoid redundant calls to Google's API. This is done to improve efficiency and reduce costs, as Google charges on a per request basis.
Eventually, this project is meant to be completely run within containers. As of now the Postgres database runs in Docker, and the API server runs locally using the user's local installation of Go.
- UNIX Operating System (Linux, MacOS, Window's Subsystem for Linux (WSL/WSL2))
- golang (version must support Go Modules)
- docker
- Google Cloud Account
- direnv - useful for loading the environment variables needed to run the project
Users will need to sign up for a Google Cloud account if they have not already and create a project with the Google Vision API enabled. In order to authenticate with the account, the user must create a Service Account under the GCP project, then export the credentials to a JSON a file that is saved locally on disk. The GOOGLE_APPLICATION_CREDENTIALS
environment variable defined in the .envrc
file must be an absolute path to this credential file for the image filtering to work.
To connect to the database, the API server loads environment variables to setup the database credentials, point to the Google API credential file, among other things.
The required environment variables are listed in the .envrc
file in the project repository. It is recommended to use direnv to handle this, as it allows developers to utilize the .envrc file instead of manually exporting the environment variables.
note: make sure to fill in the PURITY_DB_PASS
entry if using direnv, otherwise the database setup may fail.
With golang installed and Docker running, start the the database with the start-db.sh
script.
./scripts/start-db.sh
Run the API server with Make:
make
Use curl to hit the filter endpoint:
curl -i localhost:8080/filter \
-d '{"imgUriList": ["https://previews.124rf.com/images/valio84sl/valio84sl1311/valio84sl131100006/23554524-autumn-landscape-orange-trre.jpg"]}'
If everything is working, the response should look like:
{
"imgFilterResList": [
{
"imgURI": "https://www.allaboutbirds.org/news/wp-content/uploads/2020/03/THeron-Anderson-124505431.jpg",
"error": "",
"pass": true
}
]
}
In this example, the image has passed the default filter rule which filters out images found to contain nudity.
Shoot me an email if you have any questions: [email protected]