stability_sdk 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/generation_pb.rb CHANGED
@@ -21,6 +21,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
21
21
  optional :index, :uint32, 8
22
22
  optional :finish_reason, :enum, 9, "gooseai.FinishReason"
23
23
  optional :seed, :uint32, 10
24
+ optional :uuid, :string, 12
25
+ optional :size, :uint64, 13
24
26
  oneof :data do
25
27
  optional :binary, :bytes, 5
26
28
  optional :text, :string, 6
@@ -40,20 +42,6 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
40
42
  optional :artifact, :message, 4, "gooseai.Artifact"
41
43
  end
42
44
  end
43
- add_message "gooseai.AnswerMeta" do
44
- proto3_optional :gpu_id, :string, 1
45
- proto3_optional :cpu_id, :string, 2
46
- proto3_optional :node_id, :string, 3
47
- proto3_optional :engine_id, :string, 4
48
- end
49
- add_message "gooseai.Answer" do
50
- optional :answer_id, :string, 1
51
- optional :request_id, :string, 2
52
- optional :received, :uint64, 3
53
- optional :created, :uint64, 4
54
- proto3_optional :meta, :message, 6, "gooseai.AnswerMeta"
55
- repeated :artifacts, :message, 7, "gooseai.Artifact"
56
- end
57
45
  add_message "gooseai.SamplerParameters" do
58
46
  proto3_optional :eta, :float, 1
59
47
  proto3_optional :sampling_steps, :uint64, 2
@@ -63,15 +51,48 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
63
51
  end
64
52
  add_message "gooseai.ConditionerParameters" do
65
53
  proto3_optional :vector_adjust_prior, :string, 1
54
+ proto3_optional :conditioner, :message, 2, "gooseai.Model"
66
55
  end
67
56
  add_message "gooseai.ScheduleParameters" do
68
- optional :start, :float, 1
69
- optional :end, :float, 2
57
+ proto3_optional :start, :float, 1
58
+ proto3_optional :end, :float, 2
59
+ proto3_optional :value, :float, 3
70
60
  end
71
61
  add_message "gooseai.StepParameter" do
72
62
  optional :scaled_step, :float, 1
73
63
  proto3_optional :sampler, :message, 2, "gooseai.SamplerParameters"
74
64
  proto3_optional :schedule, :message, 3, "gooseai.ScheduleParameters"
65
+ proto3_optional :guidance, :message, 4, "gooseai.GuidanceParameters"
66
+ end
67
+ add_message "gooseai.Model" do
68
+ optional :architecture, :enum, 1, "gooseai.ModelArchitecture"
69
+ optional :publisher, :string, 2
70
+ optional :dataset, :string, 3
71
+ optional :version, :float, 4
72
+ optional :semantic_version, :string, 5
73
+ optional :alias, :string, 6
74
+ end
75
+ add_message "gooseai.CutoutParameters" do
76
+ repeated :cutouts, :message, 1, "gooseai.CutoutParameters"
77
+ proto3_optional :count, :uint32, 2
78
+ proto3_optional :gray, :float, 3
79
+ proto3_optional :blur, :float, 4
80
+ proto3_optional :size_power, :float, 5
81
+ end
82
+ add_message "gooseai.GuidanceScheduleParameters" do
83
+ optional :duration, :float, 1
84
+ optional :value, :float, 2
85
+ end
86
+ add_message "gooseai.GuidanceInstanceParameters" do
87
+ repeated :models, :message, 2, "gooseai.Model"
88
+ proto3_optional :guidance_strength, :float, 3
89
+ repeated :schedule, :message, 4, "gooseai.GuidanceScheduleParameters"
90
+ proto3_optional :cutouts, :message, 5, "gooseai.CutoutParameters"
91
+ proto3_optional :prompt, :message, 6, "gooseai.Prompt"
92
+ end
93
+ add_message "gooseai.GuidanceParameters" do
94
+ optional :guidance_preset, :enum, 1, "gooseai.GuidancePreset"
95
+ repeated :instances, :message, 2, "gooseai.GuidanceInstanceParameters"
75
96
  end
