Closed basicfeatures closed 1 year ago
I don't think that's necessary, you can just base64 encode them:
base64_image = Base64.encode64(image_binary_string)
base64_image_url = "data:image/png;base64,#{base64_image}"
I don't know what to do man:
require "replicate"
require "base64"
require "pry"
Replicate.configure do |config|
config.api_token = "XXX"
end
model = Replicate.client.retrieve_model("tencentarc/gfpgan")
version = model.latest_version
Dir.glob("asd/data/*.jpg") do |image|
inputs = {
img: IO.open(Base64.encode64(image), "rb") { |f| f.read },
version: "v1.4",
scale: 2
}
puts version.predict(inputs)
binding.pry
end
# https://replicate.com/p/hc24zndrq5aqbdqktbjgb7leca
# Input
# img (not stored)
# scale 2
# version v1.4
# --
# Output
# local variable 'out_path' referenced before assignment
# Report
# Running predict()...
# /tmp/tmpr6pz3rb_file.png v1.4 2.0 0.5
# global exception: 'NoneType' object has no attribute 'shape'
# Traceback (most recent call last):
# File "/root/.pyenv/versions/3.8.14/lib/python3.8/site-packages/cog/server/worker.py", line 214, in _predict
# result = self._predictor.predict(**payload)
# File "cog_predict.py", line 149, in predict
# return out_path
# UnboundLocalError: local variable 'out_path' referenced before assignment
# --
# prepare_training_images.rb:14:in `initialize": no implicit conversion of String into Integer (TypeError)
# from prepare_training_images.rb:14:in `open"
# from prepare_training_images.rb:14:in `block in <main>"
# from <internal:dir>:220:in `glob"
# from prepare_training_images.rb:12:in `<main>"
As stated in the comment above, you need to base64 encode an attachment and build a data url:
file = File.read("path/to/your/image.png")
base64_image = Base64.encode64(file)
base64_image_url = "data:image/png;base64,#{base64_image}"
inputs = {
img: base64_image_url,
version: "v1.4",
scale: 2
}
I haven't used tencentarc/gfpgan
, but it should work the same with all models.
How can I upload photos to ie. https://replicate.com/tencentarc/gfpgan/api with https://github.com/rest-client/rest-client?
Thanks!