runapi-grok-imagine 0.2.14 → 0.2.16
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.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/lib/runapi/grok_imagine/client.rb +3 -0
- data/lib/runapi/grok_imagine/contract_gen.rb +78 -4
- data/lib/runapi/grok_imagine/resources/edit_image.rb +5 -2
- data/lib/runapi/grok_imagine/resources/segment_map.rb +43 -0
- data/lib/runapi/grok_imagine/types.rb +15 -0
- data/lib/runapi/grok_imagine.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2412da27da9fdbe2b64e75e625496bcfc0ca3ee20b725139e70397201b2f8b28
|
|
4
|
+
data.tar.gz: d691869681c3af4c284d4c26a16479126f518c34646d56958c853506f12e2811
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ccf097c1e1b376bad6344a545b3c8280c913e65ae2eec4e5b933605105573e07edd60647c81d3655302fbdbf22b75eb69de6c71640b9fe2ffcb40d40ff47987
|
|
7
|
+
data.tar.gz: 4e8d3b221374ca657257eb396d482bc3d1c88b0fb642e671ae67f7dc05231f4f088c37ed592d78a878a2c638bc064a6fac51c7ffdce90cdd2db39d599a1784c9
|
data/README.md
CHANGED
|
@@ -22,6 +22,19 @@ task = client.text_to_video.create(
|
|
|
22
22
|
status = client.text_to_video.get(task.id)
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
## Edit with Image 2.0
|
|
26
|
+
|
|
27
|
+
Image 2.0 edits one to five source images directly. Provide the source URLs and output aspect ratio; the edit prompt is optional. The task-based `source_task_id` and `mask_indices` fields are no longer accepted by this request.
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
edit = client.edit_image.create(
|
|
31
|
+
model: "grok-imagine-image-2-0",
|
|
32
|
+
source_image_urls: ["https://cdn.runapi.ai/public/samples/input.png"],
|
|
33
|
+
aspect_ratio: "1:1",
|
|
34
|
+
prompt: "Change the background to a sunset beach"
|
|
35
|
+
)
|
|
36
|
+
```
|
|
37
|
+
|
|
25
38
|
Use `create` when you want to submit a task and return quickly, `get` when you need the latest task state, and `run` when a script should create and poll until completion. In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
|
|
26
39
|
|
|
27
40
|
RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
|
|
@@ -39,7 +52,6 @@ Use Ruby keyword arguments and the `RunApi::GrokImagine` error classes when buil
|
|
|
39
52
|
- Video 1.5 Fast pricing and rate limits: https://runapi.ai/models/grok-imagine/video-1.5-fast
|
|
40
53
|
- Text-to-video pricing and rate limits: https://runapi.ai/models/grok-imagine/text-to-video
|
|
41
54
|
- Image-to-video pricing and rate limits: https://runapi.ai/models/grok-imagine/image-to-video
|
|
42
|
-
- Provider comparison: https://runapi.ai/providers/xai
|
|
43
55
|
- Full catalog: https://runapi.ai/models
|
|
44
56
|
- Repository: https://github.com/runapi-ai/grok-imagine-sdk
|
|
45
57
|
|
|
@@ -18,6 +18,8 @@ module RunApi
|
|
|
18
18
|
attr_reader :image_to_video
|
|
19
19
|
# @return [Resources::TextToImage] Text-to-image generation operations.
|
|
20
20
|
attr_reader :text_to_image
|
|
21
|
+
# @return [Resources::SegmentMap] Segmentation map generation operations.
|
|
22
|
+
attr_reader :segment_map
|
|
21
23
|
# @return [Resources::EditImage] Prompt-guided image editing operations.
|
|
22
24
|
attr_reader :edit_image
|
|
23
25
|
# @return [Resources::Extensions] Extend a previously generated video.
|
|
@@ -31,6 +33,7 @@ module RunApi
|
|
|
31
33
|
@text_to_video = Resources::TextToVideo.new(http)
|
|
32
34
|
@image_to_video = Resources::ImageToVideo.new(http)
|
|
33
35
|
@text_to_image = Resources::TextToImage.new(http)
|
|
36
|
+
@segment_map = Resources::SegmentMap.new(http)
|
|
34
37
|
@edit_image = Resources::EditImage.new(http)
|
|
35
38
|
@extensions = Resources::Extensions.new(http)
|
|
36
39
|
@upscales = Resources::Upscales.new(http)
|
|
@@ -4,7 +4,7 @@ module RunApi
|
|
|
4
4
|
module GrokImagine
|
|
5
5
|
CONTRACT = {
|
|
6
6
|
"edit-image" => {
|
|
7
|
-
"models" => ["grok-imagine-edit-image"],
|
|
7
|
+
"models" => ["grok-imagine-edit-image", "grok-imagine-image-2-0"],
|
|
8
8
|
"fields_by_model" => {
|
|
9
9
|
"grok-imagine-edit-image" => {
|
|
10
10
|
"model" => {
|
|
@@ -13,8 +13,37 @@ module RunApi
|
|
|
13
13
|
"source_image_url" => {
|
|
14
14
|
"required" => true
|
|
15
15
|
}
|
|
16
|
+
},
|
|
17
|
+
"grok-imagine-image-2-0" => {
|
|
18
|
+
"aspect_ratio" => {
|
|
19
|
+
"enum" => ["1:1", "2:3", "3:2", "16:9", "9:16", "auto"],
|
|
20
|
+
"required" => true
|
|
21
|
+
},
|
|
22
|
+
"model" => {
|
|
23
|
+
"required" => true
|
|
24
|
+
},
|
|
25
|
+
"prompt" => {
|
|
26
|
+
"max" => 390000,
|
|
27
|
+
"length" => true
|
|
28
|
+
},
|
|
29
|
+
"source_image_urls" => {
|
|
30
|
+
"required" => true,
|
|
31
|
+
"min_items" => 1,
|
|
32
|
+
"max_items" => 5
|
|
33
|
+
}
|
|
16
34
|
}
|
|
17
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"rules" => [{
|
|
37
|
+
"when" => {
|
|
38
|
+
"model" => "grok-imagine-edit-image"
|
|
39
|
+
},
|
|
40
|
+
"forbidden" => ["source_task_id", "mask_indices", "source_image_urls", "aspect_ratio"]
|
|
41
|
+
}, {
|
|
42
|
+
"when" => {
|
|
43
|
+
"model" => "grok-imagine-image-2-0"
|
|
44
|
+
},
|
|
45
|
+
"forbidden" => ["source_image_url", "source_task_id", "mask_indices", "enable_safety_checker"]
|
|
46
|
+
}]
|
|
18
47
|
},
|
|
19
48
|
"extend" => {
|
|
20
49
|
"models" => [],
|
|
@@ -146,9 +175,48 @@ module RunApi
|
|
|
146
175
|
"forbidden" => ["source_task_id", "index", "motion_style", "enable_safety_checker"]
|
|
147
176
|
}]
|
|
148
177
|
},
|
|
178
|
+
"segment-map" => {
|
|
179
|
+
"models" => ["grok-imagine-image-2-0"],
|
|
180
|
+
"fields_by_model" => {
|
|
181
|
+
"grok-imagine-image-2-0" => {
|
|
182
|
+
"model" => {
|
|
183
|
+
"required" => true
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"rules" => [{
|
|
188
|
+
"required_any" => ["image_url", "source_task_id"]
|
|
189
|
+
}, {
|
|
190
|
+
"when" => {
|
|
191
|
+
"image_url" => {
|
|
192
|
+
"present" => true
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"forbidden" => ["source_task_id"]
|
|
196
|
+
}, {
|
|
197
|
+
"when" => {
|
|
198
|
+
"source_task_id" => {
|
|
199
|
+
"present" => true
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
"forbidden" => ["image_url"]
|
|
203
|
+
}]
|
|
204
|
+
},
|
|
149
205
|
"text-to-image" => {
|
|
150
|
-
"models" => ["grok-imagine-text-to-image"],
|
|
206
|
+
"models" => ["grok-imagine-image-2-0", "grok-imagine-text-to-image"],
|
|
151
207
|
"fields_by_model" => {
|
|
208
|
+
"grok-imagine-image-2-0" => {
|
|
209
|
+
"aspect_ratio" => {
|
|
210
|
+
"enum" => ["1:1", "2:3", "3:2", "16:9", "9:16"],
|
|
211
|
+
"required" => true
|
|
212
|
+
},
|
|
213
|
+
"model" => {
|
|
214
|
+
"required" => true
|
|
215
|
+
},
|
|
216
|
+
"prompt" => {
|
|
217
|
+
"required" => true
|
|
218
|
+
}
|
|
219
|
+
},
|
|
152
220
|
"grok-imagine-text-to-image" => {
|
|
153
221
|
"aspect_ratio" => {
|
|
154
222
|
"enum" => ["2:3", "3:2", "1:1", "16:9", "9:16"]
|
|
@@ -162,7 +230,13 @@ module RunApi
|
|
|
162
230
|
"length" => true
|
|
163
231
|
}
|
|
164
232
|
}
|
|
165
|
-
}
|
|
233
|
+
},
|
|
234
|
+
"rules" => [{
|
|
235
|
+
"when" => {
|
|
236
|
+
"model" => "grok-imagine-image-2-0"
|
|
237
|
+
},
|
|
238
|
+
"forbidden" => ["enable_safety_checker", "enable_pro"]
|
|
239
|
+
}]
|
|
166
240
|
},
|
|
167
241
|
"text-to-video" => {
|
|
168
242
|
"models" => ["grok-imagine-text-to-video", "grok-imagine-video-1.5-fast", "grok-imagine-video-1.5-preview"],
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
module RunApi
|
|
4
4
|
module GrokImagine
|
|
5
5
|
module Resources
|
|
6
|
-
#
|
|
6
|
+
# Prompt-guided image editing resource.
|
|
7
|
+
#
|
|
8
|
+
# Image 2.0 accepts one to five source_image_urls, an aspect_ratio, and
|
|
9
|
+
# an optional prompt. The original model continues to accept a single
|
|
10
|
+
# source_image_url and prompt.
|
|
7
11
|
class EditImage
|
|
8
12
|
include RunApi::Core::ResourceHelpers
|
|
9
13
|
|
|
@@ -35,7 +39,6 @@ module RunApi
|
|
|
35
39
|
|
|
36
40
|
def validate_params!(params)
|
|
37
41
|
validate_contract!(CONTRACT["edit-image"], params)
|
|
38
|
-
raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RunApi
|
|
4
|
+
module GrokImagine
|
|
5
|
+
module Resources
|
|
6
|
+
# Produces an editable segmentation map from a public image URL.
|
|
7
|
+
# source_task_id remains accepted as a compatibility input; use image_url instead.
|
|
8
|
+
class SegmentMap
|
|
9
|
+
include RunApi::Core::ResourceHelpers
|
|
10
|
+
|
|
11
|
+
ENDPOINT = "/api/v1/grok_imagine/segment_map"
|
|
12
|
+
|
|
13
|
+
RESPONSE_CLASS = Types::SegmentMapTaskResponse
|
|
14
|
+
COMPLETED_RESPONSE_CLASS = Types::CompletedSegmentMapTaskResponse
|
|
15
|
+
|
|
16
|
+
def initialize(http)
|
|
17
|
+
@http = http
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def run(options: nil, **params)
|
|
21
|
+
task = create(options: options, **params)
|
|
22
|
+
poll_until_complete { get(task.id, options: options) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create(options: nil, **params)
|
|
26
|
+
params = compact_params(params)
|
|
27
|
+
validate_params!(params)
|
|
28
|
+
request(:post, ENDPOINT, body: params, options: options)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get(id, options: nil)
|
|
32
|
+
request(:get, "#{ENDPOINT}/#{id}", options: options)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def validate_params!(params)
|
|
38
|
+
validate_contract!(CONTRACT["segment-map"], params)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -37,6 +37,21 @@ module RunApi
|
|
|
37
37
|
class CompletedImageTaskResponse < ImageTaskResponse
|
|
38
38
|
required :images, [-> { MediaUrl }]
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
class Segment < RunApi::Core::BaseModel
|
|
42
|
+
required :url, String
|
|
43
|
+
optional :name, String
|
|
44
|
+
optional :index, Integer
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class SegmentMapTaskResponse < AsyncTaskResponse
|
|
48
|
+
optional :segments, [-> { Segment }]
|
|
49
|
+
optional :error, String
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class CompletedSegmentMapTaskResponse < SegmentMapTaskResponse
|
|
53
|
+
required :segments, [-> { Segment }]
|
|
54
|
+
end
|
|
40
55
|
end
|
|
41
56
|
end
|
|
42
57
|
end
|
data/lib/runapi/grok_imagine.rb
CHANGED
|
@@ -6,6 +6,7 @@ require_relative "grok_imagine/contract_gen"
|
|
|
6
6
|
require_relative "grok_imagine/resources/text_to_video"
|
|
7
7
|
require_relative "grok_imagine/resources/image_to_video"
|
|
8
8
|
require_relative "grok_imagine/resources/text_to_image"
|
|
9
|
+
require_relative "grok_imagine/resources/segment_map"
|
|
9
10
|
require_relative "grok_imagine/resources/edit_image"
|
|
10
11
|
require_relative "grok_imagine/resources/extensions"
|
|
11
12
|
require_relative "grok_imagine/resources/upscales"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: runapi-grok-imagine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- RunAPI
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.4.
|
|
18
|
+
version: 0.4.1
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.4.
|
|
25
|
+
version: 0.4.1
|
|
26
26
|
description: The Grok Imagine Ruby SDK is the language-specific package for Grok Imagine
|
|
27
27
|
on RunAPI. Use this package for image and video generation, image editing, and creative
|
|
28
28
|
production workflows when your application needs request bodies, task status lookup,
|
|
@@ -43,6 +43,7 @@ files:
|
|
|
43
43
|
- lib/runapi/grok_imagine/resources/edit_image.rb
|
|
44
44
|
- lib/runapi/grok_imagine/resources/extensions.rb
|
|
45
45
|
- lib/runapi/grok_imagine/resources/image_to_video.rb
|
|
46
|
+
- lib/runapi/grok_imagine/resources/segment_map.rb
|
|
46
47
|
- lib/runapi/grok_imagine/resources/text_to_image.rb
|
|
47
48
|
- lib/runapi/grok_imagine/resources/text_to_video.rb
|
|
48
49
|
- lib/runapi/grok_imagine/resources/upscales.rb
|
|
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
71
72
|
- !ruby/object:Gem::Version
|
|
72
73
|
version: '0'
|
|
73
74
|
requirements: []
|
|
74
|
-
rubygems_version: 4.0.
|
|
75
|
+
rubygems_version: 4.0.17
|
|
75
76
|
specification_version: 4
|
|
76
77
|
summary: Grok Imagine Ruby SDK for RunAPI
|
|
77
78
|
test_files: []
|