76
97
  add_message "gooseai.TransformType" do
77
98
  oneof :type do
@@ -104,17 +125,51 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
104
125
  repeated :exceeds, :message, 2, "gooseai.ClassifierCategory"
105
126
  proto3_optional :realized_action, :enum, 3, "gooseai.Action"
106
127
  end
128
+ add_message "gooseai.AssetParameters" do
129
+ optional :action, :enum, 1, "gooseai.AssetAction"
130
+ optional :project_id, :string, 2
131
+ optional :use, :enum, 3, "gooseai.AssetUse"
132
+ end
133
+ add_message "gooseai.AnswerMeta" do
134
+ proto3_optional :gpu_id, :string, 1
135
+ proto3_optional :cpu_id, :string, 2
136
+ proto3_optional :node_id, :string, 3
137
+ proto3_optional :engine_id, :string, 4
138
+ end
139
+ add_message "gooseai.Answer" do
140
+ optional :answer_id, :string, 1
141
+ optional :request_id, :string, 2
142
+ optional :received, :uint64, 3
143
+ optional :created, :uint64, 4
144
+ proto3_optional :meta, :message, 6, "gooseai.AnswerMeta"
145
+ repeated :artifacts, :message, 7, "gooseai.Artifact"
146
+ end
107
147
  add_message "gooseai.Request" do
108
148
  optional :engine_id, :string, 1
109
149
  optional :request_id, :string, 2
110
150
  optional :requested_type, :enum, 3, "gooseai.ArtifactType"
111
151
  repeated :prompt, :message, 4, "gooseai.Prompt"
112
152
  proto3_optional :conditioner, :message, 6, "gooseai.ConditionerParameters"
113
- proto3_optional :classifier, :message, 7, "gooseai.ClassifierParameters"
114
153
  oneof :params do
115
154
  optional :image, :message, 5, "gooseai.ImageParameters"
155
+ optional :classifier, :message, 7, "gooseai.ClassifierParameters"
156
+ optional :asset, :message, 8, "gooseai.AssetParameters"
116
157
  end
117
158
  end
159
+ add_message "gooseai.OnStatus" do
160
+ repeated :reason, :enum, 1, "gooseai.FinishReason"
161
+ proto3_optional :target, :string, 2
162
+ repeated :action, :enum, 3, "gooseai.StageAction"
163
+ end
164
+ add_message "gooseai.Stage" do
165
+ optional :id, :string, 1
166
+ optional :request, :message, 2, "gooseai.Request"
167
+ repeated :on_status, :message, 3, "gooseai.OnStatus"
168
+ end
169
+ add_message "gooseai.ChainRequest" do
170
+ optional :request_id, :string, 1
171
+ repeated :stage, :message, 2, "gooseai.Stage"
172
+ end
118
173
  add_enum "gooseai.FinishReason" do
119
174
  value :NULL, 0
120
175
  value :LENGTH, 1
@@ -147,6 +202,21 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
147
202
  value :UPSCALER_GFPGAN, 1
148
203
  value :UPSCALER_ESRGAN, 2
149
204
  end
205
+ add_enum "gooseai.GuidancePreset" do
206
+ value :GUIDANCE_PRESET_NONE, 0
207
+ value :GUIDANCE_PRESET_SIMPLE, 1
208
+ value :GUIDANCE_PRESET_FAST_BLUE, 2
209
+ value :GUIDANCE_PRESET_FAST_GREEN, 3
210
+ value :GUIDANCE_PRESET_SLOW, 4
211
+ value :GUIDANCE_PRESET_SLOWER, 5
212
+ value :GUIDANCE_PRESET_SLOWEST, 6
213
+ end
214
+ add_enum "gooseai.ModelArchitecture" do
215
+ value :MODEL_ARCHITECTURE_NONE, 0
216
+ value :MODEL_ARCHITECTURE_CLIP_VIT, 1
217
+ value :MODEL_ARCHITECTURE_CLIP_RESNET, 2
218
+ value :MODEL_ARCHITECTURE_LDM, 3
219
+ end
150
220
  add_enum "gooseai.Action" do
