leoandruby 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 149d2e54ecda2eac9a33142240dd62f5b108741e0f5071b0a93a3290fec5ce10
4
+ data.tar.gz: 444ff02b5545bfb777847096c83efb9479cafa0951481cf879aa186a01a16c8e
5
+ SHA512:
6
+ metadata.gz: bca73afb65e1f65ab6468b2a6d2b31f04e601bd15284f7528e8d7bfa1ccbca5454ae4da10b958a84cec873bd3043e62f8979b7a2502f6d92bcdbcacd498989a9
7
+ data.tar.gz: ed281dbcd565b839151cf828ab0ae31cee02c60355f7b46011b59160670d007f72db87c5f1608b31aa3b67399a217febaf908e2730f8adff2d2119c4b6d371af
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-11-20
4
+
5
+ - Initial release
6
+
7
+ ## [0.1.1] - 2024-11-21
8
+
9
+ - Bug Fixes
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Richard HW Baldwin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,163 @@
1
+
2
+ # LeoAndRuby
3
+
4
+ **LeoAndRuby** is a Ruby gem for generating images using the [Leonardo.ai API](https://docs.leonardo.ai/docs/generate-your-first-images). With this gem, you can easily integrate Leonardo.ai's powerful image generation capabilities into your Ruby applications.
5
+
6
+ ---
7
+
8
+ ## Features
9
+
10
+ - Generate images using Leonardo.ai's models.
11
+ - Retrieve the status and result of a generated image.
12
+ - Simple and intuitive Ruby interface for interacting with the Leonardo.ai API.
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'leoandruby'
22
+ ```
23
+
24
+ Then, run:
25
+
26
+ ```bash
27
+ bundle install
28
+ ```
29
+
30
+ Or install it yourself with:
31
+
32
+ ```bash
33
+ gem install leoandruby
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Setup
39
+
40
+ To use LeoAndRuby, you need an API key from Leonardo.ai. You can obtain it by signing up for an account and navigating to the API key section in your dashboard.
41
+
42
+ ---
43
+
44
+ ## Usage
45
+
46
+ ### 1. Initialize the Client
47
+
48
+ Start by creating a client instance with your Leonardo.ai API key:
49
+
50
+ ```ruby
51
+ require 'leoandruby'
52
+
53
+ api_key = 'YOUR_API_KEY'
54
+ client = LeoAndRuby::Client.new(api_key)
55
+ ```
56
+
57
+ ### 2. Generate an Image
58
+
59
+ You can generate an image by providing the prompt, model ID, width, and height:
60
+
61
+ ```ruby
62
+ generation_response = client.generate_image(
63
+ prompt: 'An oil painting of a cat',
64
+ model_id: '6bef9f1b-29cb-40c7-b9df-32b51c1f67d3',
65
+ width: 512,
66
+ height: 512
67
+ )
68
+
69
+ generation_id = generation_response['sdGenerationJob']['generationId']
70
+ ```
71
+
72
+ ### 3. Retrieve the Generated Image
73
+
74
+ Wait a few seconds for the image to be generated, then retrieve it using the generation ID:
75
+
76
+ ```ruby
77
+ sleep(5)
78
+
79
+ image_response = client.get_generation(generation_id)
80
+ puts image_response
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Configuration
86
+
87
+ ### Environment Variables
88
+
89
+ You can store your API key in an environment variable for security:
90
+
91
+ ```bash
92
+ export LEOANDRUBY_API_KEY=your_api_key
93
+ ```
94
+
95
+ Then, retrieve it in your code:
96
+
97
+ ```ruby
98
+ api_key = ENV['LEOANDRUBY_API_KEY']
99
+ client = LeoAndRuby::Client.new(api_key)
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Example Script
105
+
106
+ Here's a full example script:
107
+
108
+ ```ruby
109
+ require 'leoandruby'
110
+
111
+ api_key = 'YOUR_API_KEY'
112
+ client = LeoAndRuby::Client.new(api_key)
113
+
114
+ # Generate an image
115
+ generation_response = client.generate_image(
116
+ prompt: 'A futuristic cityscape at sunset',
117
+ model_id: '6bef9f1b-29cb-40c7-b9df-32b51c1f67d3',
118
+ width: 1024,
119
+ height: 768
120
+ )
121
+
122
+ generation_id = generation_response['sdGenerationJob']['generationId']
123
+
124
+ # Wait for a few seconds
125
+ sleep(5)
126
+
127
+ # Retrieve the generated image
128
+ image_response = client.get_generation(generation_id)
129
+ puts image_response
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Supported Ruby Versions
135
+
136
+ LeoAndRuby is tested with the latest Ruby versions. Ensure your environment is up to date to avoid compatibility issues.
137
+
138
+ ---
139
+
140
+ ## Contributing
141
+
142
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/RWKotulski/leoandruby). This project is intended to be a safe, welcoming space for collaboration.
143
+
144
+ ---
145
+
146
+ ## License
147
+
148
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
149
+
150
+ ---
151
+
152
+ ## References
153
+
154
+ - [Leonardo.ai API Documentation](https://docs.leonardo.ai/)
155
+ - [RubyGems Documentation](https://guides.rubygems.org/)
156
+
157
+ ---
158
+
159
+ ## Acknowledgments
160
+
161
+ Special thanks to [Leonardo.ai](https://leonardo.ai/) for providing such an amazing image generation API.
162
+ ```
163
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "standard/rake"
5
+
6
+ task default: :standard
data/cloving.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "languages": [
3
+ {
4
+ "name": "Ruby",
5
+ "primary": true,
6
+ "directory": "lib",
7
+ "extension": ".rb"
8
+ }
9
+ ],
10
+ "frameworks": [],
11
+ "testingFrameworks": [],
12
+ "buildTools": [
13
+ {
14
+ "name": "Rake",
15
+ "type": "Build automation tool",
16
+ "version": "~> 13.0"
17
+ }
18
+ ],
19
+ "packageManager": "Bundler",
20
+ "linters": [
21
+ {
22
+ "name": "Standard",
23
+ "version": "~> 1.3",
24
+ "type": "Linter"
25
+ }
26
+ ],
27
+ "databases": [],
28
+ "projectType": "Library"
29
+ }
@@ -0,0 +1,58 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module LeoAndRuby
6
+ class Client
7
+ API_BASE_URL = 'https://cloud.leonardo.ai/api/rest/v1'.freeze
8
+
9
+ def initialize(api_key)
10
+ @api_key = api_key
11
+ end
12
+
13
+ def generate_image(prompt:, model_id:, width:, height:)
14
+ uri = URI("#{API_BASE_URL}/generations")
15
+ request = Net::HTTP::Post.new(uri)
16
+ request['Accept'] = 'application/json'
17
+ request['Authorization'] = "Bearer #{@api_key}"
18
+ request['Content-Type'] = 'application/json'
19
+
20
+ request.body = {
21
+ prompt: prompt,
22
+ modelId: model_id,
23
+ width: width,
24
+ height: height
25
+ }.to_json
26
+
27
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
28
+ http.request(request)
29
+ end
30
+
31
+ handle_response(response)
32
+ end
33
+
34
+ def get_generation(generation_id)
35
+ uri = URI("#{API_BASE_URL}/generations/#{generation_id}")
36
+ request = Net::HTTP::Get.new(uri)
37
+ request['Accept'] = 'application/json'
38
+ request['Authorization'] = "Bearer #{@api_key}"
39
+
40
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
41
+ http.request(request)
42
+ end
43
+
44
+ handle_response(response)
45
+ end
46
+
47
+ private
48
+
49
+ def handle_response(response)
50
+ case response
51
+ when Net::HTTPSuccess
52
+ JSON.parse(response.body)
53
+ else
54
+ raise "HTTP Error: #{response.code} - #{response.message}"
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Leoandruby
4
+ VERSION = "0.1.1"
5
+ end
data/lib/leoandruby.rb ADDED
@@ -0,0 +1,4 @@
1
+ #lib/leoandruby.rb
2
+
3
+ require_relative 'leoandruby/client'
4
+
@@ -0,0 +1,4 @@
1
+ module Leoandruby
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leoandruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard HW Baldwin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: LeoAndRuby is a Ruby gem for integrating with the Leonardo.ai API, enabling
14
+ seamless image generation within Ruby applications. It provides a simple and intuitive
15
+ interface for creating, managing, and retrieving AI-generated images.
16
+ email:
17
+ - richard@empireofaustralia.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".standard.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - cloving.json
29
+ - lib/leoandruby.rb
30
+ - lib/leoandruby/client.rb
31
+ - lib/leoandruby/version.rb
32
+ - sig/leoandruby.rbs
33
+ homepage: https://github.com/RWKotulski/LeoAndRuby
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/RWKotulski/LeoAndRuby
38
+ source_code_uri: https://github.com/RWKotulski/LeoAndRuby
39
+ changelog_uri: https://github.com/RWKotulski/LeoAndRuby/CHANGELOG.md
40
+ features: |
41
+ - Generate stunning AI-powered images with minimal configuration.
42
+ - Simple Ruby interface for interacting with the Leonardo.ai API.
43
+ - Supports asynchronous workflows with polling for image generation results.
44
+ - Fully configurable with support for API keys via environment variables.
45
+ - Easily integrates into Ruby and Rails applications.
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.5.17
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A Ruby gem for generating AI-powered images with Leonardo.ai's API.
65
+ test_files: []