Views
No views yet

pip install git+https://github.com/huggingface/diffusers[!CAUTION] 📝 Special Handling for Text RenderingFor both Text-to-Image and Image Editing tasks involving text generation, you must enclose the target text within single or double quotation marks (both English '...' / "..." and Chinese ‘...’ / “...” styles are supported).Reasoning: The model utilizes a specialized character-level encoding strategy specifically for quoted content. Failure to use explicit quotation marks prevents this mechanism from triggering, which will severely compromise the text rendering capability.
1import torch
2from PIL import Image
3from diffusers import LongCatImageEditPipeline
4
5if __name__ == '__main__':
6 device = torch.device('cuda')
7 pipe = LongCatImageEditPipeline.from_pretrained("meituan-longcat/LongCat-Image-Edit-Turbo", torch_dtype= torch.bfloat16 )
8 # pipe.to(device, torch.bfloat16) # Uncomment for high VRAM devices (Faster inference)
9 pipe.enable_model_cpu_offload() # Offload to CPU to save VRAM (Required ~18 GB); slower but prevents OOM
10 img = Image.open('assets/test.png').convert('RGB')
11 prompt = '将猫变成狗'
12 image = pipe(
13 img,
14 prompt,
15 negative_prompt='',
16 guidance_scale=1,
17 num_inference_steps=8,
18 num_images_per_prompt=1,
19 generator=torch.Generator("cpu").manual_seed(43)
20 ).images[0]
21 image.save('./edit_example.png')