151
221
  value :ACTION_PASSTHROUGH, 0
152
222
  value :ACTION_REGENERATE_DUPLICATE, 1
@@ -159,6 +229,23 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
159
229
  value :CLSFR_MODE_ZEROSHOT, 0
160
230
  value :CLSFR_MODE_MULTICLASS, 1
161
231
  end
232
+ add_enum "gooseai.AssetAction" do
233
+ value :ASSET_PUT, 0
234
+ value :ASSET_GET, 1
235
+ value :ASSET_DELETE, 2
236
+ end
237
+ add_enum "gooseai.AssetUse" do
238
+ value :ASSET_USE_UNDEFINED, 0
239
+ value :ASSET_USE_INPUT, 1
240
+ value :ASSET_USE_OUTPUT, 2
241
+ value :ASSET_USE_INTERMEDIATE, 3
242
+ value :ASSET_USE_PROJECT, 4
243
+ end
244
+ add_enum "gooseai.StageAction" do
245
+ value :STAGE_ACTION_PASS, 0
246
+ value :STAGE_ACTION_DISCARD, 1
247
+ value :STAGE_ACTION_RETURN, 2
248
+ end
162
249
  end
163
250
  end
164
251
 
@@ -168,22 +255,36 @@ module Gooseai
168
255
  Artifact = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Artifact").msgclass
169
256
  PromptParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.PromptParameters").msgclass
170
257
  Prompt = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Prompt").msgclass
171
- AnswerMeta = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.AnswerMeta").msgclass
172
- Answer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Answer").msgclass
173
258
  SamplerParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.SamplerParameters").msgclass
174
259
  ConditionerParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ConditionerParameters").msgclass
175
260
  ScheduleParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ScheduleParameters").msgclass
176
261
  StepParameter = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.StepParameter").msgclass
262
+ Model = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Model").msgclass
263
+ CutoutParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.CutoutParameters").msgclass
264
+ GuidanceScheduleParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.GuidanceScheduleParameters").msgclass
265
+ GuidanceInstanceParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.GuidanceInstanceParameters").msgclass
266
+ GuidanceParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.GuidanceParameters").msgclass
177
267
  TransformType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.TransformType").msgclass
178
268
  ImageParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ImageParameters").msgclass
179
269
  ClassifierConcept = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ClassifierConcept").msgclass
180
270
  ClassifierCategory = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ClassifierCategory").msgclass
181
271
  ClassifierParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ClassifierParameters").msgclass
272
+ AssetParameters = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.AssetParameters").msgclass
273
+ AnswerMeta = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.AnswerMeta").msgclass
274
+ Answer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Answer").msgclass
182
275
  Request = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Request").msgclass
276
+ OnStatus = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.OnStatus").msgclass
277
+ Stage = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Stage").msgclass
278
+ ChainRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ChainRequest").msgclass
183
279
  FinishReason = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.FinishReason").enummodule
184
280
  ArtifactType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ArtifactType").enummodule
185
281
  DiffusionSampler = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.DiffusionSampler").enummodule
186
282
  Upscaler = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Upscaler").enummodule
283
+ GuidancePreset = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.GuidancePreset").enummodule
284
+ ModelArchitecture = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ModelArchitecture").enummodule
187
285
  Action = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.Action").enummodule
188
286
  ClassifierMode = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.ClassifierMode").enummodule
287
+ AssetAction = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.AssetAction").enummodule
288
+ AssetUse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.AssetUse").enummodule
289
+ StageAction = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gooseai.StageAction").enummodule
189
290
  end
@@ -6,6 +6,9 @@ require 'generation_pb'
6
6
 
7
7
  module Gooseai
8
8
  module GenerationService
9
+ #
10
+ # gRPC services
11
+ #
9
12
  class Service
10
13
 
11
14
  include ::GRPC::GenericService
@@ -15,6 +18,7 @@ module Gooseai
15
18
  self.service_name = 'gooseai.GenerationService'
