mirror of
https://github.com/danbee/my-images
synced 2025-03-04 08:49:05 +00:00
🚨
This commit is contained in:
parent
31f1e29800
commit
5bf0727fd0
@ -1,9 +1,10 @@
|
||||
require 'base64'
|
||||
require 'http'
|
||||
require "base64"
|
||||
require "http"
|
||||
|
||||
class Clarifai
|
||||
KEY = ENV.fetch("CLARIFAI_API_KEY").freeze
|
||||
API_URL = "https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs"
|
||||
API_URL = "https://api.clarifai.com/v2/models/" \
|
||||
"aaa03c23b3724a16a56b629203edc62c/outputs".freeze
|
||||
|
||||
attr_reader :tags
|
||||
|
||||
@ -14,18 +15,18 @@ class Clarifai
|
||||
def predict!
|
||||
headers = {
|
||||
"Authorization": "Key #{KEY}",
|
||||
"Content-Type": "application/json"
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
params = {
|
||||
"inputs": [
|
||||
{
|
||||
"data": {
|
||||
"image": {
|
||||
"base64": Base64.encode64(File.read(@image_path))
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"base64": Base64.encode64(File.read(@image_path)),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
resp = HTTP.
|
||||
|
||||
@ -13,22 +13,22 @@ describe Clarifai do
|
||||
{
|
||||
"id": "ai_PpTcwbdQ",
|
||||
"name": "computer",
|
||||
"value": 0.96887743
|
||||
"value": 0.96887743,
|
||||
},
|
||||
{
|
||||
"id": "ai_62K34TR4",
|
||||
"name": "technology",
|
||||
"value": 0.96544206
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
"value": 0.96544206,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
}.to_json
|
||||
|
||||
WebMock.
|
||||
stub_request(:post, Clarifai::API_URL).
|
||||
to_return(:status => 200, :body => stub_body)
|
||||
to_return(status: 200, body: stub_body)
|
||||
|
||||
clarifai_image = Clarifai.new("spec/fixtures/spectrum.jpg")
|
||||
clarifai_image.predict!
|
||||
@ -37,5 +37,3 @@ describe Clarifai do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user