This commit is contained in:
lvmin 2023-08-10 06:54:32 -07:00
parent 9ab9cd3d53
commit 3126e4086f
2 changed files with 31 additions and 0 deletions

BIN
a.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -0,0 +1,31 @@
import os
import torch
import modules.core as core
from modules.path import modelfile_path
xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
xl_refiner_filename = os.path.join(modelfile_path, 'sd_xl_refiner_1.0.safetensors')
xl_base = core.load_model(xl_base_filename)
@torch.no_grad()
def process(positive_prompt, negative_prompt, width=1024, height=1024, batch_size=1):
positive_conditions = core.encode_prompt_condition(clip=xl_base.clip, prompt=positive_prompt)
negative_conditions = core.encode_prompt_condition(clip=xl_base.clip, prompt=negative_prompt)
empty_latent = core.generate_empty_latent(width=width, height=height, batch_size=batch_size)
sampled_latent = core.ksample(
unet=xl_base.unet,
positive_condition=positive_conditions,
negative_condition=negative_conditions,
latent_image=empty_latent
)
decoded_latent = core.decode_vae(vae=xl_base.vae, latent_image=sampled_latent)
images = core.image_to_numpy(decoded_latent)
return images