From 1eb9dc37a718d650b16e0d621fd7faa5a140c089 Mon Sep 17 00:00:00 2001 From: Paul Arterburn Date: Wed, 15 May 2024 09:46:13 -0600 Subject: [PATCH] Update clarafai --- app/models/entry.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/entry.rb b/app/models/entry.rb index ec041712..d0793703 100644 --- a/app/models/entry.rb +++ b/app/models/entry.rb @@ -150,9 +150,23 @@ def hashtags def check_image if image.present? && ENV['CLARIFAI_PERSONAL_ACCESS_TOKEN'].present? begin - url = "https://api.clarifai.com/v2/users/clarifai/apps/main/models/nsfw-recognition/versions/aa47919c9a8d4d94bfa283121281bcc4/outputs" + url = "https://api.clarifai.com/v2/models/nsfw-recognition/outputs" headers = {"Authorization" => "Key #{ENV['CLARIFAI_PERSONAL_ACCESS_TOKEN']}", "Content-Type" => "application/json"} - payload = { inputs: [ { data: { image: { url: image_url_cdn } } } ] }.to_json + payload = { + user_app_id: { + user_id: ENV['CLARIFAI_USER_ID'], + app_id: ENV['CLARIFAI_APP_ID'] + }, + inputs: [ + { + data: { + image: { + url: image_url_cdn + } + } + } + ] + }.to_json res = JSON.parse(RestClient.post(url, payload, headers)) nsfw_percent = res.try(:[], 'outputs')&.first.try(:[], 'data').try(:[], 'concepts')&.second.try(:[], 'value') if nsfw_percent.present? && nsfw_percent >= ENV['CLARIFAI_THRESHOLD'].to_f