forked from vladmandic/sdnext
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
444 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
|
||
# curl -vX POST http://localhost:7860/sdapi/v1/txt2img --header "Content-Type: application/json" -d @3261.json | ||
import os | ||
import json | ||
import logging | ||
import argparse | ||
import requests | ||
import urllib3 | ||
|
||
|
||
sd_url = os.environ.get('SDAPI_URL', "http://127.0.0.1:7860") | ||
sd_username = os.environ.get('SDAPI_USR', None) | ||
sd_password = os.environ.get('SDAPI_PWD', None) | ||
options = { | ||
"save_images": True, | ||
"send_images": True, | ||
} | ||
|
||
logging.basicConfig(level = logging.INFO, format = '%(asctime)s %(levelname)s: %(message)s') | ||
log = logging.getLogger(__name__) | ||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
|
||
|
||
def auth(): | ||
if sd_username is not None and sd_password is not None: | ||
return requests.auth.HTTPBasicAuth(sd_username, sd_password) | ||
return None | ||
|
||
|
||
def post(endpoint: str, payload: dict = None): | ||
if 'sdapi' not in endpoint: | ||
endpoint = f'sdapi/v1/{endpoint}' | ||
if 'http' not in endpoint: | ||
endpoint = f'{sd_url}/{endpoint}' | ||
req = requests.post(endpoint, json = payload, timeout=300, verify=False, auth=auth()) | ||
return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } if req.status_code != 200 else req.json() | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description = 'api-txt2img') | ||
parser.add_argument('endpoint', nargs=1, help='endpoint') | ||
parser.add_argument('json', nargs=1, help='json data or file') | ||
args = parser.parse_args() | ||
log.info(f'api-json: {args}') | ||
if os.path.isfile(args.json[0]): | ||
with open(args.json[0], 'r', encoding='ascii') as f: | ||
dct = json.load(f) # TODO fails with b64 encoded images inside json due to string encoding | ||
else: | ||
dct = json.loads(args.json[0]) | ||
res = post(endpoint=args.endpoint[0], payload=dct) | ||
print(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python | ||
import io | ||
import os | ||
import sys | ||
import base64 | ||
from PIL import Image | ||
from rich import print # pylint: disable=redefined-builtin | ||
|
||
|
||
def encode(file: str): | ||
image = Image.open(file) if os.path.exists(file) else None | ||
print(f'Input: file={file} image={image}') | ||
if image is None: | ||
return None | ||
if image.mode != 'RGB': | ||
image = image.convert('RGB') | ||
with io.BytesIO() as stream: | ||
image.save(stream, 'JPEG') | ||
image.close() | ||
values = stream.getvalue() | ||
encoded = base64.b64encode(values).decode() | ||
return encoded | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.argv.pop(0) | ||
fn = sys.argv[0] if len(sys.argv) > 0 else '' | ||
b64 = encode(fn) | ||
print('=== BEGIN ===') | ||
print(f'{b64}') | ||
print('=== END ===') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule sdnext-modernui
updated
25 files
+4 −0 | style.css | |
+2 −0 | themes/Aptro-AmberGlow.css | |
+4 −2 | themes/BrknSoul-Amstrad.css | |
+2 −0 | themes/Default.css | |
+4 −2 | themes/Eoan-Alpha.css | |
+2 −0 | themes/Eoan-Cyan.css | |
+2 −0 | themes/Eoan-Green.css | |
+2 −0 | themes/Eoan-Minimal.css | |
+2 −0 | themes/Eoan-Moonlight.css | |
+2 −0 | themes/Eoan-Orange.css | |
+2 −0 | themes/Eoan-OrangeMinimal.css | |
+2 −0 | themes/Eoan-OrangeMoonlight.css | |
+2 −0 | themes/Eoan-Quad.css | |
+2 −0 | themes/Eoan-Subdued.css | |
+2 −0 | themes/Eoan-Tron.css | |
+2 −0 | themes/Eoan-Yellow.css | |
+2 −0 | themes/IlluZn-Domination.css | |
+2 −0 | themes/IlluZn-LavenderZest.css | |
+2 −0 | themes/IlluZn-Superuser.css | |
+2 −0 | themes/IlluZn-VintageBeige.css | |
+2 −0 | themes/QS-Sunset.css | |
+3 −1 | themes/QS-Teal.css | |
+3 −1 | themes/QS-WhiteRabbit.css | |
+2 −0 | themes/Vlad-Default.css | |
+2 −0 | themes/Vlad-Flat.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.