Discourse 图像过滤器

此插件使用 Google Cloud Vision API 来限制在论坛上传露骨图片。它会处理所有上传的图片,包括头像、徽标等。

它利用上传错误弹窗显示消息,解释导致图片上传受限的具体违规内容。

可接受的阈值可通过站点设置进行配置。


设置

步骤:

  1. 在 Google Cloud 上创建服务账号 Create service accounts  |  Identity and Access Management (IAM)  |  Google Cloud Documentation
    Google 将触发下载一个 JSON 文件。请安全存储其内容。

  2. 将以下行粘贴到 app.yml 中 env 部分的底部

     GOOGLE_ACCOUNT_TYPE: 'service_account'
     GOOGLE_CLIENT_ID: 'client-id-from-json-file'
     GOOGLE_CLIENT_EMAIL: "service-account-email-address"
     GOOGLE_PRIVATE_KEY:  见下文说明
    
  • 如何设置 GOOGLE_PRIVATE_KEY 参数?

    • 将 JSON 文件中的密钥粘贴到代码编辑器中。
    • 使用 查找和替换 功能,将 \n 替换为 \\n
    • 复制结果,并将其粘贴到 app.yml 中的 GOOGLE_PRIVATE_KEY 前,并用单引号 ' ' 包裹。
  1. 现在按照常规步骤安装插件。

插件设置

if_adult_max_acceptableadult 类别的可接受最大级别
if_spoof_max_acceptablespoof 类别的可接受最大级别
if_medical_max_acceptablemedical 类别的可接受最大级别
if_violence_max_acceptableviolence 类别的可接受最大级别
if_racy_max_acceptableracy 类别的可接受最大级别

您可以在此处详细了解这些标准以及 API 本身。Detect explicit content (SafeSearch)  |  Cloud Vision API  |  Google Cloud Documentation

:page_facing_up: 获取代码

:raising_hand_woman: 请求功能

:bug: 报告错误

开发说明

若要在 macOS 的开发环境中使用,请将以下行添加到您的 .bash_profile 文件中
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

迷路了?

感谢 @Terrapop 赞助此插件。

22 个赞

@riking

我创建了这个 PR https://github.com/discourse/discourse/pull/10605,因为我意识到如果在上传头像或徽标时发生 Rails 端异常,上传错误弹窗将不会显示。它在从编辑器上传时运行良好。我认为这是一个值得纳入上游的不错更改。

6 个赞

感谢提醒,我错过了 GitHub 的通知。

5 个赞

非常感谢合并。这对 Discourse 和我的插件都有帮助。

4 个赞

太好了,感谢你的帮助 @fzngagan 让这一切成为可能,与你合作非常愉快。

对于所有需要符合儿童安全 COPPA 要求、希望确保 AdSense 安全,或单纯不希望出现任何血腥或裸露图片的社区来说,这个插件是必备之选。

7 个赞

@Razcle
这或许会让你感兴趣

谢谢 Faizaan!我一直在考虑制作一个更专注于语言理解且可定制的产品。你有这方面的经验吗?

R

3 个赞

@jahan_gagan 可能对自然语言处理(NLP)有些话要说。

2 个赞

我尝试过使用 stackoverflow dataset 进行 tags prediction,之后尝试将相同的代码用于 discourse 数据集,但由于 discourse 的数据量较少,该代码在此无法运行。

2 个赞

我的服务账号需要哪些权限范围?我收到了“请求的认证权限范围不足”的提示。

这能帮上忙吗?完全在客户端运行

文本毒性模型

本插件针对的是图片,而非文本。

针对文本,有一个基于 Jigsaw 引擎的 Google Perspective 插件可用:

2 个赞

你好 :waving_hand: 这个插件还能用吗?我刚看到最后一次提交大约是 4 年前。谢谢 :slightly_smiling_face:

1 个赞

我尝试将其安装在测试实例上,但似乎存在 gem 问题。重建失败。希望可以修复。:crossed_fingers: 也许这些 gem 已被弃用……

rake aborted!

Gem::LoadError: can't activate google-protobuf-3.13.0-x86_64-linux, already activated google-protobuf-4.27.3-x86_64-linux (Gem::LoadError)

/var/www/discourse/lib/plugin_gem.rb:25:in `load'

/var/www/discourse/lib/plugin/instance.rb:835:in `gem'

/var/www/discourse/plugins/discourse-image-filter/plugin.rb:12:in `activate!'

/var/www/discourse/lib/plugin/instance.rb:778:in `instance_eval'

/var/www/discourse/lib/plugin/instance.rb:778:in `activate!'

/var/www/discourse/lib/discourse.rb:348:in `block in activate_plugins!'

/var/www/discourse/lib/discourse.rb:345:in `each'

/var/www/discourse/lib/discourse.rb:345:in `activate_plugins!'

/var/www/discourse/config/application.rb:231:in `block in <class:Application>'

/var/www/discourse/lib/plugin.rb:6:in `initialization_guard'

/var/www/discourse/config/application.rb:231:in `<class:Application>'

/var/www/discourse/config/application.rb:75:in `<module:Discourse>'

/var/www/discourse/config/application.rb:74:in `<top (required)>'

/var/www/discourse/Rakefile:7:in `<top (required)>'

/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'

/usr/local/bin/bundle:25:in `load'

/usr/local/bin/bundle:25:in `<main>'

(See full trace by running task with --trace)

I, [2024-08-02T16:48:02.872895 #1] INFO -- : gem install os -v 1.1.1 -i /var/www/discourse/plugins/discourse-image-filter/gems/3.3.3 --no-document --ignore-dependencies --no-user-install

Successfully installed os-1.1.1

1 gem installed

gem install google-protobuf -v 3.13.0 -i /var/www/discourse/plugins/discourse-image-filter/gems/3.3.3 --no-document --ignore-dependencies --no-user-install

Successfully installed google-protobuf-3.13.0-x86_64-linux

1 gem installed

I, [2024-08-02T16:48:02.886926 #1] INFO -- : Terminating async processes

I, [2024-08-02T16:48:02.888160 #1] INFO -- : Sending INT to HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main pid: 36

I, [2024-08-02T16:48:02.888588 #1] INFO -- : Sending TERM to exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf pid: 98

2024-08-02 16:48:02.888 UTC [36] LOG: received fast shutdown request

98:signal-handler (1722617282) Received SIGTERM scheduling shutdown...

2024-08-02 16:48:02.892 UTC [36] LOG: aborting any active transactions

98:M 02 Aug 2024 16:48:02.896 # User requested shutdown...

98:M 02 Aug 2024 16:48:02.897 * Saving the final RDB snapshot before exiting.

2024-08-02 16:48:02.906 UTC [36] LOG: background worker "logical replication launcher" (PID 51) exited with exit code 1

2024-08-02 16:48:02.909 UTC [46] LOG: shutting down

98:M 02 Aug 2024 16:48:02.939 * DB saved on disk

98:M 02 Aug 2024 16:48:02.939 # Redis is now ready to exit, bye bye...

2024-08-02 16:48:02.949 UTC [36] LOG: database system is shut down

FAILED

--------------------

Pups::ExecError: cd /var/www/discourse &amp;&amp; su discourse -c 'bundle exec rake db:migrate' failed with return #&lt;Process::Status: pid 571 exit 1&gt;

Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'

exec failed with the params {"cd"=>"$home", "tag"=>"migrate", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}

bootstrap failed with exit code 1

** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.

./discourse-doctor may help diagnose the problem.

9213a43b80e800c6f2b1d0adc0663ec82a483b860f0302b8ebabc8a3b2bb0619

我将此标记为 #broken。

2 个赞