getimg_client 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/lib/getimg_client.rb +22 -11
- data/test/integration/getimg_client_integration_test.rb +30 -0
- 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: 0be3d07a0b0797a6ba6cda229533c2217aab46fddc7849a9c13bd3c65d94ba66
|
4
|
+
data.tar.gz: a14b88b25b2d50dd76717852a12b56d94342e0631ebfe2b6d888a0e829413ad1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda481b1a639b1ad5dedf15576747fdac585c81c26d55ff529ec3c27b1d75b94fe923fbf219c13f9c0f1c354d4cf89b392dd71c04ff5615fbe13266df1715266
|
7
|
+
data.tar.gz: 1b334b38945b0c6ffa5b203a8f8bad6cf3b92911343f3a81ed7ae8590a262611a3503ad0c4fd079fa64d07f96778d18a4f21ac9d47684d6465ddddce5f066689
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GetimgClient
|
1
|
+
# GetimgClient [![Gem Version](https://badge.fury.io/rb/getimg_client.svg)](https://badge.fury.io/rb/getimg_client)
|
2
2
|
|
3
3
|
## Introduction
|
4
4
|
GetimgClient is a Ruby gem designed to interact with the Getimg.ai API, enabling users to generate, manipulate, and enhance images using various AI models. This gem simplifies the process of making API requests to Getimg.ai, allowing for seamless integration of image generation and manipulation capabilities into your Ruby applications.
|
@@ -83,7 +83,7 @@ If an HTTP error occurs, the error message will include both the HTTP status and
|
|
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
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"
|
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" values at the API's end.
|
87
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
88
|
|
89
89
|
## Latent Consistency Models (LCM)
|
@@ -158,7 +158,21 @@ puts result["image"]
|
|
158
158
|
```
|
159
159
|
|
160
160
|
## Logging
|
161
|
-
|
161
|
+
GetimgClient supports logging request details for debugging and development purposes. The logging behavior depends on the environment and configuration:
|
162
|
+
|
163
|
+
Rails Development Environment: If the **RAILS_ENV** environment variable is set to "development" and Rails is defined, logs will be sent to the Rails logger.
|
164
|
+
|
165
|
+
**GETIMG_LOG** Environment Variable: If the GETIMG_LOG environment variable is set, logs will be printed to the standard output.
|
166
|
+
|
167
|
+
#### Log output example
|
168
|
+
```text
|
169
|
+
Generating image with the following details:
|
170
|
+
Prompt: A scenic landscape
|
171
|
+
Model: stable-diffusion-v1-5
|
172
|
+
Requested Pipeline: text-to-image
|
173
|
+
Endpoint URI: https://api.getimg.ai/v1/stable-diffusion/text-to-image
|
174
|
+
Options: {width: 512, height: 512}
|
175
|
+
```
|
162
176
|
|
163
177
|
## Unit Testing
|
164
178
|
The gem includes unit tests using Minitest. Integration tests make real API calls and will incur usage fees. Ensure your API key is set in the environment before running tests.
|
data/lib/getimg_client.rb
CHANGED
@@ -43,7 +43,7 @@ class GetimgClient
|
|
43
43
|
|
44
44
|
# Convert model to appropriate ID format
|
45
45
|
model_id = model.to_s.gsub('_', '-')
|
46
|
-
if
|
46
|
+
if %w[essential essential-v2].include?(model_id)
|
47
47
|
model_info = models[model_id] || { name: model_id, pipelines: ['text-to-image'] }
|
48
48
|
else
|
49
49
|
model_info = models[model_id] || raise(ArgumentError, "Unknown model: #{model}")
|
@@ -75,16 +75,8 @@ class GetimgClient
|
|
75
75
|
# Ensure scale is an integer if present
|
76
76
|
options[:scale] = options[:scale].to_i if options[:scale]
|
77
77
|
|
78
|
-
#
|
79
|
-
|
80
|
-
puts "Generating image with the following details:"
|
81
|
-
puts "Prompt: #{prompt}"
|
82
|
-
puts "Model: #{model_id}"
|
83
|
-
puts "Requested Pipeline: #{requested_pipeline}"
|
84
|
-
puts "Endpoint URI: #{uri}"
|
85
|
-
truncated_options = options.transform_values { |v| v.is_a?(String) && v.length > 50 ? "#{v[0, 50]}..." : v }
|
86
|
-
puts "Options: #{truncated_options}"
|
87
|
-
end
|
78
|
+
# Log the request details
|
79
|
+
log_request_details(prompt, model_id, requested_pipeline, uri, options)
|
88
80
|
|
89
81
|
# Create and send the request
|
90
82
|
request = create_request(uri, prompt, model: model_id, **options)
|
@@ -105,6 +97,25 @@ class GetimgClient
|
|
105
97
|
|
106
98
|
private
|
107
99
|
|
100
|
+
# Log request details
|
101
|
+
def self.log_request_details(prompt, model_id, requested_pipeline, uri, options)
|
102
|
+
log_message = <<~LOG
|
103
|
+
Generating image with the following details:
|
104
|
+
Prompt: #{prompt}
|
105
|
+
Model: #{model_id}
|
106
|
+
Requested Pipeline: #{requested_pipeline}
|
107
|
+
Endpoint URI: #{uri}
|
108
|
+
Options: #{options.transform_values { |v| v.is_a?(String) && v.length > 50 ? "#{v[0, 50]}..." : v }}
|
109
|
+
LOG
|
110
|
+
|
111
|
+
if (ENV['RAILS_ENV'] === 'development' || ENV['RAILS_ENV'].nil?) && defined?(Rails) && Rails.logger
|
112
|
+
Rails.logger.info(log_message)
|
113
|
+
end
|
114
|
+
if ENV['GETIMG_LOG']
|
115
|
+
puts log_message
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
108
119
|
# Determine the requested method based on provided image paths, controlnet, and model_info
|
109
120
|
def self.method_requested(base_image, mask_image_path, controlnet, model_info)
|
110
121
|
return :controlnet if controlnet
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "../test_helper"
|
2
|
+
require 'stringio'
|
2
3
|
|
3
4
|
class GetimgClientIntegrationTest < Minitest::Test
|
4
5
|
def setup
|
@@ -63,6 +64,35 @@ class GetimgClientIntegrationTest < Minitest::Test
|
|
63
64
|
save_image(result["image"], "test_generate_text_to_image_essential")
|
64
65
|
end
|
65
66
|
|
67
|
+
def test_logging_to_rails_logger
|
68
|
+
skip "Rails not defined, skipping Rails logger test" unless defined?(Rails) && (ENV['RAILS_ENV'] === 'development' || ENV['RAILS_ENV'].nil?)
|
69
|
+
|
70
|
+
original_logger = Rails.logger
|
71
|
+
log_output = StringIO.new
|
72
|
+
Rails.logger = Logger.new(log_output)
|
73
|
+
|
74
|
+
GetimgClient.generate_image("A scenic landscape", model: :stable_diffusion_v1_5, width: 512, height: 512)
|
75
|
+
|
76
|
+
assert_includes log_output.string, "Generating image with the following details:"
|
77
|
+
assert_includes log_output.string, "Prompt: A scenic landscape"
|
78
|
+
|
79
|
+
Rails.logger = original_logger
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_logging_to_puts
|
83
|
+
ENV['GETIMG_LOG'] = '1'
|
84
|
+
log_output = StringIO.new
|
85
|
+
$stdout = log_output
|
86
|
+
|
87
|
+
GetimgClient.generate_image("A scenic landscape", model: :stable_diffusion_v1_5, width: 512, height: 512)
|
88
|
+
|
89
|
+
assert_includes log_output.string, "Generating image with the following details:"
|
90
|
+
assert_includes log_output.string, "Prompt: A scenic landscape"
|
91
|
+
|
92
|
+
$stdout = STDOUT
|
93
|
+
ENV.delete('GETIMG_LOG')
|
94
|
+
end
|
95
|
+
|
66
96
|
private
|
67
97
|
|
68
98
|
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.6
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|