getimg 0.1.0

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: 9278befbee725204753bb3f9bedb08ae51dba0782b35aa17149dd5ea49754070
4
+ data.tar.gz: 350c69db91451ca82f21a597bcd624f5e19edd807797d761f1ae0946af42a5d9
5
+ SHA512:
6
+ metadata.gz: e9b3f3489eb956d699b47011ab22a082de2b7be077de98279602ee8317b1ded2c74fec18edbc8722d67987576dc73a8dfec005a4088ccfb64a554cdf5f370114
7
+ data.tar.gz: 1d1a56adc56e52034fb051afa762e620873d537c9b48d51823b5d250c5343506ee0e8b528afc7108e02f280e52dc2f0b8169c17669971f22468d2a1bc8b27702
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-11-08
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at arubinofaux@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 acidtib
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,39 @@
1
+ # Getimg
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/getimg`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/getimg. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/getimg/blob/master/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Getimg project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/getimg/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getimg
4
+ class Client
5
+ class Account
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def balance(options = {})
11
+ @client.get("/account/balance", options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getimg
4
+ class Client
5
+ class Models
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Query Params
11
+ # family string
12
+ # pipeline string
13
+ def list(options = {})
14
+ @client.get("/models", options)
15
+ end
16
+
17
+ # Path Params
18
+ # id string, required
19
+ def get(id)
20
+ @client.get("/models/#{id}")
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getimg
4
+ class Client
5
+ class StableDiffusion
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Body Params
11
+ # model string
12
+ # prompt string, required
13
+ # negative_prompt string
14
+ # width integer
15
+ # height integer
16
+ # steps integer
17
+ # guidance number
18
+ # seed integer
19
+ # scheduler string
20
+ # output_format string
21
+
22
+ # client.stable_diffusion.text_to_image({model: "stable-diffusion-v1-5", prompt: "a photo of an astronaut riding a horse on mars", guidance: 7.5, width: 256, height: 256, steps: 25, output_format: "png"})
23
+ def text_to_image(options = {})
24
+ @client.post("/stable-diffusion/text-to-image", options)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getimg
4
+ class Client
5
+ class StableDiffusionXl
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Body Params
11
+ # model string
12
+ # prompt string, required
13
+ # negative_prompt string
14
+ # prompt_2 string
15
+ # negative_prompt_2 string
16
+ # width integer
17
+ # height integer
18
+ # steps integer
19
+ # guidance number
20
+ # seed integer
21
+ # scheduler string
22
+ # output_format string
23
+
24
+ # client.stable_diffusion_xl.text_to_image({model: "stable-diffusion-xl-v1-0", prompt: "a photo of an astronaut riding a horse on mars", guidance: 7.5, width: 1024, height: 1024, steps: 30, output_format: "png"})
25
+ def text_to_image(options = {})
26
+ @client.post("/stable-diffusion-xl/text-to-image", options)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "getimg/client/models"
4
+ require "getimg/client/stable_diffusion"
5
+ require "getimg/client/stable_diffusion_xl"
6
+ require "getimg/client/account"
7
+
8
+ module Getimg
9
+ # Client for the getimg API
10
+ #
11
+ # @see https://docs.getimg.ai
12
+ class Client
13
+ include HTTParty
14
+
15
+ base_uri "https://api.getimg.ai/v1"
16
+
17
+ default_timeout 600
18
+
19
+ format :json
20
+
21
+ def initialize(api_key = nil)
22
+ @api_key = api_key || ENV["GETIMG_API_LEY"]
23
+ end
24
+
25
+ def models
26
+ @models ||= Models.new(self)
27
+ end
28
+
29
+ def stable_diffusion
30
+ @stable_diffusion ||= StableDiffusion.new(self)
31
+ end
32
+
33
+ def stable_diffusion_xl
34
+ @stable_diffusion_xl ||= StableDiffusionXl.new(self)
35
+ end
36
+
37
+ def account
38
+ @account ||= Account.new(self)
39
+ end
40
+
41
+ def get(path, options = {})
42
+ options = default_request_options.merge({query: options})
43
+ handle_response(self.class.get(path, options))
44
+ end
45
+
46
+ def post(path, options = {}, headers = {})
47
+ options = default_request_options(headers).merge({body: options.to_json})
48
+ handle_response(self.class.post(path, options))
49
+ end
50
+
51
+ private
52
+
53
+ def default_request_options(headers = {})
54
+ {
55
+ headers: {
56
+ Authorization: "Bearer #{@api_key}",
57
+ Accept: "application/json",
58
+ "Content-Type": "application/json"
59
+ }.merge(headers)
60
+ }
61
+ end
62
+
63
+ def handle_response(response)
64
+ result = Oj.load(response.body)
65
+
66
+ case response.code
67
+ when 200...300
68
+ result
69
+ when 400
70
+ raise BadRequestError, "Invalid request parameter."
71
+ when 401
72
+ raise UnauthorizedError, "Invalid API Key provided."
73
+ when 402
74
+ raise PaymentRequiredError, "Quota exceeded."
75
+ when 404
76
+ raise NotFoundError, "The resource doesnt exist."
77
+ when 429
78
+ raise TooManyRequestsError, "Too many requests hit the API too quickly"
79
+ when 500
80
+ raise ServerError, "Something went wrong on our end."
81
+ else
82
+ raise Error, "Unexpected response: #{response.code} - #{result}"
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getimg
4
+ class Image
5
+ def base64_to_file(base64_data, filename = "image")
6
+ # return base64_data unless base64_data.present? && base64_data.is_a?(String)
7
+
8
+ # decode64
9
+ img_from_base64 = Base64.decode64(base64_data)
10
+
11
+ # find file type
12
+ filetype = /(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF)/.match(img_from_base64[0, 16])[0]
13
+
14
+ # write file
15
+ file = "#{filename}.#{filetype}"
16
+ File.binwrite(file, img_from_base64)
17
+ end
18
+
19
+ def file_to_base64(file_path)
20
+ File.open(file_path, "rb") do |file|
21
+ # why strict_encode64
22
+ # https://ruby-doc.org/stdlib-2.3.1/libdoc/base64/rdoc/Base64.html#method-i-strict_encode64
23
+ Base64.strict_encode64(file.read)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getimg
4
+ VERSION = "0.1.0"
5
+ end
data/lib/getimg.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+ require "oj"
5
+ require "base64"
6
+
7
+ require_relative "getimg/version"
8
+ require "getimg/client"
9
+ require "getimg/image"
10
+
11
+ module Getimg
12
+ class Error < StandardError; end
13
+
14
+ class BadRequestError < StandardError; end
15
+
16
+ class UnauthorizedError < StandardError; end
17
+
18
+ class PaymentRequiredError < StandardError; end
19
+
20
+ class TooManyRequestsError < StandardError; end
21
+
22
+ class NotFoundError < StandardError; end
23
+
24
+ class ServerError < StandardError; end
25
+ # Your code goes here...
26
+ end
data/sig/getimg.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Getimg
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: getimg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - acidtib
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.21.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.21.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.16'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 3.16.1
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '3.16'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.16.1
47
+ description: Client library for getimg API.
48
+ email:
49
+ - arubinofaux@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".standard.yml"
55
+ - CHANGELOG.md
56
+ - CODE_OF_CONDUCT.md
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/getimg.rb
61
+ - lib/getimg/client.rb
62
+ - lib/getimg/client/account.rb
63
+ - lib/getimg/client/models.rb
64
+ - lib/getimg/client/stable_diffusion.rb
65
+ - lib/getimg/client/stable_diffusion_xl.rb
66
+ - lib/getimg/image.rb
67
+ - lib/getimg/version.rb
68
+ - sig/getimg.rbs
69
+ homepage: https://github.com/acidtib/getimg-rb
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/acidtib/getimg-rb
74
+ changelog_uri: https://github.com/acidtib/getimg-rb/blob/main/CHANGELOG.md
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.6.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.4.21
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Client library for getimg API.
94
+ test_files: []