Skip to content

Commit

Permalink
Update clarafai
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed May 15, 2024
1 parent b65f1f6 commit 1eb9dc3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/models/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1eb9dc3

Please sign in to comment.