Module: Replicate::Client::Upload

Included in:
Replicate::Client
Defined in:
lib/replicate/client/upload.rb

Overview

Methods for the Prediction API

Instance Method Summary collapse

Instance Method Details

#create_upload(filename = 'data.zip') ⇒ Object

Create an upload



17
18
19
20
# File 'lib/replicate/client/upload.rb', line 17

def create_upload(filename = 'data.zip')
  response = dreambooth_endpoint.post("upload/#{filename}")
  Replicate::Record::Upload.new(self, response)
end

#update_upload(upload_endpoint_url, zip_path) ⇒ Object

Create an upload



24
25
26
27
28
29
30
31
32
# File 'lib/replicate/client/upload.rb', line 24

def update_upload(upload_endpoint_url, zip_path)
  endpoint = Replicate::Endpoint.new(endpoint_url: upload_endpoint_url, api_token: nil)
  endpoint.agent.put do |req|
    req.headers["Content-Type"] = "application/zip"
    req.headers["Content-Length"] = File.size(zip_path).to_s
    req.headers["Transfer-Encoding"] = "chunked"
    req.body = Faraday::UploadIO.new(zip_path, 'application/zip')
  end
end

#upload_zip(zip_path) ⇒ Object

Create upload object and upload zip file



8
9
10
11
12
13
# File 'lib/replicate/client/upload.rb', line 8

def upload_zip(zip_path)
  filename = zip_path.split('/')[-1]
  upload = create_upload(filename)
  upload.attach(zip_path)
  upload
end