# Image Upload - Image Recognition API Support

**URL:** https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648
**Category:** Feature
**Created:** [June 23, 2020, 4:55am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648 "2020-06-23T04:55:06Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![markersocial](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markersocial/32/170136_2.png) [@markersocial](https://meta.discourse.org/u/markersocial)
#### Post date: [June 23, 2020, 4:55am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/1 "2020-06-23T04:55:06Z")

</div>

In light of the SESTA/FOSTA laws, which effectively remove a lot of protections for social/forum/ugc webmasters (Section 230 safe harbor). Making webmasters liable for what their users do.

It might be wise to support using an image recognition API as one solution for improving protection. In order to automate blocking uploads of explicit content like (unsafe, nudity, gore etc.).

Also improve protection from exploits like uploading inappropriate images in drafts, then hotlinking to those images elsewhere. Using it like free anonymous image hosting. I’m not sure how exploitable this is with Discourse, but it looks like with default settings, it could be exploitable for 180 days after draft creation without the webmaster knowing what has been uploaded (delete drafts older than n days).

Some APIs:

- [Amazon Rekognition](https://aws.amazon.com/rekognition/) (they claim it is directly integrate with [Machine Learning Workflow & Integrated Workflows - Amazon Augmented AI - AWS](https://aws.amazon.com/augmented-ai/) for human reviews if wanted also).
- [Google Vision AI](https://cloud.google.com/vision/)
- [Microsoft Computer Vision](https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/)
- [Imagga](https://imagga.com/)

 ![hotdog](https://global.discourse-cdn.com/meta/original/3X/1/8/18cd817497b8d626185cab256f6c354d019a2766.jpeg)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 23, 2020, 5:05am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/2 "2020-06-23T05:05:05Z")

</div>

This would have to start with a plugin, unlikely to ever be a core discourse feature.

[![](https://global.discourse-cdn.com/meta/original/3X/9/5/952d6e8b61cf424572c20c794c5000747272eaa9.jpeg "Silicon Valley - Jian Yangs hotdog app") ](https://www.youtube.com/watch?v=tWwCK95X6go)

---

<div class="post-metadata">

### Author: ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)
#### Post date: [August 21, 2020, 2:51pm UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/3 "2020-08-21T14:51:40Z")

</div>

Checking all images uploaded to Discourse via the Google Cloud Vision API would be really nice in order to stay safe for Adsense. We did that on our former website and never got any nude or gore pictures uploaded.

> **[Vision-Clientbibliotheken  |  Cloud Vision API  |  Google Cloud Documentation](https://docs.cloud.google.com/vision/docs/libraries?hl=de)**
>
> Sie können Code für Vision in Python, Java, Node.js, Ruby, Go, PHP, C# und C++ schreiben.

A Ruby Gem is provided by Google:

> **[Ruby Client for the Cloud Vision API  |  Ruby client libraries  |  Google...](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-vision/latest)**

> **[Ruby Client for the Cloud Vision API  |  Ruby client libraries  |  Google...](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-vision/latest)**

> **[Detect explicit content (SafeSearch)  |  Cloud Vision API  |  Google Cloud...](https://docs.cloud.google.com/vision/docs/detecting-safe-search)**

A potential plugin should hook into the main image upload process of Discourse for all images (posts, avatars, profile backgrounds etc.) and reject images that contain disallowed content:

```plaintext
  puts "Adult: #{safe_search.adult}" puts "Spoof: #{safe_search.spoof}" puts "Medical: #{safe_search.medical}" puts "Violence: #{safe_search.violence}" puts "Racy: #{safe_search.racy}"

```

```plaintext
['UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY']

```

Where needs such a plugin hook into in the Discourse code base?

Is anybody interested to develop it via #Marketplace?

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 21, 2020, 3:02pm UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/4 "2020-08-21T15:02:19Z")

</div>

> [@Terrapop](#):
>
> Checking all images uploaded to Discourse via the Google Cloud Vision API would be really nice in order to stay safe for Adsense.

This is absolutely possble but it would take away the `seamlessness` IMHO from the experience. If there’s any way the model could be built into the plugin, that would be super cool.

> [@Terrapop](#):
>
> We did that on our former website and never got any nude or gore pictures uploaded.

Did you guys use the vision api itself?

Here’s a plugin built by @angus which can act as a starting point. [GitHub - angusmcleod/discourse-machine-learning · GitHub](https://github.com/angusmcleod/discourse-machine-learning)

---

<div class="post-metadata">

### Author: ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)
#### Post date: [August 21, 2020, 3:04pm UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/5 "2020-08-21T15:04:52Z")

</div>

What exactly do you mean by “seamlessness”?

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 21, 2020, 3:05pm UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/6 "2020-08-21T15:05:56Z")

</div>

I mean before uploading, checking the image by POSTing it to the api and getting a green flag would take some time right?

---

<div class="post-metadata">

### Author: ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)
#### Post date: [August 21, 2020, 3:13pm UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/7 "2020-08-21T15:13:54Z")

</div>

Well, the upload process for inline images is async already IMHO. And the Google API is very fast.

On the other hand, I would also be happy to check images after a user has posted a new post via an external webhook (Discourse API), and alter the user’s post (e.g. change the image and replace it with a text “ **IMAGE REMOVED BY ADMIN** ”). That part seems to be possible with the API, but I can’t find any reference how to actually DELETE the “bad” image via the API in such a case, because I don’t even want to keep the somewhere in the shadow.

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 22, 2020, 4:25am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/8 "2020-08-22T04:25:06Z")

</div>

> [@Terrapop](#):
>
> Well, the upload process for inline images is async already IMHO. And the Google API is very fast.

I’m happy to work on this as a paid gig. Can you help with the API side of the things i.e. which api is used to detect offensive content etc.

---

<div class="post-metadata">

### Author: ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)
#### Post date: [August 22, 2020, 6:06am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/9 "2020-08-22T06:06:36Z")

</div>

It’s all very good documented here for Ruby:

> **[Detect explicit content (SafeSearch)  |  Cloud Vision API  |  Google Cloud...](https://docs.cloud.google.com/vision/docs/detecting-safe-search)**

In PHP we implemented this into Drupal in just under 2 hours.

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [August 22, 2020, 6:37am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/10 "2020-08-22T06:37:30Z")

</div>

2 hours should be acceptable for this. Should I send you a PM regarding this?

---

<div class="post-metadata">

### Author: ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)
#### Post date: [August 22, 2020, 6:48am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/11 "2020-08-22T06:48:36Z")

</div>

Yes, please. That would be great.

---

<div class="post-metadata">

### Author: ![markersocial](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markersocial/32/170136_2.png) [@markersocial](https://meta.discourse.org/u/markersocial)
#### Post date: [August 23, 2020, 10:03am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/12 "2020-08-23T10:03:25Z")

</div>

@Terrapop - Something you may want to take into account is the accuracy of the recognition. It can be good to be able to see some of the content that was blocked, to ensure it isn’t configured too strict in terms of ‘POSSIBLE’, ‘LIKELY’ and ‘VERY\_LIKELY’. False positives and negatives are quite common.

I think it might be a better implementation to send any posts that include images above a certain ‘possibly adult’ level to the review queue. So the post is never public, but you can still approve it if the recognition wasn’t accurate. If it’s rejected from there, the images will be deleted, I believe after a time period according to what is set for the ‘clean\_orphan\_uploads\_grace\_period\_hours’.

This would allow using the ‘POSSIBLY’ detection level with more confidence.

---

<div class="post-metadata">

### Author: ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)
#### Post date: [August 23, 2020, 10:40am UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/13 "2020-08-23T10:40:54Z")

</div>

We have tested the API on our current website and know which levels work for us quite well.

@fzngagan is developing the plugin for us open source, thus once finished you can alter and pull request an option to not directly reject but instead forward to mod queue.

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [September 18, 2020, 12:56pm UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/14 "2020-09-18T12:56:55Z")

</div>

Here’s the plugin.

> [@Discourse Image Filter](https://meta.discourse.org/t/discourse-image-filter/163927):
>
> This plugin uses the Google Cloud Vision API to restrict uploading explicit images to the forum. It accounts for all the images uploaded i.e. avatars, logos, etc. It uses the upload error popup to display a message explaining which violations resulted in the restriction of the image upload. The acceptable limits can be set via the site settings. Setup Steps: Create a service account on google cloud [https://cloud.google.com/iam/docs/creating-managing-service-accounts](https://cloud.google.com/iam/docs/creating-managing-service-accounts) Google will trigger a…

I love the idea of tying the likelyhood to the review queues when the image is a part of the post. Happy to accept sponsorship/PR in that regard. 🙂

---

<div class="post-metadata">

### Author: ![Terrapop](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Terrapop](https://meta.discourse.org/u/Terrapop)
#### Post date: [September 18, 2020, 6:24pm UTC](https://meta.discourse.org/t/image-upload-image-recognition-api-support/155648/15 "2020-09-18T18:24:39Z")

</div>

If that is optional as an addition on top, I am fine with that of course.

We used the API in our former community for quite some time and know the levels acceptable for us. And most of the time the API was correct to deny, and the user simply uploaded a less severe image instead.

Also, I wanted not only posts but also image uploads of avatars and profile backgrounds checked. Don’t know if a queue option is being possible for those as well?
