Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -214,13 +214,13 @@ def generate_image(prompt, negative, face_emb, face_image, image_strength, image
|
|
| 214 |
pipe.unload_lora_weights()
|
| 215 |
et = time.time()
|
| 216 |
elapsed_time = et - st
|
| 217 |
-
print('Unfuse and unload took: ', elapsed_time, 'seconds')
|
| 218 |
st = time.time()
|
| 219 |
pipe.load_lora_weights(loaded_state_dict)
|
| 220 |
pipe.fuse_lora(lora_scale)
|
| 221 |
et = time.time()
|
| 222 |
elapsed_time = et - st
|
| 223 |
-
print('Fuse and load took: ', elapsed_time, 'seconds')
|
| 224 |
last_fused = True
|
| 225 |
is_pivotal = sdxl_loras[selected_state_index]["is_pivotal"]
|
| 226 |
if(is_pivotal):
|
|
@@ -265,6 +265,7 @@ def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_stre
|
|
| 265 |
global last_lora, last_merged, last_fused, pipe
|
| 266 |
selected_state_index = selected_state.index
|
| 267 |
face_image = center_crop_image_as_square(face_image)
|
|
|
|
| 268 |
try:
|
| 269 |
face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
|
| 270 |
face_info = sorted(face_info, key=lambda x:(x['bbox'][2]-x['bbox'][0])*x['bbox'][3]-x['bbox'][1])[-1] # only use the maximum face
|
|
@@ -272,7 +273,9 @@ def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_stre
|
|
| 272 |
face_kps = draw_kps(face_image, face_info['kps'])
|
| 273 |
except:
|
| 274 |
raise gr.Error("No face found in your image. Only face images work here. Try again")
|
| 275 |
-
|
|
|
|
|
|
|
| 276 |
for lora_list in lora_defaults:
|
| 277 |
if lora_list["model"] == sdxl_loras[selected_state_index]["repo"]:
|
| 278 |
prompt_full = lora_list.get("prompt", None)
|
|
@@ -284,13 +287,15 @@ def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_stre
|
|
| 284 |
if(prompt == ""):
|
| 285 |
prompt = "a person"
|
| 286 |
#prepare face zoe
|
|
|
|
| 287 |
with torch.no_grad():
|
| 288 |
image_zoe = zoe(face_image)
|
| 289 |
-
|
|
|
|
|
|
|
| 290 |
width, height = face_kps.size
|
| 291 |
images = [face_kps, image_zoe.resize((height, width))]
|
| 292 |
|
| 293 |
-
|
| 294 |
#if(selected_state.index < 0):
|
| 295 |
# if(selected_state.index == -9999):
|
| 296 |
# selected_state.index = 0
|
|
|
|
| 214 |
pipe.unload_lora_weights()
|
| 215 |
et = time.time()
|
| 216 |
elapsed_time = et - st
|
| 217 |
+
print('Unfuse and unload LoRA took: ', elapsed_time, 'seconds')
|
| 218 |
st = time.time()
|
| 219 |
pipe.load_lora_weights(loaded_state_dict)
|
| 220 |
pipe.fuse_lora(lora_scale)
|
| 221 |
et = time.time()
|
| 222 |
elapsed_time = et - st
|
| 223 |
+
print('Fuse and load LoRA took: ', elapsed_time, 'seconds')
|
| 224 |
last_fused = True
|
| 225 |
is_pivotal = sdxl_loras[selected_state_index]["is_pivotal"]
|
| 226 |
if(is_pivotal):
|
|
|
|
| 265 |
global last_lora, last_merged, last_fused, pipe
|
| 266 |
selected_state_index = selected_state.index
|
| 267 |
face_image = center_crop_image_as_square(face_image)
|
| 268 |
+
st = time.time()
|
| 269 |
try:
|
| 270 |
face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
|
| 271 |
face_info = sorted(face_info, key=lambda x:(x['bbox'][2]-x['bbox'][0])*x['bbox'][3]-x['bbox'][1])[-1] # only use the maximum face
|
|
|
|
| 273 |
face_kps = draw_kps(face_image, face_info['kps'])
|
| 274 |
except:
|
| 275 |
raise gr.Error("No face found in your image. Only face images work here. Try again")
|
| 276 |
+
et = time.time()
|
| 277 |
+
elapsed_time = et - st
|
| 278 |
+
print('Calculating face embeds took: ', elapsed_time, 'seconds')
|
| 279 |
for lora_list in lora_defaults:
|
| 280 |
if lora_list["model"] == sdxl_loras[selected_state_index]["repo"]:
|
| 281 |
prompt_full = lora_list.get("prompt", None)
|
|
|
|
| 287 |
if(prompt == ""):
|
| 288 |
prompt = "a person"
|
| 289 |
#prepare face zoe
|
| 290 |
+
st = time.time()
|
| 291 |
with torch.no_grad():
|
| 292 |
image_zoe = zoe(face_image)
|
| 293 |
+
et = time.time()
|
| 294 |
+
elapsed_time = et - st
|
| 295 |
+
print('Zoe Depth calculations took: ', elapsed_time, 'seconds')
|
| 296 |
width, height = face_kps.size
|
| 297 |
images = [face_kps, image_zoe.resize((height, width))]
|
| 298 |
|
|
|
|
| 299 |
#if(selected_state.index < 0):
|
| 300 |
# if(selected_state.index == -9999):
|
| 301 |
# selected_state.index = 0
|