getimg_client 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -6
- data/lib/endpoints.json +1 -0
- data/lib/getimg_client.rb +15 -9
- data/test/integration/getimg_client_integration_test.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df68c244073fbc74c6cb913c4b9208c40a2d136d226a1974dec6addae2bc4682
|
4
|
+
data.tar.gz: 641715c9f551b30eb44f06252be3ded05df990676e5260cff8e89893d3b0ca77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5249e227172db1f03aeced82d4a8f6429b1ad75c6eaa2c51d0285000e0f324b9b14ef833bc638949dd35e3aef03d1ab99c93049a0de65bebe57c58d8f9d35f97
|
7
|
+
data.tar.gz: dec0e93875f2d227ac3a7128b57d7e65f7f3d8b334f7f4c379f7a4cb87b1c6aa0672789979b950a65cd5f96bc6fabb2fb0cf9f613d8596147b8449dffbb7b9dd
|
data/README.md
CHANGED
@@ -46,14 +46,14 @@ Fetch and cache the list of available models from the API.
|
|
46
46
|
### `models`
|
47
47
|
Retrieve cached models or fetch them if not already retrieved.
|
48
48
|
|
49
|
-
### `generate_image(prompt, model
|
50
|
-
Generate an image based on a text prompt and specified model. Supports various image manipulation methods such as image-to-image, inpainting, controlnet, face fixing, instruct and upscaling.
|
49
|
+
### `generate_image(prompt, model: :essential, **options)`
|
50
|
+
Generate an image based on a text prompt and specified model. Supports various image manipulation methods such as image-to-image, inpainting, controlnet, face fixing, instruct, and upscaling. Specifying a model is optional; by default, it will invoke the Essential V1 endpoint.
|
51
51
|
|
52
52
|
### `get_balance`
|
53
53
|
Retrieve the current account balance from the Getimg.ai API.
|
54
54
|
|
55
55
|
## Request Routing
|
56
|
-
The `generate_image` method routes requests based on the provided options and the model's supported pipelines, sending it to its respective pipeline whether that's SD1.5, SDXL or LCM based:
|
56
|
+
The `generate_image` method routes requests based on the provided options and the model's supported pipelines, sending it to its respective pipeline whether that's SD1.5, SDXL, Essential, or LCM based:
|
57
57
|
- **text-to-image**: Default if no images are provided.
|
58
58
|
- **image-to-image**: Triggered if a base image is provided.
|
59
59
|
- **inpaint**: Triggered if a mask image is provided.
|
@@ -82,8 +82,12 @@ If an HTTP error occurs, the error message will include both the HTTP status and
|
|
82
82
|
## Models
|
83
83
|
The provided `model` option will determine the model use, and contribute to the client's inference of the desired endpoint. Models can be the string `id` listed online at [the GetImg dashboard](https://dashboard.getimg.ai/models) or retrieved using the `GetimgClient.models` method. Equally, you can use symbols instead. For example, `:realistic_vision_v5_1` will translate to `'realistic-vision-v5-1'`
|
84
84
|
|
85
|
+
## Essential
|
86
|
+
Getimg offers the "essential" checkpoints, which perform more abstract Stable Diffusion operations based on the provided prompt. Note that *:essential* and *:essential_v2* will *not* be listed in the model listing, as these are not in fact actual models, nor valid "model" value at the API's end.
|
87
|
+
In order to route a request to Essential or Essential V2 however, you can provide *:essential* or *:essential_v2* as a model argument in *#generate_image*.
|
88
|
+
|
85
89
|
## Latent Consistency Models (LCM)
|
86
|
-
Latent
|
90
|
+
Latent Consistency Models (LCM) are optimized for faster image generation and lower costs by avoiding the repetitive steps of traditional diffusion methods. They work in a lower-dimensional space, resulting in quicker outputs but with slightly less detail compared to standard models.
|
87
91
|
|
88
92
|
## Base Image Options
|
89
93
|
The `base_image` option can be provided, which will automatically set the "image" property for image-to-image, controlnet, face-fix, upscale, inpaint and instruct calls, and can be either a file path or a base64 encoded string of the file contents.
|
@@ -98,7 +102,13 @@ If all went well and no errors were reported, the response will be equal to the
|
|
98
102
|
GetimgClient.set_api_key('your_api_key')
|
99
103
|
```
|
100
104
|
|
101
|
-
### Generate Text-to-Image
|
105
|
+
### Generate Text-to-Image using Essential V1 with default options
|
106
|
+
```ruby
|
107
|
+
result = GetimgClient.generate_image("A city skyline at night")
|
108
|
+
puts result["image"]
|
109
|
+
```
|
110
|
+
|
111
|
+
### Generate Text-to-Image using Stable Diffusion 1.5
|
102
112
|
```ruby
|
103
113
|
result = GetimgClient.generate_image("A scenic landscape", model: :stable_diffusion_v1_5, width: 512, height: 512)
|
104
114
|
puts result["image"]
|
@@ -114,7 +124,7 @@ puts result["image"]
|
|
114
124
|
### Generate an image using Controlnet
|
115
125
|
```ruby
|
116
126
|
base_image = "path/to/base_image.jpg"
|
117
|
-
result = GetimgClient.generate_image("Enhance the scene", model: :stable_diffusion_v1_5, base_image:, strength: 0.7, controlnet: canny-1.1)
|
127
|
+
result = GetimgClient.generate_image("Enhance the scene", model: :stable_diffusion_v1_5, base_image:, strength: 0.7, controlnet: 'canny-1.1')
|
118
128
|
puts result["image"]
|
119
129
|
```
|
120
130
|
|
data/lib/endpoints.json
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
"lcm_text_to_image": "https://api.getimg.ai/v1/latent-consistency/text-to-image",
|
11
11
|
"lcm_image_to_image": "https://api.getimg.ai/v1/latent-consistency/image-to-image",
|
12
12
|
"essential_text_to_image": "https://api.getimg.ai/v1/essential/text-to-image",
|
13
|
+
"essentialv2_text_to_image": "https://api.getimg.ai/v1/essential-v2/text-to-image",
|
13
14
|
"face_fix": "https://api.getimg.ai/v1/enhancements/face-fix",
|
14
15
|
"upscale": "https://api.getimg.ai/v1/enhancements/upscale",
|
15
16
|
"models": "https://api.getimg.ai/v1/models",
|
data/lib/getimg_client.rb
CHANGED
@@ -32,7 +32,7 @@ class GetimgClient
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# Generate an image based on the prompt and model
|
35
|
-
def self.generate_image(prompt, model
|
35
|
+
def self.generate_image(prompt, model: :essential, **options)
|
36
36
|
# Validate the prompt
|
37
37
|
raise ArgumentError, 'Prompt is required' unless prompt.is_a?(String) && !prompt.strip.empty?
|
38
38
|
|
@@ -43,7 +43,11 @@ class GetimgClient
|
|
43
43
|
|
44
44
|
# Convert model to appropriate ID format
|
45
45
|
model_id = model.to_s.gsub('_', '-')
|
46
|
-
|
46
|
+
if model_id === 'essential' || model_id === 'essential-v2'
|
47
|
+
model_info = models[model_id] || { name: model_id, pipelines: ['text-to-image'] }
|
48
|
+
else
|
49
|
+
model_info = models[model_id] || raise(ArgumentError, "Unknown model: #{model}")
|
50
|
+
end
|
47
51
|
|
48
52
|
# Determine the requested pipeline
|
49
53
|
requested_pipeline = method_requested(base_image, mask_image_path, controlnet, model_info).to_s.gsub('_', '-')
|
@@ -54,7 +58,7 @@ class GetimgClient
|
|
54
58
|
end
|
55
59
|
|
56
60
|
# Determine the endpoint key based on the model family and pipeline
|
57
|
-
endpoint_key = determine_endpoint_key(model_info, requested_pipeline)
|
61
|
+
endpoint_key = determine_endpoint_key(model_info, requested_pipeline, model_id)
|
58
62
|
uri = URI(API_ENDPOINTS[endpoint_key.to_s])
|
59
63
|
|
60
64
|
# Handle image to image, controlnet, instruct, inpaint, face-fix, and upscale pipelines
|
@@ -113,8 +117,12 @@ class GetimgClient
|
|
113
117
|
end
|
114
118
|
|
115
119
|
# Determine the appropriate endpoint key based on the model family and pipeline
|
116
|
-
def self.determine_endpoint_key(model_info, requested_pipeline)
|
117
|
-
if
|
120
|
+
def self.determine_endpoint_key(model_info, requested_pipeline, model_id)
|
121
|
+
if model_id == 'essential'
|
122
|
+
return :essential_text_to_image
|
123
|
+
elsif model_id == 'essential-v2'
|
124
|
+
return :essentialv2_text_to_image
|
125
|
+
elsif model_info[:family] == 'stable-diffusion-xl'
|
118
126
|
return :sdxl_image_to_image if requested_pipeline == 'image-to-image'
|
119
127
|
return :sdxl_inpaint if requested_pipeline == 'inpaint'
|
120
128
|
return :sdxl_text_to_image
|
@@ -133,10 +141,8 @@ class GetimgClient
|
|
133
141
|
request['accept'] = 'application/json'
|
134
142
|
request['content-type'] = 'application/json'
|
135
143
|
|
136
|
-
body = {
|
137
|
-
|
138
|
-
model: model
|
139
|
-
}.merge(options)
|
144
|
+
body = { prompt: prompt }.merge(options)
|
145
|
+
body[:model] = model unless %w[essential essential-v2].include?(model)
|
140
146
|
|
141
147
|
request.body = body.to_json
|
142
148
|
request
|
@@ -3,9 +3,7 @@ require_relative "../test_helper"
|
|
3
3
|
class GetimgClientIntegrationTest < Minitest::Test
|
4
4
|
def setup
|
5
5
|
@base_image = Base64.strict_encode64(File.read(File.join(__dir__, "sample_image.jpeg")))
|
6
|
-
|
7
6
|
@small_image = Base64.strict_encode64(File.read(File.join(__dir__, "small_sample_image.jpeg")))
|
8
|
-
|
9
7
|
@mask_image = Base64.strict_encode64(File.read(File.join(__dir__, "mask_image.jpeg")))
|
10
8
|
end
|
11
9
|
|
@@ -58,6 +56,13 @@ class GetimgClientIntegrationTest < Minitest::Test
|
|
58
56
|
save_image(result["image"], "test_upscale")
|
59
57
|
end
|
60
58
|
|
59
|
+
def test_generate_text_to_image_essential
|
60
|
+
puts "-- Running test_generate_text_to_image_essential..."
|
61
|
+
result = GetimgClient.generate_image("A modern cityscape")
|
62
|
+
assert result["image"]
|
63
|
+
save_image(result["image"], "test_generate_text_to_image_essential")
|
64
|
+
end
|
65
|
+
|
61
66
|
private
|
62
67
|
|
63
68
|
def save_image(base64_image, filename)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getimg_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Melvin Sommer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|