multimodalart HF staff commited on
Commit
c24886c
1 Parent(s): 3a60690

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -207,16 +207,16 @@ def merge_incompatible_lora(full_path_lora, lora_scale):
207
 
208
  def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_strength, image_strength, guidance_scale, depth_control_scale, sdxl_loras, progress=gr.Progress(track_tqdm=True)):
209
  global last_lora, last_merged, last_fused, pipe
210
- #print("Images:", images)
211
- #print("Face image", images[0])
212
- #face_image = images[0]
213
  face_image = center_crop_image_as_square(face_image)
214
- #print("Cropped image:", face_image)
215
- face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
216
- 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
217
- face_emb = face_info['embedding']
218
- face_kps = draw_kps(face_image, face_info['kps'])
219
-
 
 
220
  for lora_list in lora_defaults:
221
  if lora_list["model"] == sdxl_loras[selected_state.index]["repo"]:
222
  prompt_full = lora_list.get("prompt", None)
@@ -224,7 +224,9 @@ def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_stre
224
  prompt = prompt_full.replace("<subject>", prompt)
225
 
226
 
227
- print("Prompt:", prompt)
 
 
228
  #prepare face zoe
229
  with torch.no_grad():
230
  image_zoe = zoe(face_image)
@@ -347,7 +349,7 @@ with gr.Blocks(css="custom.css") as demo:
347
  )
348
  with gr.Column(scale=3):
349
  with gr.Row():
350
- prompt = gr.Textbox(label="Prompt", show_label=False, lines=1, max_lines=1, placeholder="A person", elem_id="prompt")
351
  button = gr.Button("Run", elem_id="run_button")
352
  with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
353
  community_icon = gr.HTML(community_icon_html)
 
207
 
208
  def run_lora(face_image, prompt, negative, lora_scale, selected_state, face_strength, image_strength, guidance_scale, depth_control_scale, sdxl_loras, progress=gr.Progress(track_tqdm=True)):
209
  global last_lora, last_merged, last_fused, pipe
210
+
 
 
211
  face_image = center_crop_image_as_square(face_image)
212
+ try:
213
+ face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
214
+ 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
215
+ face_emb = face_info['embedding']
216
+ face_kps = draw_kps(face_image, face_info['kps'])
217
+ except:
218
+ raise gr.Error("No face found in your image. Only face images work here. Try again")
219
+
220
  for lora_list in lora_defaults:
221
  if lora_list["model"] == sdxl_loras[selected_state.index]["repo"]:
222
  prompt_full = lora_list.get("prompt", None)
 
224
  prompt = prompt_full.replace("<subject>", prompt)
225
 
226
 
227
+ print("Prompt:", prompt)
228
+ if(prompt == ""):
229
+ prompt = "A person"
230
  #prepare face zoe
231
  with torch.no_grad():
232
  image_zoe = zoe(face_image)
 
349
  )
350
  with gr.Column(scale=3):
351
  with gr.Row():
352
+ prompt = gr.Textbox(label="Prompt", show_label=False, lines=1, max_lines=1, info="Describe your subject (optional)", value="A person", elem_id="prompt")
353
  button = gr.Button("Run", elem_id="run_button")
354
  with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
355
  community_icon = gr.HTML(community_icon_html)