16
19
 
17
20
  rpc :Generate, ::Gooseai::Request, stream(::Gooseai::Answer)
21
+ rpc :ChainGenerate, ::Gooseai::ChainRequest, stream(::Gooseai::Answer)
18
22
  end
19
23
 
20
24
  Stub = Service.rpc_stub_class
@@ -23,10 +23,15 @@ module StabilitySDK
23
23
  logger.warn "not implemented for ArtifactType #{artifact.type}"
24
24
  end
25
25
 
26
+ if artifact.finish_reason == :FILTER
27
+ logger.debug "the generated image is filtered"
28
+ end
29
+
26
30
  next if filename == "" || contents == ""
27
31
 
28
32
  File.open(filename, "wb") do |f|
29
33
  f.write(contents)
34
+ logger.debug "wrote #{artifact.type} to #{filename}"
30
35
  end
31
36
  end
32
37
  end
@@ -1,5 +1,6 @@
1
1
  require "grpc"
2
2
  require "generation_services_pb"
3
+ require "logger"
3
4
 
4
5
  module StabilitySDK
5
6
  class Client
@@ -14,7 +15,7 @@ module StabilitySDK
14
15
  DEFAULT_START_SCHEDULE = 1.0
15
16
  DEFAULT_END_SCHEDULE = 0.01
16
17
 
