Jacobmadwed commited on
Commit
64e6528
·
verified ·
1 Parent(s): 97df0ce

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +14 -6
handler.py CHANGED
@@ -27,6 +27,11 @@ dtype = torch.float16 if str(device).__contains__("cuda") else torch.float32
27
  STYLE_NAMES = list(styles.keys())
28
  DEFAULT_STYLE_NAME = "Spring Festival"
29
 
 
 
 
 
 
30
  class GenerateImageRequest(BaseModel):
31
  inputs: str
32
  negative_prompt: str
@@ -110,7 +115,8 @@ class EndpointHandler:
110
  )
111
 
112
  # load and disable LCM
113
- self.pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
 
114
  self.pipe.disable_lora()
115
 
116
  self.pipe.cuda()
@@ -178,11 +184,13 @@ class EndpointHandler:
178
  enhance_face_region = request.enhance_face_region
179
  enable_LCM = request.enable_LCM
180
 
181
- self.pipe.disable_lora() if not enable_LCM else self.pipe.enable_lora()
182
-
183
- scheduler_class_name = "EulerDiscreteScheduler"
184
-
185
- self.pipe.scheduler = diffusers.EulerDiscreteScheduler.from_config(self.pipe.scheduler.config)
 
 
186
 
187
  # apply the style template
188
  inputs, negative_prompt = apply_style(style_name, inputs, negative_prompt)
 
27
  STYLE_NAMES = list(styles.keys())
28
  DEFAULT_STYLE_NAME = "Spring Festival"
29
 
30
+ # Download LCM-LoRA model if not already downloaded
31
+ lcm_lora_path = "./checkpoints/pytorch_lora_weights.safetensors"
32
+ if not os.path.exists(lcm_lora_path):
33
+ hf_hub_download(repo_id="latent-consistency/lcm-lora-sdxl", filename="pytorch_lora_weights.safetensors", local_dir="./checkpoints")
34
+
35
  class GenerateImageRequest(BaseModel):
36
  inputs: str
37
  negative_prompt: str
 
115
  )
116
 
117
  # load and disable LCM
118
+ self.pipe.load_lora_weights(lcm_lora_path)
119
+ self.pipe.fuse_lora()
120
  self.pipe.disable_lora()
121
 
122
  self.pipe.cuda()
 
184
  enhance_face_region = request.enhance_face_region
185
  enable_LCM = request.enable_LCM
186
 
187
+ if enable_LCM:
188
+ self.pipe.enable_lora()
189
+ self.pipe.scheduler = diffusers.LCMScheduler.from_config(self.pipe.scheduler.config)
190
+ guidance_scale = min(max(guidance_scale, 0), 1)
191
+ else:
192
+ self.pipe.disable_lora()
193
+ self.pipe.scheduler = diffusers.EulerDiscreteScheduler.from_config(self.pipe.scheduler.config)
194
 
195
  # apply the style template
196
  inputs, negative_prompt = apply_style(style_name, inputs, negative_prompt)