Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -106,10 +106,9 @@ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str
|
|
106 |
negative = ""
|
107 |
return p.replace("{prompt}", positive), n + negative
|
108 |
|
109 |
-
unetX = UNet2DConditionModel.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='unet', low_cpu_mem_usage=False, token=True) #.to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
|
110 |
|
111 |
def load_and_prepare_model():
|
112 |
-
|
113 |
vaeX = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None, use_safetensors=False, low_cpu_mem_usage=False, torch_dtype=torch.float32, token=True) #.to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
|
114 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
115 |
'ford442/RealVisXL_V5.0_BF16',
|
@@ -122,7 +121,7 @@ def load_and_prepare_model():
|
|
122 |
text_encoder=None,
|
123 |
text_encoder_2=None,
|
124 |
vae=None,
|
125 |
-
|
126 |
)
|
127 |
|
128 |
'''
|
@@ -176,7 +175,7 @@ model = Phi3ForCausalLM.from_pretrained(checkpoint).to('cuda:0')
|
|
176 |
#model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map='cuda') #.to('cuda')
|
177 |
|
178 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
179 |
-
|
180 |
text_encoder_2=CLIPTextModelWithProjection.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='text_encoder_2',token=True) #.to(device=device, dtype=torch.bfloat16)
|
181 |
|
182 |
MAX_SEED = np.iinfo(np.int32).max
|
@@ -405,6 +404,9 @@ def generate_30(
|
|
405 |
print(caption)
|
406 |
print(caption_2)
|
407 |
print("-- generating further caption --")
|
|
|
|
|
|
|
408 |
del captioner2
|
409 |
del model5
|
410 |
del processor5
|
@@ -415,13 +417,17 @@ def generate_30(
|
|
415 |
expanded = expand_prompt(caption_2)
|
416 |
expanded_1 = expanded[0]
|
417 |
expanded_2 = expanded[1]
|
|
|
|
|
418 |
del model
|
419 |
del txt_tokenizer
|
420 |
gc.collect()
|
421 |
torch.cuda.clear_cache()
|
422 |
-
|
|
|
|
|
423 |
pipe.text_encoder_2=text_encoder_2.to(device=device, dtype=torch.bfloat16)
|
424 |
-
pipe.unet=unetX.to(device=device, dtype=torch.bfloat16)
|
425 |
|
426 |
print('-- generating image --')
|
427 |
sd_image = ip_model.generate(
|
@@ -485,7 +491,7 @@ def generate_60(
|
|
485 |
samples=1,
|
486 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
487 |
):
|
488 |
-
pipe.text_encoder=
|
489 |
pipe.text_encoder_2=text_encoder_2
|
490 |
seed = random.randint(0, MAX_SEED)
|
491 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
@@ -575,7 +581,7 @@ def generate_90(
|
|
575 |
samples=1,
|
576 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
577 |
):
|
578 |
-
pipe.text_encoder=
|
579 |
pipe.text_encoder_2=text_encoder_2
|
580 |
seed = random.randint(0, MAX_SEED)
|
581 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
|
|
106 |
negative = ""
|
107 |
return p.replace("{prompt}", positive), n + negative
|
108 |
|
|
|
109 |
|
110 |
def load_and_prepare_model():
|
111 |
+
unetX = UNet2DConditionModel.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='unet', low_cpu_mem_usage=False, token=True) #.to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
|
112 |
vaeX = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None, use_safetensors=False, low_cpu_mem_usage=False, torch_dtype=torch.float32, token=True) #.to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
|
113 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
114 |
'ford442/RealVisXL_V5.0_BF16',
|
|
|
121 |
text_encoder=None,
|
122 |
text_encoder_2=None,
|
123 |
vae=None,
|
124 |
+
unet=unetX,
|
125 |
)
|
126 |
|
127 |
'''
|
|
|
175 |
#model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map='cuda') #.to('cuda')
|
176 |
|
177 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
178 |
+
text_encoder_1=CLIPTextModel.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='text_encoder',token=True) #.to(device=device, dtype=torch.bfloat16)
|
179 |
text_encoder_2=CLIPTextModelWithProjection.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='text_encoder_2',token=True) #.to(device=device, dtype=torch.bfloat16)
|
180 |
|
181 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
404 |
print(caption)
|
405 |
print(caption_2)
|
406 |
print("-- generating further caption --")
|
407 |
+
global model5
|
408 |
+
global captioner2
|
409 |
+
global processor5
|
410 |
del captioner2
|
411 |
del model5
|
412 |
del processor5
|
|
|
417 |
expanded = expand_prompt(caption_2)
|
418 |
expanded_1 = expanded[0]
|
419 |
expanded_2 = expanded[1]
|
420 |
+
global model
|
421 |
+
global txt_tokenizer
|
422 |
del model
|
423 |
del txt_tokenizer
|
424 |
gc.collect()
|
425 |
torch.cuda.clear_cache()
|
426 |
+
global text_encoder_1
|
427 |
+
global text_encoder_2
|
428 |
+
pipe.text_encoder=text_encoder_1.to(device=device, dtype=torch.bfloat16)
|
429 |
pipe.text_encoder_2=text_encoder_2.to(device=device, dtype=torch.bfloat16)
|
430 |
+
#pipe.unet=unetX.to(device=device, dtype=torch.bfloat16)
|
431 |
|
432 |
print('-- generating image --')
|
433 |
sd_image = ip_model.generate(
|
|
|
491 |
samples=1,
|
492 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
493 |
):
|
494 |
+
pipe.text_encoder=text_encoder_1
|
495 |
pipe.text_encoder_2=text_encoder_2
|
496 |
seed = random.randint(0, MAX_SEED)
|
497 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
|
|
581 |
samples=1,
|
582 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
583 |
):
|
584 |
+
pipe.text_encoder=text_encoder_1
|
585 |
pipe.text_encoder_2=text_encoder_2
|
586 |
seed = random.randint(0, MAX_SEED)
|
587 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|