primerz commited on
Commit
f13fc6a
Β·
verified Β·
1 Parent(s): dcf2365

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -18
app.py CHANGED
@@ -291,21 +291,29 @@ def generate_image(prompt, negative, face_emb, face_image, face_kps, image_stren
291
  print('Prompt processing took: ', elapsed_time, 'seconds')
292
  print("Processing image...")
293
  st = time.time()
294
- image = pipe(
295
- prompt_embeds=conditioning,
296
- pooled_prompt_embeds=pooled,
297
- negative_prompt_embeds=negative_conditioning,
298
- negative_pooled_prompt_embeds=negative_pooled,
299
- width=1024,
300
- height=1024,
301
- image_embeds=face_emb,
302
- image=face_image,
303
- strength=1-image_strength,
304
- control_image=images,
305
- num_inference_steps=36,
306
- guidance_scale = guidance_scale,
307
- controlnet_conditioning_scale=[face_strength, depth_control_scale],
308
- ).images[0]
 
 
 
 
 
 
 
 
309
  et = time.time()
310
  elapsed_time = et - st
311
  print('Image processing took: ', elapsed_time, 'seconds')
@@ -320,11 +328,17 @@ def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_stre
320
  # face_image = center_crop_image_as_square(face_image)
321
  try:
322
  face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
323
- 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
 
 
 
 
324
  face_emb = face_info['embedding']
325
  face_kps = draw_kps(face_image, face_info['kps'])
326
- except:
327
- raise gr.Error("No face found in your image. Only face images work here. Try again")
 
 
328
  et = time.time()
329
  elapsed_time = et - st
330
  print('Cropping and calculating face embeds took: ', elapsed_time, 'seconds')
 
291
  print('Prompt processing took: ', elapsed_time, 'seconds')
292
  print("Processing image...")
293
  st = time.time()
294
+
295
+ inputs = {
296
+ "prompt_embeds": conditioning,
297
+ "pooled_prompt_embeds": pooled,
298
+ "negative_prompt_embeds": negative_conditioning,
299
+ "negative_pooled_prompt_embeds": negative_pooled,
300
+ "width": 1024,
301
+ "height": 1024,
302
+ "image": face_image,
303
+ "strength": 1 - image_strength,
304
+ "guidance_scale": guidance_scale,
305
+ }
306
+
307
+ if face_emb is not None:
308
+ inputs["image_embeds"] = face_emb
309
+ inputs["control_image"] = [face_kps, image_zoe.resize((height, width))]
310
+ inputs["controlnet_conditioning_scale"] = [face_strength, depth_control_scale]
311
+ else:
312
+ inputs["control_image"] = [image_zoe.resize((height, width))]
313
+ inputs["controlnet_conditioning_scale"] = [depth_control_scale]
314
+
315
+ image = pipe(**inputs).images[0]
316
+
317
  et = time.time()
318
  elapsed_time = et - st
319
  print('Image processing took: ', elapsed_time, 'seconds')
 
328
  # face_image = center_crop_image_as_square(face_image)
329
  try:
330
  face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
331
+ face_info = sorted(face_info, key=lambda x:(x['bbox'][2]-x['bbox'][0])*x['bbox'][3]-x['bbox'][1])[-1] if face_info else None
332
+ except:
333
+ face_info = None
334
+
335
+ if face_info:
336
  face_emb = face_info['embedding']
337
  face_kps = draw_kps(face_image, face_info['kps'])
338
+ else:
339
+ face_emb = None
340
+ face_kps = Image.new("RGB", face_image.size, (0, 0, 0)) # empty placeholder for consistency
341
+
342
  et = time.time()
343
  elapsed_time = et - st
344
  print('Cropping and calculating face embeds took: ', elapsed_time, 'seconds')