ktrndy commited on
Commit
c2f2b07
·
verified ·
1 Parent(s): fc5f0c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -24,8 +24,7 @@ def get_lora_sd_pipeline(
24
  base_model_name_or_path=model_id_default,
25
  dtype=torch_dtype,
26
  device=device,
27
- adapter_name="default",
28
- lora_scale=0.5
29
  ):
30
  unet_sub_dir = os.path.join(ckpt_dir, "unet")
31
  text_encoder_sub_dir = os.path.join(ckpt_dir, "text_encoder")
@@ -39,7 +38,6 @@ def get_lora_sd_pipeline(
39
  pipe = StableDiffusionPipeline.from_pretrained(base_model_name_or_path, torch_dtype=dtype).to(device)
40
  pipe.unet = PeftModel.from_pretrained(pipe.unet, unet_sub_dir, adapter_name=adapter_name)
41
  pipe.unet.set_adapter(adapter_name)
42
- pipe.fuse_lora(lora_scale=lora_scale)
43
 
44
  if os.path.exists(text_encoder_sub_dir):
45
  pipe.text_encoder = PeftModel.from_pretrained(
@@ -73,7 +71,9 @@ def encode_prompt(prompt, tokenizer, text_encoder):
73
  if len(part_of_text_inputs) < tokenizer.model_max_length:
74
  part_of_text_inputs = torch.cat([part_of_text_inputs, torch.tensor([tokenizer.pad_token_id] * (tokenizer.model_max_length - len(part_of_text_inputs)))])
75
  embeds.append(text_encoder(part_of_text_inputs.to(text_encoder.device).unsqueeze(0))[0])
76
- start += int((8/11)*tokenizer.model_max_length)
 
 
77
  prompt_embeds = torch.mean(torch.stack(embeds, dim=0), dim=0)
78
  return prompt_embeds
79
 
@@ -93,11 +93,11 @@ def infer(
93
  ):
94
  generator = torch.Generator(device).manual_seed(seed)
95
  pipe = get_lora_sd_pipeline(base_model_name_or_path=model_id,
96
- adapter_name="sticker_of_funny_cat_Pusheen",
97
- lora_scale=lora_scale)
98
  pipe = pipe.to(device)
99
  prompt_embeds = encode_prompt(prompt, pipe.tokenizer, pipe.text_encoder)
100
  negative_prompt_embeds = encode_prompt(negative_prompt, pipe.tokenizer, pipe.text_encoder)
 
101
 
102
  image = pipe(
103
  prompt_embeds=prompt_embeds,
 
24
  base_model_name_or_path=model_id_default,
25
  dtype=torch_dtype,
26
  device=device,
27
+ adapter_name="default"
 
28
  ):
29
  unet_sub_dir = os.path.join(ckpt_dir, "unet")
30
  text_encoder_sub_dir = os.path.join(ckpt_dir, "text_encoder")
 
38
  pipe = StableDiffusionPipeline.from_pretrained(base_model_name_or_path, torch_dtype=dtype).to(device)
39
  pipe.unet = PeftModel.from_pretrained(pipe.unet, unet_sub_dir, adapter_name=adapter_name)
40
  pipe.unet.set_adapter(adapter_name)
 
41
 
42
  if os.path.exists(text_encoder_sub_dir):
43
  pipe.text_encoder = PeftModel.from_pretrained(
 
71
  if len(part_of_text_inputs) < tokenizer.model_max_length:
72
  part_of_text_inputs = torch.cat([part_of_text_inputs, torch.tensor([tokenizer.pad_token_id] * (tokenizer.model_max_length - len(part_of_text_inputs)))])
73
  embeds.append(text_encoder(part_of_text_inputs.to(text_encoder.device).unsqueeze(0))[0])
74
+ start += int((8/
75
+
76
+ 11)*tokenizer.model_max_length)
77
  prompt_embeds = torch.mean(torch.stack(embeds, dim=0), dim=0)
78
  return prompt_embeds
79
 
 
93
  ):
94
  generator = torch.Generator(device).manual_seed(seed)
95
  pipe = get_lora_sd_pipeline(base_model_name_or_path=model_id,
96
+ adapter_name="sticker_of_funny_cat_Pusheen")
 
97
  pipe = pipe.to(device)
98
  prompt_embeds = encode_prompt(prompt, pipe.tokenizer, pipe.text_encoder)
99
  negative_prompt_embeds = encode_prompt(negative_prompt, pipe.tokenizer, pipe.text_encoder)
100
+ pipe.fuse_lora(lora_scale=lora_scale)
101
 
102
  image = pipe(
103
  prompt_embeds=prompt_embeds,