gen-ai 0.2.0 → 0.2.1

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: 8fd6ea8e9dbcde79c04b1d37681d8d96e8722b09e2e24d0d9766b97319f065b0
4
+ data.tar.gz: 6e0599dd926747a2d71065ccc43c77648e9a0f3cdd10357540fb847606dfa656
5
5
  SHA512:
6
- metadata.gz: '02380f33e49b058b40c62c07b2470d5cebb36e8301f4d985077fbd27c9279948cf981227b6f8293bcac74a7b455f17e0ce64310601afcc7cfcd4bf81e3293fee'
7
- data.tar.gz: 51e6bd0e3950fa62ae26f7f4103fbdd457e262212a840a9dab3abf84ed8337a6f50b60f011fbc717b891b4ac78483cbc60224784f4dfc78cdc7b938ac29f22a6
6
+ metadata.gz: 6c1f85d0be4dc4a345afa45af335226a933a2d044a64fa787cb81d3985e986f921231862f1ff91de002a66769382ba7fab2240d5f9c0f6827d9a0ef76744472b
7
+ data.tar.gz: 54d9de6a6ac83d6a6ef59f75d39e7aa5042e202d2b1c4ea8dbaff7f001f00b56b2e4b52d89ded9dab333a548185d317158db80e2202b1148e7112839aeeff579
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.
@@ -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.1'
5
5
  end
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.1
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-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday