Views
No views yet
1
2import torch
3import cv2
4from PIL import Image
5import numpy as np
6from diffusers.utils import load_image
7from diffusers.pipelines.flux.pipeline_flux_controlnet import FluxControlNetPipeline
8from diffusers.models.controlnet_flux import FluxControlNetModel
9
10controlnet_model_path = './flux_controlnet_artistic_text'
11controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.bfloat16)
12pipe = FluxControlNetPipeline.from_pretrained('black-forest-labs/FLUX.1-dev',
13 controlnet=controlnet,
14 torch_dtype=torch.bfloat16).to("cuda")
15
16
17font_mask_pil = Image.open("pictures/A.png").convert("RGB")
18font_mask_npy = np.array(font_mask_pil)
19
20prompt = "Vibrant, multicolored lettering against a soft, pastel background, with the letters appearing to be made of delicate petals and blooming flowers, giving a sense of freshness and natural beauty. The texture should mimic the intricate layers and velvety surfaces of various blossoms, with subtle gradients and occasional dewdrops enhancing the lifelike appearance."
21image = pipe(prompt,
22 control_image=font_mask_pil,
23 controlnet_conditioning_scale=0.6,
24 num_inference_steps=30,
25 guidance_scale=3.5,
26 generator=torch.Generator("cuda").manual_seed(42)).images[0]
27rgba = Image.fromarray(np.concatenate([np.array(image), cv2.resize(font_mask_npy, (1024, 1024))[..., :1]], axis=-1))
28rgba.save("./{}.png".format(datetime.now().strftime("%Y%m%d%H%M%S")))