hysts HF staff commited on
Commit
d3fe5c5
1 Parent(s): b106068
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -1,11 +1,8 @@
1
  import math
2
- import os
3
  import random
4
 
5
  import cv2
6
- import diffusers
7
  import gradio as gr
8
- import insightface
9
  import numpy as np
10
  import PIL
11
  import spaces
@@ -40,8 +37,8 @@ app = FaceAnalysis(name="antelopev2", root="./", providers=["CPUExecutionProvide
40
  app.prepare(ctx_id=0, det_size=(640, 640))
41
 
42
  # Path to InstantID models
43
- face_adapter = f"./checkpoints/ip-adapter.bin"
44
- controlnet_path = f"./checkpoints/ControlNetModel"
45
 
46
  # Load pipeline
47
  controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
@@ -221,7 +218,7 @@ def generate_image(
221
  progress=gr.Progress(track_tqdm=True),
222
  ):
223
  if face_image is None:
224
- raise gr.Error(f"Cannot find any input face image! Please upload the face image")
225
 
226
  if prompt is None:
227
  prompt = "a person"
@@ -238,7 +235,7 @@ def generate_image(
238
  face_info = app.get(face_image_cv2)
239
 
240
  if len(face_info) == 0:
241
- raise gr.Error(f"Cannot find any face in the image! Please upload another person image")
242
 
243
  face_info = sorted(
244
  face_info,
@@ -257,7 +254,7 @@ def generate_image(
257
  face_info = app.get(pose_image_cv2)
258
 
259
  if len(face_info) == 0:
260
- raise gr.Error(f"Cannot find any face in the reference image! Please upload another person image")
261
 
262
  face_info = face_info[-1]
263
  face_kps = draw_kps(pose_image, face_info["kps"])
@@ -484,6 +481,5 @@ with gr.Blocks(css=css) as demo:
484
 
485
  gr.Markdown(article)
486
 
487
-
488
  demo.queue(api_open=False)
489
  demo.launch()
 
1
  import math
 
2
  import random
3
 
4
  import cv2
 
5
  import gradio as gr
 
6
  import numpy as np
7
  import PIL
8
  import spaces
 
37
  app.prepare(ctx_id=0, det_size=(640, 640))
38
 
39
  # Path to InstantID models
40
+ face_adapter = "./checkpoints/ip-adapter.bin"
41
+ controlnet_path = "./checkpoints/ControlNetModel"
42
 
43
  # Load pipeline
44
  controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
 
218
  progress=gr.Progress(track_tqdm=True),
219
  ):
220
  if face_image is None:
221
+ raise gr.Error("Cannot find any input face image! Please upload the face image")
222
 
223
  if prompt is None:
224
  prompt = "a person"
 
235
  face_info = app.get(face_image_cv2)
236
 
237
  if len(face_info) == 0:
238
+ raise gr.Error("Cannot find any face in the image! Please upload another person image")
239
 
240
  face_info = sorted(
241
  face_info,
 
254
  face_info = app.get(pose_image_cv2)
255
 
256
  if len(face_info) == 0:
257
+ raise gr.Error("Cannot find any face in the reference image! Please upload another person image")
258
 
259
  face_info = face_info[-1]
260
  face_kps = draw_kps(pose_image, face_info["kps"])
 
481
 
482
  gr.Markdown(article)
483
 
 
484
  demo.queue(api_open=False)
485
  demo.launch()