Spaces:
Paused
Paused
lllyasviel
commited on
Commit
·
bbedeb2
1
Parent(s):
1f71b3b
- modules/default_pipeline.py +31 -0
modules/default_pipeline.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
import modules.core as core
|
4 |
+
|
5 |
+
from modules.path import modelfile_path
|
6 |
+
|
7 |
+
|
8 |
+
xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
|
9 |
+
xl_refiner_filename = os.path.join(modelfile_path, 'sd_xl_refiner_1.0.safetensors')
|
10 |
+
|
11 |
+
xl_base = core.load_model(xl_base_filename)
|
12 |
+
|
13 |
+
|
14 |
+
@torch.no_grad()
|
15 |
+
def process(positive_prompt, negative_prompt, width=1024, height=1024, batch_size=1):
|
16 |
+
positive_conditions = core.encode_prompt_condition(clip=xl_base.clip, prompt=positive_prompt)
|
17 |
+
negative_conditions = core.encode_prompt_condition(clip=xl_base.clip, prompt=negative_prompt)
|
18 |
+
|
19 |
+
empty_latent = core.generate_empty_latent(width=width, height=height, batch_size=batch_size)
|
20 |
+
|
21 |
+
sampled_latent = core.ksample(
|
22 |
+
unet=xl_base.unet,
|
23 |
+
positive_condition=positive_conditions,
|
24 |
+
negative_condition=negative_conditions,
|
25 |
+
latent_image=empty_latent
|
26 |
+
)
|
27 |
+
|
28 |
+
decoded_latent = core.decode_vae(vae=xl_base.vae, latent_image=sampled_latent)
|
29 |
+
|
30 |
+
images = core.image_to_numpy(decoded_latent)
|
31 |
+
return images
|