File size: 1,911 Bytes
f06aba5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch

from transformers import AutoProcessor
from longcat_image.models import LongCatImageTransformer2DModel
from longcat_image.pipelines import LongCatImagePipeline
from misc.prompt_rewrite_api import prompt_rewrite_deepseek

if __name__ == '__main__':

    device = torch.device('cuda')
    checkpoint_dir = './weights/LongCat-Image'

    text_processor = AutoProcessor.from_pretrained( checkpoint_dir, subfolder = 'tokenizer'  )
    transformer = LongCatImageTransformer2DModel.from_pretrained( checkpoint_dir , subfolder = 'transformer', 
        torch_dtype=torch.bfloat16, use_safetensors=True).to(device)
    
    pipe = LongCatImagePipeline.from_pretrained(
        checkpoint_dir,
        transformer=transformer,
        text_processor=text_processor
    )
    pipe.to(device, torch.bfloat16)

    prompt = 'ไธ€ไธชๅนด่ฝป็š„ไบš่ฃ”ๅฅณๆ€ง๏ผŒ่บซ็ฉฟ้ป„่‰ฒ้’ˆ็ป‡่กซ๏ผŒๆญ้…็™ฝ่‰ฒ้กน้“พใ€‚ๅฅน็š„ๅŒๆ‰‹ๆ”พๅœจ่†็›–ไธŠ๏ผŒ่กจๆƒ…ๆฌ้™ใ€‚่ƒŒๆ™ฏๆ˜ฏไธ€ๅ ต็ฒ—็ณ™็š„็ –ๅข™๏ผŒๅˆๅŽ็š„้˜ณๅ…‰ๆธฉๆš–ๅœฐๆด’ๅœจๅฅน่บซไธŠ๏ผŒ่ฅ้€ ๅ‡บไธ€็งๅฎ้™่€Œๆธฉ้ฆจ็š„ๆฐ›ๅ›ดใ€‚้•œๅคด้‡‡็”จไธญ่ท็ฆป่ง†่ง’๏ผŒ็ชๅ‡บๅฅน็š„็ฅžๆ€ๅ’Œๆœ้ฅฐ็š„็ป†่Š‚ใ€‚ๅ…‰็บฟๆŸ”ๅ’Œๅœฐๆ‰“ๅœจๅฅน็š„่„ธไธŠ๏ผŒๅผบ่ฐƒๅฅน็š„ไบ”ๅฎ˜ๅ’Œ้ฅฐๅ“็š„่ดจๆ„Ÿ๏ผŒๅขžๅŠ ็”ป้ข็š„ๅฑ‚ๆฌกๆ„ŸไธŽไบฒๅ’ŒๅŠ›ใ€‚ๆ•ดไธช็”ป้ขๆž„ๅ›พ็ฎ€ๆด๏ผŒ็ –ๅข™็š„็บน็†ไธŽ้˜ณๅ…‰็š„ๅ…‰ๅฝฑๆ•ˆๆžœ็›ธๅพ—็›Šๅฝฐ๏ผŒ็ชๆ˜พๅ‡บไบบ็‰ฉ็š„ไผ˜้›…ไธŽไปŽๅฎนใ€‚'
    
    enable_prompt_rewrite_api = False
    if enable_prompt_rewrite_api:
        prompt = prompt_rewrite_deepseek( prompt )

    image = pipe(
        prompt,
        negative_prompt='',
        height=768,
        width=1344,
        guidance_scale=4.5,
        num_inference_steps=50,
        num_images_per_prompt=1,
        generator= torch.Generator("cpu").manual_seed(43),
        enable_cfg_renorm=True,
        enable_prompt_rewrite=True if not enable_prompt_rewrite_api else False
    ).images[0]
    image.save('./t2i_example.png')