0.01
No release in over a year
Rails gem for Replicate
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 5.0
>= 0
>= 0
>= 6
~> 13.0
~> 1.21

Runtime

 Project Readme

Replicate Rails Gem

This gem bundles the replicate-ruby gem and adds webhook support for replicate.com.

Installation

Add this line to your application's Gemfile:

gem 'replicate-rails', require: 'replicate_rails'

Usage

Setup an initializer and webhook adapter class:

# config/initializers/replicate.rb
Replicate.client.api_token = "your-api-token"

ReplicateRails.configure do |config|
  config.webhook_adapter = ReplicateWebhook.new
end

class ReplicateWebhook
  def call(prediction)
    # do your thing
  end
end

and mount the route:

# config/routes.rb
mount ReplicateRails::Engine => "/replicate/webhook"

Now you can run predictions as follows:

model = Replicate.client.retrieve_model("stability-ai/stable-diffusion")
version = model.latest_version
version.predict(prompt: "a beautiful sunset", "https://yourdomain.tld/replicate/webhook")

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.