gen-ai 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20e16166f4ff21fb5130cf198be040b3d89019ba18cebd55e25f02720b32de62
4
- data.tar.gz: 0eb3c0b7aace3f1dc97cc6f28635b45dae67aac3304d9fc9926a2f6a517d42cf
3
+ metadata.gz: 2b25d130c100818a73d652eaf9b585a4d024f6134a66de3f20eb5dd6e3d2212a
4
+ data.tar.gz: 7d971d676915f71edf74fec57cd7cb59b2d2c6607d7ed818d05d07b19f8cdecc
5
5
  SHA512:
6
- metadata.gz: '02380f33e49b058b40c62c07b2470d5cebb36e8301f4d985077fbd27c9279948cf981227b6f8293bcac74a7b455f17e0ce64310601afcc7cfcd4bf81e3293fee'
7
- data.tar.gz: 51e6bd0e3950fa62ae26f7f4103fbdd457e262212a840a9dab3abf84ed8337a6f50b60f011fbc717b891b4ac78483cbc60224784f4dfc78cdc7b938ac29f22a6
6
+ metadata.gz: 98554f5f32925f6ea70ea78e8c462d3d24949fb265fed69ae5f73fc722206c455e81bec75a879aa21bf841b372518f6ffce5497ec3c82bf60260b4d4c8ed2525
7
+ data.tar.gz: 905b2aa2b483711de399aa166dc5c83f9e7a482a1649f77281c995adbcf0f3dc9847b3ecbc0bdc21028a0f79f4ffb770c0a09dbad6a02d2a191d206dfeb43712
data/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
- ## [Unreleased]
1
+ ## [0.2.0] - 2023-10-22
2
+ - Add image generation abilities
2
3
 
3
4
  ## [0.1.0] - 2023-10-13
4
5
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ✨ Generative AI toolset for Ruby ✨
4
4
 
5
- GenAI allows you to easily integrate Generative AI model providers like OpenAI, Google Vertex AI, Stability AI, etc. Easily add Large Language Models, Stable Diffusion image generation, and other AI models into your application!
5
+ GenAI allows you to easily integrate Generative AI model providers like OpenAI, Google Vertex AI, Stability AI, etc. Easily add Large Language Models, Stable Diffusion image generation, and other AI model integrations into your application!
6
6
 
