mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
add preview
This commit is contained in:
@@ -74,6 +74,8 @@ async def interrogate(f):
|
||||
if 'caption' in res:
|
||||
for term in res.caption.split(', '):
|
||||
term = term.replace('(', '').replace(')', '').split(':')
|
||||
if len(term) < 2:
|
||||
continue
|
||||
keywords[term[0]] = term[1]
|
||||
keywords = dict(sorted(keywords.items(), key=lambda x:x[1], reverse=True))
|
||||
for word in keywords.items():
|
||||
|
||||
@@ -5,6 +5,7 @@ import json
|
||||
import base64
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
from inspect import getsourcefile
|
||||
|
||||
from util import Map, log
|
||||
from sdapi import getsync, postsync
|
||||
@@ -38,13 +39,13 @@ def encode(f):
|
||||
def create_preview(name: str, suffix: str):
|
||||
options = getsync('/sdapi/v1/options')
|
||||
cmdflags = getsync('/sdapi/v1/cmd-flags')
|
||||
print(cmdflags.embeddings_dir)
|
||||
img2img_options['prompt'] = template.format(name = name, suffix = suffix)
|
||||
log.info({ 'preview prompt': img2img_options['prompt'] })
|
||||
log.debug({ 'preview options': img2img_options })
|
||||
mask_path = os.path.join(os.path.dirname(getsourcefile(lambda:0)), mask)
|
||||
if len(img2img_options['init_images']) == 0:
|
||||
for i in range(img2img_options.batch_size):
|
||||
img2img_options['init_images'].append(encode(mask))
|
||||
img2img_options['init_images'].append(encode(mask_path))
|
||||
data = postsync('/sdapi/v1/img2img', img2img_options)
|
||||
if 'error' in data:
|
||||
log.error({ 'preview': data['error'], 'reason': data['reason'] })
|
||||
|
||||
Reference in New Issue
Block a user