-
Notifications
You must be signed in to change notification settings - Fork 7
/
txt2img-with-lora.py
56 lines (46 loc) · 1.6 KB
/
txt2img-with-lora.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
from novita_client import NovitaClient, Txt2ImgV3LoRA, Samplers, ProgressResponseStatusCode, ModelType, add_lora_to_prompt, save_image
from novita_client.utils import base64_to_image, input_image_to_pil
from PIL import Image
def make_image_grid(images, rows: int, cols: int, resize: int = None):
"""
Prepares a single grid of images. Useful for visualization purposes.
"""
assert len(images) == rows * cols
if resize is not None:
images = [img.resize((resize, resize)) for img in images]
w, h = images[0].size
grid = Image.new("RGB", size=(cols * w, rows * h))
for i, img in enumerate(images):
grid.paste(img, box=(i % cols * w, i // cols * h))
return grid
client = NovitaClient(os.getenv('NOVITA_API_KEY'), os.getenv('NOVITA_API_URI', None))
res1 = client.txt2img_v3(
prompt="a photo of handsome man, close up",
image_num=1,
guidance_scale=7.0,
sampler_name=Samplers.DPMPP_M_KARRAS,
model_name="dreamshaper_8_93211.safetensors",
height=512,
width=512,
seed=1024,
)
res2 = client.txt2img_v3(
prompt="a photo of handsome man, close up",
image_num=1,
guidance_scale=7.0,
sampler_name=Samplers.DPMPP_M_KARRAS,
model_name="dreamshaper_8_93211.safetensors",
height=512,
width=512,
seed=1024,
loras=[
Txt2ImgV3LoRA(
model_name="add_detail_44319",
strength=0.9,
)
]
)
make_image_grid([base64_to_image(res1.images_encoded[0]), base64_to_image(res2.images_encoded[0])], 1, 2, 512).save("./txt2img-lora-compare.png")