userapi-ai 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +39 -3
- data/lib/userapi/http.rb +6 -4
- data/lib/userapi/tools.rb +13 -0
- data/lib/userapi/version.rb +1 -1
- data/lib/userapi-ai.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9f1e430a00b0c38594bfdcaf2e9a73fc0e1b84335880cbf41b4c37ed2f3962
|
4
|
+
data.tar.gz: 35674d40a7625af53ee130443d89b52b212e2f03540e26e1a8dd69b52e5cceba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f2e96c827d8e79235b72b43f431649558b99c42da4ad203cf31368e00d9505ccfe8da0ae9749454675ceda58149af6052c5b2af7861fb3639b7b3f147674168
|
7
|
+
data.tar.gz: abe25672348422d4d4fbb64868f3dfecf757fc504ab068303c1ab7f0f37ecda6c72e2fcaa19b8366b6be948188497b9dae58346b81db769efa0ad893058fd318
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,23 @@
|
|
1
|
-
#
|
1
|
+
# Userapi.ai Ruby
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/userapi-ai.svg)](https://badge.fury.io/rb/userapi-ai)
|
4
4
|
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/neonix20b/userapi-ai/blob/main/LICENSE.txt)
|
5
5
|
|
6
6
|
Userapi.ai is an awesome tool that brings great value to products.
|
7
7
|
This gem was created to facilitate Ruby and also Rails applications to use all services of Userapi.ai:
|
8
|
-
- Midjourney
|
8
|
+
- Midjourney API
|
9
|
+
- [Imagine](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
10
|
+
- [Describe](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
11
|
+
- [Upscale](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
12
|
+
- [Upsample](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
13
|
+
- [Variation](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
14
|
+
- [Inpaint](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
15
|
+
- [Blend](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
16
|
+
- [Reroll](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
17
|
+
- [Zoom](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
18
|
+
- [Pan](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
19
|
+
- [Info](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
20
|
+
- [Status](https://www.notion.so/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142?pvs=21)
|
9
21
|
|
10
22
|
## Installation
|
11
23
|
|
@@ -91,7 +103,31 @@ You can use it to generate images of people, animals, objects, and anything else
|
|
91
103
|
webhook_url: "https://example.com/upscale/webhook-url",
|
92
104
|
webhook_type: "result")
|
93
105
|
```
|
94
|
-
See more [here](https://butternut-saffron-e5e.notion.site/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142#9abe719bb58948039acb5f0a6aee8947)
|
106
|
+
See more [here](https://butternut-saffron-e5e.notion.site/Midjourney-userapi-ai-doc-en-119680339b0a47e2ba6ae467eca58142#9abe719bb58948039acb5f0a6aee8947).
|
107
|
+
|
108
|
+
#### Tools
|
109
|
+
|
110
|
+
You can split the quad-layout output from Midjourney into 4 separate images. Don't forget to add the `gem 'mini_magick'`.
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
response = client.status result
|
114
|
+
if response["status"] == "done"
|
115
|
+
local_paths = UserapiAi::Tool.crop result: response["result"]
|
116
|
+
# or UserapiAi::Tool.crop url: "https://example.com/img.png"
|
117
|
+
local_paths.each do |path|
|
118
|
+
f = File.open(path)
|
119
|
+
...
|
120
|
+
end
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
```bash
|
125
|
+
=> local_paths
|
126
|
+
["/var/folders/yb/bjdvl6mn3cx2l7nd08726k500000gn/T/mini_magick20240324-73984-31zmkb-0.png",
|
127
|
+
"/var/folders/yb/bjdvl6mn3cx2l7nd08726k500000gn/T/mini_magick20240324-73984-31zmkb-1.png",
|
128
|
+
"/var/folders/yb/bjdvl6mn3cx2l7nd08726k500000gn/T/mini_magick20240324-73984-31zmkb-2.png",
|
129
|
+
"/var/folders/yb/bjdvl6mn3cx2l7nd08726k500000gn/T/mini_magick20240324-73984-31zmkb-3.png"]
|
130
|
+
```
|
95
131
|
|
96
132
|
## Development
|
97
133
|
|
data/lib/userapi/http.rb
CHANGED
@@ -7,9 +7,6 @@ module UserapiAi
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def json_post(path:, parameters:)
|
10
|
-
puts uri(path: path)
|
11
|
-
puts headers
|
12
|
-
puts parameters.to_json
|
13
10
|
to_json(conn.post(uri(path: path)) do |req|
|
14
11
|
req.headers = headers
|
15
12
|
req.body = parameters.to_json
|
@@ -21,7 +18,12 @@ module UserapiAi
|
|
21
18
|
def to_json(string)
|
22
19
|
return unless string
|
23
20
|
|
24
|
-
JSON.parse(string)
|
21
|
+
json = JSON.parse(string)
|
22
|
+
if json["status"] == false and json.has_key?("error")
|
23
|
+
raise StandardError.new json["error"]
|
24
|
+
else
|
25
|
+
json
|
26
|
+
end
|
25
27
|
rescue JSON::ParserError
|
26
28
|
# Convert a multiline string of JSON objects to a JSON array.
|
27
29
|
JSON.parse(string.gsub("}\n{", "},{").prepend("[").concat("]"))
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module UserapiAi
|
2
|
+
class Tool
|
3
|
+
def self.crop url: nil, result: nil
|
4
|
+
url = result["url"] if url.nil?
|
5
|
+
image = MiniMagick::Image.open url
|
6
|
+
image.crop "50%x50%"
|
7
|
+
arr = image.path.split(".")
|
8
|
+
(0..3).map{ |i|
|
9
|
+
arr.dup.insert(-2, "-#{i}.").join("")
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/userapi/version.rb
CHANGED
data/lib/userapi-ai.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userapi-ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Smolev Denis
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/userapi/client.rb
|
58
58
|
- lib/userapi/compatibility.rb
|
59
59
|
- lib/userapi/http.rb
|
60
|
+
- lib/userapi/tools.rb
|
60
61
|
- lib/userapi/version.rb
|
61
62
|
- sig/userapi/ai.rbs
|
62
63
|
homepage: https://userapi.ai.
|
@@ -72,9 +73,9 @@ require_paths:
|
|
72
73
|
- lib
|
73
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
|
-
- -
|
76
|
+
- - '='
|
76
77
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
+
version: 3.0.0
|
78
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
81
|
- - ">="
|