17
- sampler_algorithms = {
18
+ SAMPLER_ALGORITHMS = {
18
19
  "ddim": Gooseai::DiffusionSampler::SAMPLER_DDIM,
19
20
  "plms": Gooseai::DiffusionSampler::SAMPLER_DDPM,
20
21
  "k_euler": Gooseai::DiffusionSampler::SAMPLER_K_EULER,
@@ -31,24 +32,42 @@ module StabilitySDK
31
32
  call_creds = GRPC::Core::CallCredentials.new(proc { { "authorization" => "Bearer #{options[:api_key]}" } })
32
33
  creds = channel_creds.compose(call_creds)
33
34
 
34
- @stub = Gooseai::GenerationService::Stub.new(host, creds)
35
+ stub_params = {}
36
+ [:channel_override, :timeout, :propagate_mask, :channel_args, :interceptors].each do |kw|
37
+ stub_params[kw] = options[kw] if options.has_key?(kw)
38
+ end
39
+
40
+ if options.has_key?(:logger)
41
+ @logger = options[:logger]
42
+ else
43
+ logger = Logger.new(STDOUT)
44
+ logger.level = Logger::WARN
45
+ @logger = logger
46
+ end
47
+
48
+ @stub = Gooseai::GenerationService::Stub.new(host, creds, **stub_params)
35
49
  end
36
50
 
37
51
  def generate(prompt, options, &block)
38
- width = options.has_key?(:width) ? options[:width].to_i : DEFAULT_IMAGE_WIDTH
39
- height = options.has_key?(:height) ? options[:height].to_i : DEFAULT_IMAGE_HEIGHT
40
- samples = options.has_key?(:num_samples) ? [:num_samples].to_i : DEFAULT_SAMPLE_SIZE
41
- steps = options.has_key?(:steps) ? options[:steps].to_i : DEFAULT_STEPS
52
+ width = options.has_key?(:width) ? options[:width] : DEFAULT_IMAGE_WIDTH
53
+ height = options.has_key?(:height) ? options[:height] : DEFAULT_IMAGE_HEIGHT
54
+
55
+ if width % 64 != 0 || height % 64 != 0
56
+ raise InvalidParameter, "width and height must be a multiple of 64"
57
+ end
58
+
59
+ samples = options.has_key?(:num_samples) ? options[:num_samples] : DEFAULT_SAMPLE_SIZE
60
+ steps = options.has_key?(:steps) ? options[:steps] : DEFAULT_STEPS
42
61
  seed = options.has_key?(:seed) ? [options[:seed]] : [rand(4294967295)]
43
62
  transform = Gooseai::TransformType.new(
44
- diffusion: options.has_key?(:sampler) ? sampler_algorithms[options[:sampler]] : DEFAULT_SAMPLER_ALGORITHM,
63
+ diffusion: options.has_key?(:sampler) ? SAMPLER_ALGORITHMS[options[:sampler].to_sym] : DEFAULT_SAMPLER_ALGORITHM,
45
64
  )
46
- parameters = [Gooseai::StepParameter.new(
65
+ step_parameter = Gooseai::StepParameter.new(
47
66
  scaled_step: 0,
48
67
  sampler: Gooseai::SamplerParameters.new(
49
- cfg_scale: options.has_key?(:cfg_scale) ? options[:cfg_scale].to_f : DEFAULT_CFG_SCALE,
68
+ cfg_scale: options.has_key?(:cfg_scale) ? options[:cfg_scale] : DEFAULT_CFG_SCALE,
50
69
  ),
51
- )]
70
+ )
52
71
 
53
72
  prompt_param = []
54
73
  if prompt != ""
@@ -56,21 +75,65 @@ module StabilitySDK
56
75
  end
57
76
  if options.has_key?(:init_image)
58
77
  prompt_param << init_image_to_prompt(options[:init_image])
59
- parameters = [Gooseai::StepParameter.new(
60
- scaled_step: 0,
61
- sampler: Gooseai::SamplerParameters.new(
62
- cfg_scale: options.has_key?(:cfg_scale) ? options[:cfg_scale].to_f : DEFAULT_CFG_SCALE,
63
- ),
64
- schedule: Gooseai::ScheduleParameters.new(
65
- start: options.has_key?(:start_schedule) ? options[:start_schedule].to_f : DEFAULT_START_SCHEDULE,
66
- end: options.has_key?(:end_schedule) ? options[:end_schedule].to_f : DEFAULT_END_SCHEDULE,
67
- ),
68
- )]
78
+ step_parameter.scaled_step = 0
79
+ step_parameter.sampler = Gooseai::SamplerParameters.new(
80
+ cfg_scale: options.has_key?(:cfg_scale) ? options[:cfg_scale] : DEFAULT_CFG_SCALE,
81
+ )
82
+ step_parameter.schedule = Gooseai::ScheduleParameters.new(
83
+ start: options.has_key?(:start_schedule) ? options[:start_schedule] : DEFAULT_START_SCHEDULE,
84
+ end: options.has_key?(:end_schedule) ? options[:end_schedule] : DEFAULT_END_SCHEDULE,
85
+ )
69
86
  end
70
87
  if options.has_key?(:mask_image)
71
88
  prompt_param << mask_image_to_prompt(options[:mask_image])
72
89
  end
73
90
 
91
+ # CLIP guidance
92
+ if options.has_key?(:guidance_preset) && options[:guidance_preset] != "GUIDANCE_PRESET_NONE"
93
+ step_parameter.sampler = nil
94
+
95
+ guidance_prompt =
96
+ if options.has_key?(:guidance_prompt)
97
+ Gooseai::Prompt.new(text: options[:guidance_prompt])
98
+ else
99
+ Gooseai::Prompt.new(text: prompt)
100
+ end
101
+
102
+ guidance_strength = nil
103
+ if options.has_key?(:guidance_strength) && options[:guidance_strength] != 0
104
+ guidance_strength = options[:guidance_strength]
105
+ end
106
+
107
+ models = nil
108
+ if options.has_key?(:guidance_models)
109
+ models = options[:guidance_models].map { |m| Gooseai::Model.new(alias: m) }
110
+ end
111
+
112
+ cutouts = nil
113
+ if options.has_key?(:guidance_cuts)
114
+ cutouts = Gooseai::CutoutParameters.new(count: options[:guidance_cuts])
115
+ end
116
+
117
+ step_parameter.guidance = Gooseai::GuidanceParameters.new(
118
+ guidance_preset: Gooseai::GuidancePreset.const_get(options[:guidance_preset].to_sym),
119
+ instances: [
120
+ Gooseai::GuidanceInstanceParameters.new(
121
+ guidance_strength: guidance_strength,
122
+ models: models,
123
+ cutouts: cutouts,
124
+ prompt: guidance_prompt,
125
+ ),
126
+ ],
127
+ )
128
+
129
+ if transform.diffusion != Gooseai::DiffusionSampler::SAMPLER_K_DPM_2_ANCESTRAL && transform.diffusion != Gooseai::DiffusionSampler::SAMPLER_K_EULER_ANCESTRAL
130
+ transform = Gooseai::TransformType.new(
131
+ diffusion: Gooseai::DiffusionSampler::SAMPLER_K_DPM_2_ANCESTRAL
132
+ )
133
+ @logger.warn "CLIP guidance is only supported with ancestral samplers. So override it with SAMPLER_K_DPM_2_ANCESTRAL."
134
+ end
135
+ end
136
+
74
137
  image_param = Gooseai::ImageParameters.new(
75
138
  width: width,
76
139
  height: height,
@@ -78,7 +141,7 @@ module StabilitySDK
78
141
  steps: steps,
79
142
  seed: seed,
80
143
  transform: transform,
81
- parameters: parameters,
144
+ parameters: [step_parameter],
82
145
  )
83
146
 
84
147
  req = Gooseai::Request.new(
@@ -87,8 +150,20 @@ module StabilitySDK
87
150
  image: image_param
88
151
  )
89
152
 
153
+ @logger.debug "sending request."
154
+ start = Time.now
90
155
  @stub.generate(req).each do |answer|
156
+ duration = Time.now - start
157
+ if answer.artifacts.size > 0
158
+ artifact_types = answer.artifacts.map { |a| a.type }
159
+ @logger.debug "got #{answer.answer_id} with #{artifact_types} in #{duration.round(2)}s"
160
+ else
161
+ @logger.debug "got keepalive #{answer.answer_id} in #{duration.round(2)}s"
162
+ end
163
+
91
164
  block.call(answer)
165
+
166
+ start = Time.now
92
167
  end
93
168
  end
94
169
 
@@ -0,0 +1,31 @@
1
+ require "grpc"
2
+ require "dashboard_services_pb"
3
+
4
+ module StabilitySDK
5
+ class DashboardClient
6
+ DEFAULT_API_HOST = "grpc.stability.ai:443"
7
+
8
+ def initialize(options={})
9
+ host = options[:api_host] || DEFAULT_API_HOST
10
+ channel_creds = options.has_key?(:ca_cert) ? GRPC::Core::ChannelCredentials.new(options[:ca_cert]) : GRPC::Core::ChannelCredentials.new
11
+ call_creds = GRPC::Core::CallCredentials.new(proc { { "authorization" => "Bearer #{options[:api_key]}" } })
12
+ creds = channel_creds.compose(call_creds)
13
+
14
+ stub_params = {}
15
+ [:channel_override, :timeout, :propagate_mask, :channel_args, :interceptors].each do |kw|
16
+ stub_params[kw] = options[kw] if options.has_key?(kw)
17
+ end
18
+
19
+ @stub = Gooseai::DashboardService::Stub.new(host, creds, **stub_params)
20
+ end
21
+
22
+ def get_me
23
+ @stub.get_me(Gooseai::EmptyRequest.new)
24
+ end
25
+
26
+ def get_organization
27
+ me = self.get_me
28
+ @stub.get_organization(Gooseai::GetChargesRequest.new(organization_id: me.organizations[0].organization.id))
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module StabilitySDK
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/stability_sdk.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require "stability_sdk/version"
2
2
  require "stability_sdk/client"
3
3
  require "stability_sdk/cli"
4
+ require "stability_sdk/dashboard_client"
4
5
 
5
6
  module StabilitySDK
6
7
  class Error < StandardError; end
7
8
  class InsufficientParameter < StandardError; end
9
+ class InvalidParameter < StandardError; end
8
10
  end
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = "Interacting with stability.ai APIs (e.g. stable diffusion inference). Ruby client of https://github.com/Stability-AI/stability-sdk ."
11
11
  spec.homepage = "https://github.com/cou929/stability-sdk-ruby"
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.license = "MIT"
13
14
 
14
15
  spec.metadata["homepage_uri"] = spec.homepage
15
16
  spec.metadata["source_code_uri"] = "https://github.com/cou929/stability-sdk-ruby"
@@ -24,7 +25,9 @@ Gem::Specification.new do |spec|
24
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
26
  spec.require_paths = ["lib"]
26
27
 
27
- spec.add_dependency "grpc"
28
- spec.add_dependency "mime-types"
28
+ spec.add_dependency "grpc", ">= 1.41.1"
29
+ spec.add_dependency "mime-types", ">= 3.0.0"
30
+ spec.add_dependency "fastimage", "~> 2.2", ">= 2.2.6"
31
+ spec.add_dependency "thor", ">= 1.2.1"
29
32
  spec.add_development_dependency "grpc-tools"
30
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stability_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kosei Moriyama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -16,28 +16,62 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.41.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.41.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 3.0.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: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: fastimage
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.2.6
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.2'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.2.6
61
+ - !ruby/object:Gem::Dependency
62
+ name: thor
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 1.2.1
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.2.1
41
75
  - !ruby/object:Gem::Dependency
42
76
  name: grpc-tools
43
77
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +92,34 @@ email:
58
92
  - cou929@gmail.com
59
93
  executables:
60
94
  - stability-client
95
+ - stability-dashboard-client
61
96
  extensions: []
62
97
  extra_rdoc_files: []
63
98
  files:
64
99
  - ".gitignore"
100
+ - ".gitmodules"
65
101
  - ".travis.yml"
66
102
  - Gemfile
67
- - Gemfile.lock
103
+ - LICENSE
68
104
  - README.md
69
105
  - Rakefile
70
106
  - bin/console
71
107
  - bin/setup
72
108
  - exe/stability-client
109
+ - exe/stability-dashboard-client
110
+ - lib/dashboard_pb.rb
111
+ - lib/dashboard_services_pb.rb
73
112
  - lib/generation_pb.rb
74
113
  - lib/generation_services_pb.rb
75
114
  - lib/stability_sdk.rb
76
115
  - lib/stability_sdk/cli.rb
77
116
  - lib/stability_sdk/client.rb
117
+ - lib/stability_sdk/dashboard_client.rb
78
118
  - lib/stability_sdk/version.rb
79
- - proto/generation.proto
80
119
  - stability_sdk.gemspec
81
120
  homepage: https://github.com/cou929/stability-sdk-ruby
82
- licenses: []
121
+ licenses:
122
+ - MIT
83
123
  metadata:
84
124
  homepage_uri: https://github.com/cou929/stability-sdk-ruby
85
125
  source_code_uri: https://github.com/cou929/stability-sdk-ruby
@@ -99,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
139
  - !ruby/object:Gem::Version
100
140
  version: '0'
101
141
  requirements: []
102
- rubygems_version: 3.1.4
142
+ rubygems_version: 3.1.6
103
143
  signing_key:
104
144
  specification_version: 4
105
145
  summary: Ruby client for interacting with stability.ai APIs (e.g. stable diffusion
data/Gemfile.lock DELETED
@@ -1,34 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- stability_sdk (0.2.0)
5
- grpc
6
- mime-types
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- google-protobuf (3.21.5)
12
- googleapis-common-protos-types (1.4.0)
13
- google-protobuf (~> 3.14)
14
- grpc (1.48.0)
15
- google-protobuf (~> 3.19)
16
- googleapis-common-protos-types (~> 1.0)
17
- grpc-tools (1.48.0)
18
- mime-types (3.4.1)
19
- mime-types-data (~> 3.2015)
20
- mime-types-data (3.2022.0105)
21
- minitest (5.16.3)
22
- rake (12.3.3)
23
-
24
- PLATFORMS
25
- arm64-darwin-20
26
-
27
- DEPENDENCIES
28
- grpc-tools
29
- minitest (~> 5.0)
30
- rake (~> 12.0)
31
- stability_sdk!
32
-
33
- BUNDLED WITH
34
- 2.2.2