7
7
  ![Tests](https://github.com/alchaplinsky/gen-ai/actions/workflows/main.yml/badge.svg?branch=main)
8
8
  [![Gem Version](https://badge.fury.io/rb/gen-ai.svg)](https://badge.fury.io/rb/gen-ai)
@@ -31,12 +31,12 @@ Language models capabilities
31
31
  | **Google Palm2** | ✅ | ✅ | ✅ | 🛠️ | 🛠️ |
32
32
 
33
33
 
34
- Image generation model capabilities
34
+ Image generation model capabilities
35
35
 
36
36
  | Provider | Generate | Variations | Edit | Upscale |
37
37
  | ---------------- | --------- | :--------: | :----------: | :-------: |
38
38
  | **OpenAI** | ✅ | ✅ | ✅ | ❌ |
39
- | **StabilityAI** | ✅ | ❌ | ✅ | 🛠️ |
39
+ | **StabilityAI** | ✅ | ❌ | ✅ | |
40
40
 
41
41
  ### Language
42
42
 
@@ -123,6 +123,8 @@ File.open('dog.jpg', 'wb') do |f|
123
123
  f.write(Base64.decode64(result.value))
124
124
  end
125
125
  ```
126
+ ![dog](https://github.com/alchaplinsky/gen-ai/assets/695947/27a2af5d-530b-4966-94e8-6cdf628b6cac)
127
+
126
128
 
127
129
  Get more **variations** of the same image
128
130
 
@@ -139,6 +141,8 @@ File.open('dog_variation.jpg', 'wb') do |f|
139
141
  end
140
142
 
141
143
  ```
144
+ ![dog_variation](https://github.com/alchaplinsky/gen-ai/assets/695947/977f5238-0114-4085-8e61-8f8b356ce308)
145
+
142
146
 
143
147
  **Editing** existing images with additional prompt
144
148
 
@@ -153,9 +157,12 @@ result.value
153
157
  File.open('dog_edited.jpg', 'wb') do |f|
154
158
  f.write(Base64.decode64(result.value))
155
159
  end
156
-
157
160
  ```
158
161
 
162
+ ![llama](https://github.com/alchaplinsky/gen-ai/assets/695947/9c862c6c-428e-463c-b935-ca749a6a33df)
163
+ ![llama_edited](https://github.com/alchaplinsky/gen-ai/assets/695947/070d8e6a-07a0-4ed2-826f-8b9aabd183ae)
164
+
165
+
159
166
  ## Development
160
167
 
161
168
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/gen-ai.gemspec CHANGED
@@ -9,8 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['alchaplinsky@gmail.com']
10
10
 
11
11
  spec.summary = 'Generative AI toolset for Ruby.'
12
- spec.description = 'Generative AI toolset for Ruby.'
12
+ spec.description = 'GenAI allows you to easily integrate Generative AI model providers like OpenAI, Google Vertex AI, Stability AI, etc'
13
13
  spec.homepage = 'https://github.com/alchaplinsky/gen-ai'
14
+ spec.licenses = ['MIT']
14
15
  spec.required_ruby_version = '>= 2.7.0'
15
16
 
16
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
@@ -33,7 +34,7 @@ Gem::Specification.new do |spec|
33
34
 
34
35
  # Uncomment to register a new dependency of your gem
35
36
  spec.add_dependency 'faraday', '~> 2.7'
36
- spec.add_dependency 'faraday-multipart'
37
+ spec.add_dependency 'faraday-multipart', '~> 1.0'
37
38
  spec.add_dependency 'zeitwerk', '~> 2.6'
38
39
 
39
40
  spec.add_development_dependency 'google_palm_api', '~> 0.1'
@@ -10,6 +10,14 @@ module GenAI
10
10
  def variations(...)
11
11
  raise NotImplementedError, "#{self.class.name} does not support variations"
12
12
  end
13
+
14
+ def edit(...)
15
+ raise NotImplementedError, "#{self.class.name} does not support editing"
16
+ end
17
+
18
+ def upscale(...)
19
+ raise NotImplementedError, "#{self.class.name} does not support upscaling"
20
+ end
13
21
  end
14
22
  end
15
23
  end
@@ -8,6 +8,7 @@ module GenAI
8
8
  DEFAULT_SIZE = '256x256'
9
9
  API_BASE_URL = 'https://api.stability.ai'
10
10
  DEFAULT_MODEL = 'stable-diffusion-xl-beta-v2-2-2'
11
+ UPSCALE_MODEL = 'stable-diffusion-x4-latent-upscaler'
11
12
 
12
13
  def initialize(token:, options: {})
13
14
  build_client(token)
@@ -39,6 +40,19 @@ module GenAI
39
40
  )
40
41
  end
41
42
 
43
+ def upscale(image, options = {})
44
+ model = options[:model] || UPSCALE_MODEL
45
+ url = "/v1/generation/#{model}/image-to-image/upscale"
46
+
47
+ response = client.post url, build_upscale_body(image, options), multipart: true
48
+
49
+ build_result(
50
+ raw: response,
51
+ model: model,
52
+ parsed: response['artifacts'].map { |artifact| artifact['base64'] }
53
+ )
54
+ end
55
+
42
56
  private
43
57
 
44
58
  def build_client(token)
@@ -56,10 +70,20 @@ module GenAI
56
70
  end
57
71
 
58
72
  def build_edit_body(image, prompt, options)
59
- {
73
+ params = {
60
74
  init_image: File.binread(image),
61
75
  'text_prompts[0][text]' => prompt,
62
76
  'text_prompts[0][weight]' => 1.0
77
+ }
78
+ params.merge!(mask: File.binread(options.delete(:mask))) if options[:mask]
79
+ params.merge(options)
80
+ end
81
+
82
+ def build_upscale_body(image, options)
83
+ w, = size(options)
84
+ {
85
+ image: File.binread(image),
86
+ width: w
63
87
  }.merge(options)
64
88
  end
65
89
 
data/lib/gen_ai/image.rb CHANGED
@@ -18,7 +18,9 @@ module GenAI
18
18
  client.edit(image, prompt, options)
19
19
  end
20
20
 
21
- # def upscale; end
21
+ def upscale(image, options = {})
22
+ client.upscale(image, options)
23
+ end
22
24
 
23
25
  private
24
26
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GenAI
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.2'
5
5
  end
data/lib/gen_ai.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'zeitwerk'
4
- require 'pry'
5
4
 
6
5
  loader = Zeitwerk::Loader.for_gem
7
6
  loader.inflector.inflect(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gen-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaplinsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-22 00:00:00.000000000 Z
11
+ date: 2023-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: faraday-multipart
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: zeitwerk
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5.1'
83
- description: Generative AI toolset for Ruby.
83
+ description: GenAI allows you to easily integrate Generative AI model providers like
84
+ OpenAI, Google Vertex AI, Stability AI, etc
84
85
  email:
85
86
  - alchaplinsky@gmail.com
86
87
  executables: []
@@ -111,7 +112,8 @@ files:
111
112
  - lib/gen_ai/version.rb
112
113
  - sig/gen_ai.rbs
113
114
  homepage: https://github.com/alchaplinsky/gen-ai
114
- licenses: []
115
+ licenses:
116
+ - MIT
115
117
  metadata:
116
118
  homepage_uri: https://github.com/alchaplinsky/gen-ai
117
119
  source_code_uri: https://github.com/alchaplinsky/gen-ai