Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,16 +38,16 @@ with open('loras.json', 'r') as f:
|
|
| 38 |
|
| 39 |
# Initialize the base model
|
| 40 |
dtype = torch.bfloat16
|
|
|
|
| 41 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 42 |
|
| 43 |
# 공통 FLUX 모델 로드
|
| 44 |
base_model = "black-forest-labs/FLUX.1-dev"
|
| 45 |
-
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype)
|
| 46 |
-
pipe.to(device) # 여기서 한 번만 device로 이동
|
| 47 |
|
| 48 |
# LoRA를 위한 설정
|
| 49 |
-
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype)
|
| 50 |
-
good_vae = AutoencoderKL.from_pretrained(base_model, subfolder="vae", torch_dtype=dtype)
|
| 51 |
|
| 52 |
# Image-to-Image 파이프라인 설정
|
| 53 |
pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
|
|
@@ -59,32 +59,26 @@ pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
|
|
| 59 |
text_encoder_2=pipe.text_encoder_2,
|
| 60 |
tokenizer_2=pipe.tokenizer_2,
|
| 61 |
torch_dtype=dtype
|
| 62 |
-
)
|
| 63 |
|
|
|
|
| 64 |
controlnet = FluxControlNetModel.from_pretrained(
|
| 65 |
"jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
print("Available attributes in FLUX pipeline:", pipe.__dict__.keys())
|
| 69 |
|
| 70 |
-
# Upscale 파이프라인 설정 (
|
| 71 |
pipe_upscale = FluxControlNetPipeline(
|
| 72 |
vae=pipe.vae,
|
| 73 |
text_encoder=pipe.text_encoder,
|
| 74 |
-
text_encoder_2=pipe.text_encoder_2,
|
| 75 |
tokenizer=pipe.tokenizer,
|
| 76 |
-
tokenizer_2=pipe.tokenizer_2,
|
| 77 |
transformer=pipe.transformer,
|
| 78 |
scheduler=pipe.scheduler,
|
| 79 |
controlnet=controlnet
|
| 80 |
-
)
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
# 추가 속성 설정 (있는 경우에만)
|
| 83 |
-
if hasattr(pipe, 'image_processor'):
|
| 84 |
-
pipe_upscale.image_processor = pipe.image_processor
|
| 85 |
|
| 86 |
-
# 모든 파이프라인을 device로 이동
|
| 87 |
-
pipe_upscale.to(device)
|
| 88 |
|
| 89 |
|
| 90 |
MAX_SEED = 2**32 - 1
|
|
|
|
| 38 |
|
| 39 |
# Initialize the base model
|
| 40 |
dtype = torch.bfloat16
|
| 41 |
+
|
| 42 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 43 |
|
| 44 |
# 공통 FLUX 모델 로드
|
| 45 |
base_model = "black-forest-labs/FLUX.1-dev"
|
| 46 |
+
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype).to(device)
|
|
|
|
| 47 |
|
| 48 |
# LoRA를 위한 설정
|
| 49 |
+
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
| 50 |
+
good_vae = AutoencoderKL.from_pretrained(base_model, subfolder="vae", torch_dtype=dtype).to(device)
|
| 51 |
|
| 52 |
# Image-to-Image 파이프라인 설정
|
| 53 |
pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
|
|
|
|
| 59 |
text_encoder_2=pipe.text_encoder_2,
|
| 60 |
tokenizer_2=pipe.tokenizer_2,
|
| 61 |
torch_dtype=dtype
|
| 62 |
+
).to(device)
|
| 63 |
|
| 64 |
+
# Upscale을 위한 ControlNet 설정
|
| 65 |
controlnet = FluxControlNetModel.from_pretrained(
|
| 66 |
"jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
|
| 67 |
+
).to(device)
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
# Upscale 파이프라인 설정 (기존 pipe 재사용)
|
| 70 |
pipe_upscale = FluxControlNetPipeline(
|
| 71 |
vae=pipe.vae,
|
| 72 |
text_encoder=pipe.text_encoder,
|
|
|
|
| 73 |
tokenizer=pipe.tokenizer,
|
|
|
|
| 74 |
transformer=pipe.transformer,
|
| 75 |
scheduler=pipe.scheduler,
|
| 76 |
controlnet=controlnet
|
| 77 |
+
).to(device)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
|
|
|
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
MAX_SEED = 2**32 - 1
|