Views
No views yet


pip install git+https://github.com/huggingface/diffusers[!TIP] Leveraging a stronger LLM for prompt refinement can further enhance image generation quality. Please refer to inference_t2i.py for detailed usage instructions.
[!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 diffusers import LongCatImagePipeline
3
4if __name__ == '__main__':
5 device = torch.device('cuda')
6
7 pipe = LongCatImagePipeline.from_pretrained("meituan-longcat/LongCat-Image", 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 ~17 GB); slower but prevents OOM
10
11 prompt = '一个年轻的亚裔女性,身穿黄色针织衫,搭配白色项链。她的双手放在膝盖上,表情恬静。背景是一堵粗糙的砖墙,午后的阳光温暖地洒在她身上,营造出一种宁静而温馨的氛围。镜头采用中距离视角,突出她的神态和服饰的细节。光线柔和地打在她的脸上,强调她的五官和饰品的质感,增加画面的层次感与亲和力。整个画面构图简洁,砖墙的纹理与阳光的光影效果相得益彰,突显出人物的优雅与从容。'
12
13 image = pipe(
14 prompt,
15 height=768,
16 width=1344,
17 guidance_scale=4.0,
18 num_inference_steps=50,
19 num_images_per_prompt=1,
20 generator=torch.Generator("cpu").manual_seed(43),
21 enable_cfg_renorm=True,
22 enable_prompt_rewrite=True
23 ).images[0]
24
25 image.save('./t2i_example.png')