automatic1111 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +77 -0
- data/README.md +12 -1
- data/lib/automatic1111/client.rb +19 -0
- data/lib/automatic1111/configurable.rb +30 -0
- data/lib/automatic1111/connection.rb +82 -0
- data/lib/automatic1111/version.rb +1 -1
- data/lib/automatic1111.rb +10 -1
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da6e8e072ce73cd690e52055b50c50d3f1f9f7d98c83739096274bff64dc9aca
|
4
|
+
data.tar.gz: 701b00689274d734d33a11bcf90ca98132df7d47610815a2edf0286e38e95685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eba6a96c47e0996021431a0fd01651a5e72e525a0bc8d3a20011ecf5ba0a5bdcc438c4cad45ba04b275b6d8d8f381e6fe8f2f2fa9997da2c11c82d8cb633796d
|
7
|
+
data.tar.gz: 2ada977842ff633c1e864c5050a8f43852885f827f5ae0a9b8f4e1b9607c40319822e0e9abca775505ca30db3b79994619e55464c2b1cb9330905119fdd7737c
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
automatic1111 (0.1.0)
|
5
|
+
addressable
|
6
|
+
faraday (>= 2.0)
|
7
|
+
faraday-multipart
|
8
|
+
faraday-retry
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
addressable (2.8.1)
|
14
|
+
public_suffix (>= 2.0.2, < 6.0)
|
15
|
+
ast (2.4.2)
|
16
|
+
byebug (11.1.3)
|
17
|
+
coderay (1.1.3)
|
18
|
+
crack (0.4.5)
|
19
|
+
rexml
|
20
|
+
faraday (2.7.4)
|
21
|
+
faraday-net_http (>= 2.0, < 3.1)
|
22
|
+
ruby2_keywords (>= 0.0.4)
|
23
|
+
faraday-multipart (1.0.4)
|
24
|
+
multipart-post (~> 2)
|
25
|
+
faraday-net_http (3.0.2)
|
26
|
+
faraday-retry (2.0.0)
|
27
|
+
faraday (~> 2.0)
|
28
|
+
hashdiff (1.0.1)
|
29
|
+
json (2.6.3)
|
30
|
+
method_source (1.0.0)
|
31
|
+
minitest (5.17.0)
|
32
|
+
multipart-post (2.3.0)
|
33
|
+
parallel (1.22.1)
|
34
|
+
parser (3.2.1.0)
|
35
|
+
ast (~> 2.4.1)
|
36
|
+
pry (0.14.2)
|
37
|
+
coderay (~> 1.1)
|
38
|
+
method_source (~> 1.0)
|
39
|
+
public_suffix (5.0.1)
|
40
|
+
rainbow (3.1.1)
|
41
|
+
rake (13.0.6)
|
42
|
+
regexp_parser (2.7.0)
|
43
|
+
rexml (3.2.5)
|
44
|
+
rubocop (1.46.0)
|
45
|
+
json (~> 2.3)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 3.2.0.0)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
|
+
rexml (>= 3.2.5, < 4.0)
|
51
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.26.0)
|
55
|
+
parser (>= 3.2.1.0)
|
56
|
+
ruby-progressbar (1.11.0)
|
57
|
+
ruby2_keywords (0.0.5)
|
58
|
+
unicode-display_width (2.4.2)
|
59
|
+
webmock (3.18.1)
|
60
|
+
addressable (>= 2.8.0)
|
61
|
+
crack (>= 0.3.2)
|
62
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
arm64-darwin-22
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
automatic1111!
|
69
|
+
byebug
|
70
|
+
minitest (~> 5.0)
|
71
|
+
pry
|
72
|
+
rake (~> 13.0)
|
73
|
+
rubocop (~> 1.21)
|
74
|
+
webmock
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
2.4.6
|
data/README.md
CHANGED
@@ -13,7 +13,18 @@ gem 'automatic1111'
|
|
13
13
|
|
14
14
|
## Usage
|
15
15
|
|
16
|
-
|
16
|
+
```ruby
|
17
|
+
# Setup client
|
18
|
+
client = Automatic1111::Client.new(api_endpoint_url: '<http://127.0.0.1:7860 or
|
19
|
+
https://xxxxxx.gradio.live')
|
20
|
+
|
21
|
+
# Authenticate
|
22
|
+
client.post('/login', params: { username: 'username', password: 'password' }, headers: { 'Content-Type' => 'application/x-www-form-urlencoded' })
|
23
|
+
|
24
|
+
# Call endpoint
|
25
|
+
resp = client.post('/sdapi/v1/txt2img', params: { prompt: 'test', sampler_name: 'DPM++ SDE Karras', steps: 20, enable_hr: true, hr_upscaler: 'Latent', denoising_strength: 0.7, width: 512, height: 768 })
|
26
|
+
resp['images']
|
27
|
+
```
|
17
28
|
|
18
29
|
## Development
|
19
30
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "automatic1111/configurable"
|
4
|
+
require "automatic1111/connection"
|
5
|
+
|
6
|
+
module Automatic1111
|
7
|
+
class Client
|
8
|
+
include Automatic1111::Configurable
|
9
|
+
include Automatic1111::Connection
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
# Use options passed in, but fall back to module defaults
|
13
|
+
Automatic1111::Configurable.keys.each do |key|
|
14
|
+
value = options.key?(key) ? options[key] : Automatic1111.instance_variable_get(:"@#{key}")
|
15
|
+
instance_variable_set(:"@#{key}", value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Automatic1111
|
4
|
+
module Configurable
|
5
|
+
attr_accessor :api_endpoint_url, :cookie, :read_timeout
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# List of configurable keys for {Datatrans::Client}
|
9
|
+
# @return [Array] of option keys
|
10
|
+
def keys
|
11
|
+
@keys ||= %i[api_endpoint_url cookie read_timeout]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Set configuration options using a block
|
16
|
+
def configure
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_timeout
|
21
|
+
@read_timeout ||= 60
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def options
|
27
|
+
Hash[Automatic1111::Configurable.keys.map { |key| [key, send(key)] }]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'byebug'
|
4
|
+
require "faraday"
|
5
|
+
require "faraday/net_http"
|
6
|
+
require "faraday/retry"
|
7
|
+
require "faraday/multipart"
|
8
|
+
require "addressable/uri"
|
9
|
+
|
10
|
+
module Automatic1111
|
11
|
+
# Network layer for API clients.
|
12
|
+
module Connection
|
13
|
+
def get(url, params: {}, headers: {})
|
14
|
+
request :get, url, params, headers: headers
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(url, params: {}, headers: {})
|
18
|
+
request :post, url, params, headers: headers
|
19
|
+
end
|
20
|
+
|
21
|
+
def put(url, params: {}, headers: {})
|
22
|
+
request :put, url, params, headers: headers
|
23
|
+
end
|
24
|
+
|
25
|
+
def patch(url, params: {}, headers: {})
|
26
|
+
request :patch, url, params, headers: headers
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(url, params: {}, headers: {})
|
30
|
+
request :delete, url, params, headers: headers
|
31
|
+
end
|
32
|
+
|
33
|
+
def head(url, params: {}, headers: {})
|
34
|
+
request :head, url, params, headers: headers
|
35
|
+
end
|
36
|
+
|
37
|
+
# Response for last HTTP request
|
38
|
+
#
|
39
|
+
# @return [Sawyer::Response]
|
40
|
+
def last_response
|
41
|
+
@last_response if defined? @last_response
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def request(method, path, data, headers: {})
|
47
|
+
headers['Content-Type'] ||= 'application/json'
|
48
|
+
headers['Cookie'] ||= cookie
|
49
|
+
|
50
|
+
connection = Faraday.new(url: api_endpoint_url) do |conn|
|
51
|
+
conn.request :retry
|
52
|
+
conn.adapter :net_http
|
53
|
+
conn.options.read_timeout = read_timeout
|
54
|
+
end
|
55
|
+
|
56
|
+
# @last_response = connection.send(method, Addressable::URI.parse(path.to_s).normalize.to_s, data)
|
57
|
+
@last_response = connection.send(method, Addressable::URI.parse(path.to_s).normalize.to_s) do |req|
|
58
|
+
req.headers = headers
|
59
|
+
case headers["Content-Type"]
|
60
|
+
when 'application/x-www-form-urlencoded'
|
61
|
+
req.body = URI.encode_www_form(data)
|
62
|
+
else
|
63
|
+
req.body = data.to_json
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
case @last_response.status
|
68
|
+
when 400
|
69
|
+
raise Error, "#{@last_response.status} #{@last_response.reason_phrase}: #{JSON.parse(@last_response.body)}"
|
70
|
+
else
|
71
|
+
self.cookie = @last_response.headers['set-cookie'] if @last_response.headers['set-cookie']
|
72
|
+
|
73
|
+
case headers["Content-Type"]
|
74
|
+
when 'application/json'
|
75
|
+
JSON.parse(@last_response.body)
|
76
|
+
else
|
77
|
+
@last_response.body
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/automatic1111.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "automatic1111/version"
|
4
|
+
require_relative "automatic1111/client"
|
4
5
|
|
5
6
|
module Automatic1111
|
6
7
|
class Error < StandardError; end
|
7
|
-
|
8
|
+
|
9
|
+
class << self
|
10
|
+
include Automatic1111::Configurable
|
11
|
+
|
12
|
+
def client
|
13
|
+
return @client if defined?(@client)
|
14
|
+
@client = Automatic1111::Client.new(options)
|
15
|
+
end
|
16
|
+
end
|
8
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: automatic1111
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dreaming Tulpa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday-multipart
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: addressable
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description:
|
84
112
|
email:
|
85
113
|
- hey@dreamingtulpa.com
|
@@ -90,9 +118,13 @@ files:
|
|
90
118
|
- ".rubocop.yml"
|
91
119
|
- CHANGELOG.md
|
92
120
|
- Gemfile
|
121
|
+
- Gemfile.lock
|
93
122
|
- README.md
|
94
123
|
- Rakefile
|
95
124
|
- lib/automatic1111.rb
|
125
|
+
- lib/automatic1111/client.rb
|
126
|
+
- lib/automatic1111/configurable.rb
|
127
|
+
- lib/automatic1111/connection.rb
|
96
128
|
- lib/automatic1111/version.rb
|
97
129
|
- sig/automatic1111.rbs
|
98
130
|
homepage: https://github.com/dreamingtulpa/automatic1111-ruby
|