Spaces:
Runtime error
Runtime error
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')
|