Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dreamingtulpa/replicate-rails
Replicate gem for Rails
https://github.com/dreamingtulpa/replicate-rails
Last synced: 2 months ago
JSON representation
Replicate gem for Rails
- Host: GitHub
- URL: https://github.com/dreamingtulpa/replicate-rails
- Owner: dreamingtulpa
- Created: 2022-10-14T08:28:21.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T13:30:22.000Z (about 2 years ago)
- Last Synced: 2024-11-07T19:54:44.280Z (3 months ago)
- Language: Ruby
- Size: 12.7 KB
- Stars: 30
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-replicate - replicate-rails - A gem that bundles the Ruby client and adds webhook support. (Client libraries)
README
# Replicate Rails Gem
This gem bundles the [replicate-ruby](https://github.com/dreamingtulpa/replicate-ruby) gem and adds webhook support for replicate.com.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'replicate-rails', require: 'replicate_rails'
```## Usage
Setup an initializer and webhook adapter class:
```ruby
# config/initializers/replicate.rb
Replicate.client.api_token = "your-api-token"ReplicateRails.configure do |config|
config.webhook_adapter = ReplicateWebhook.new
endclass ReplicateWebhook
def call(prediction)
# do your thing
end
end
```and mount the route:
```ruby
# 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.