diff --git a/CHANGELOG.md b/CHANGELOG.md index 73d2a83ea..53c6d5c61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - Add FreeU for *backend:diffusers* for *backend:original* use extension: - Add HyperTile: -- Fix override settings +- Implement Styles extra field This is a big one, with some major changes and new functionality... And probably the biggest release since introduction of **Diffusers** diff --git a/cli/gen-styles.py b/cli/gen-styles.py new file mode 100755 index 000000000..44a47611a --- /dev/null +++ b/cli/gen-styles.py @@ -0,0 +1,70 @@ +#!/bin/env python + +import io +import sys +import json +import base64 +import requests +from PIL import Image + + +url = 'http://127.0.0.1:7860' +size = 128 +quality = 35 +prompt = 'woman walking in a city' +options = { + "negative_prompt": "", + "steps": 20, + "batch_size": 1, + "n_iter": 1, + "seed": -1, + "sampler_name": "UniPC", + "cfg_scale": 6, + "width": 512, + "height": 512, + "save_images": False, + "send_images": True, +} +styles = [] + + +def pil_to_b64(img: Image): + img = img.convert('RGB') + img = img.resize((size, size)) + buffer = io.BytesIO() + img.save(buffer, format="JPEG", quality=quality) + b64encoded = base64.b64encode(buffer.getvalue()).decode("utf-8") + return f'data:image/jpeg;base64,{b64encoded}' + + +def post(endpoint: str, dct: dict = None): + req = requests.post(f'{url}{endpoint}', json = dct, timeout=300, verify=False) + if req.status_code != 200: + return { 'error': req.status_code, 'reason': req.reason, 'url': req.url } + else: + return req.json() + + +if __name__ == '__main__': + sys.argv.pop(0) + if len(sys.argv) < 2: + print('gen-styles.py ') + sys.exit(1) + with open(sys.argv[0], encoding='utf-8') as f: + lines = f.readlines() + for line in lines: + line = line.strip().replace('\n', '') + print(line) + options['prompt'] = f'{line} {prompt}' + data = post('/sdapi/v1/txt2img', options) + b64str = data['images'][0].split(',',1)[0] + image = Image.open(io.BytesIO(base64.b64decode(b64str))) + styles.append({ + 'name': line, + 'prompt': line + ' {prompt}', + 'negative': '', + 'extra': '', + 'preview': pil_to_b64(image) + }) + with open(sys.argv[1], 'w', encoding='utf-8') as outfile: + json.dump(styles, outfile, indent=2) diff --git a/javascript/style.css b/javascript/style.css index d57086de0..3576dfb26 100644 --- a/javascript/style.css +++ b/javascript/style.css @@ -242,7 +242,7 @@ table.settings-value-table td { padding: 0.4em; border: 1px solid #ccc; max-widt .extra-networks .search { flex: 1; } .extra-networks .description { flex: 3; } .extra-networks .tab-nav > button { margin-right: 0; height: 24px; padding: 2px 4px 2px 4px; } -.extra-networks .buttons { position: absolute; right: 0; margin: -4px; } +.extra-networks .buttons { position: absolute; right: 0; margin: -4px; background: var(--background-color); } .extra-networks .custom-button { width: 120px; width: 100%; background: none; justify-content: left; text-align: left; padding: 2px 8px 2px 16px; text-indent: -8px; box-shadow: none; line-break: auto; } .extra-networks .custom-button:hover { background: var(--button-primary-background-fill) } .extra-networks-tab { padding: 0 !important; }