|
from io import BytesIO |
|
|
|
import requests |
|
import torch |
|
from PIL import Image |
|
|
|
from lyrasd_model import LyraSDImg2ImgPipeline |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib_path = "./lyrasd_model/lyrasd_lib/libth_lyrasd_cu12_sm86.so" |
|
model_path = "./models/lyrasd_rev_animated" |
|
|
|
|
|
model = LyraSDImg2ImgPipeline(model_path, lib_path) |
|
|
|
|
|
prompt = "a cat, cartoon style" |
|
negative_prompt = "NSFW" |
|
height, width = 512, 512 |
|
steps = 20 |
|
guidance_scale = 7.5 |
|
generator = torch.Generator().manual_seed(123) |
|
num_images = 1 |
|
|
|
|
|
init_image_url = "https://chuangxin-research-1258344705.cos.ap-guangzhou.myqcloud.com/share/files/seaside_town.png?q-sign-algorithm=sha1&q-ak=AKIDBF6i7GCtKWS8ZkgOtACzX3MQDl37xYty&q-sign-time=1692601590;1865401590&q-key-time=1692601590;1865401590&q-header-list=&q-url-param-list=&q-signature=ca04ca92d990d94813029c0d9ef29537e5f4637c" |
|
init_image = BytesIO(requests.get(init_image_url).content) |
|
init_image = Image.open(init_image).convert('RGB') |
|
init_image = init_image.resize((width, height), Image.Resampling.LANCZOS) |
|
|
|
strength = 0.8 |
|
|
|
|
|
images = model(prompt, init_image, strength, steps, |
|
guidance_scale, negative_prompt, num_images, |
|
generator=generator |
|
) |
|
|
|
|
|
for i, image in enumerate(images): |
|
image.save(f"./outputs/res_img2img_{i}.png") |
|
|