Views
No views yet
1import torch
2from diffusers import AutoPipelineForText2Image
3
4# PEFT 라이브러리 필요 (LoRA 로딩용)
5from peft import PeftModel, PeftConfig
6
7# 기기 설정
8device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
10# 기본 모델 로드
11print("기본 FLUX 모델 로드 중...")
12pipe = AutoPipelineForText2Image.from_pretrained(
13 "black-forest-labs/FLUX.1-dev",
14 torch_dtype=torch.float16 # bfloat16 대신 float16 사용
15)
16pipe.to(device)
17
18# Uncensored LoRA 로드
19print("Uncensored LoRA 로드 중...")
20pipe.load_lora_weights(
21 'Heartsync/Flux-NSFW-uncensored',
22 weight_name='lora.safetensors',
23 adapter_name="uncensored"
24)
25
26# 이미지 생성
27prompt = "A woman in a sheer white dress standing on a beach at sunset, backlit so her silhouette is visible through the thin fabric, shot with Canon EOS R5, 85mm f/1.2 lens, golden hour natural lighting, professional composition, hyperrealistic detail, masterpiece quality, 8K resolution."
28negative_prompt = "text, watermark, signature, cartoon, anime, illustration, painting, drawing, low quality, blurry"
29
30# 시드 설정
31seed = 42
32generator = torch.Generator(device=device).manual_seed(seed)
33
34# 이미지 생성
35image = pipe(
36 prompt=prompt,
37 negative_prompt=negative_prompt,
38 guidance_scale=7.0,
39 num_inference_steps=28,
40 width=1024,
41 height=1024,
42 generator=generator,
43).images[0]
44
45# 이미지 저장
46image.save("generated_image.png")