Spaces:
Runtime error
Runtime error
lixiang46
commited on
Commit
β’
98c6239
1
Parent(s):
4cdc2c2
update
Browse files
app.py
CHANGED
@@ -44,10 +44,12 @@ pipe = StableDiffusionXLPipeline(
|
|
44 |
)
|
45 |
|
46 |
class FaceInfoGenerator():
|
|
|
47 |
def __init__(self, root_dir = "./.insightface/"):
|
48 |
self.app = FaceAnalysis(name = 'antelopev2', root = root_dir, providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
49 |
self.app.prepare(ctx_id = 0, det_size = (640, 640))
|
50 |
|
|
|
51 |
def get_faceinfo_one_img(self, face_image):
|
52 |
face_info = self.app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
|
53 |
|
@@ -57,6 +59,7 @@ class FaceInfoGenerator():
|
|
57 |
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
|
58 |
return face_info
|
59 |
|
|
|
60 |
def face_bbox_to_square(bbox):
|
61 |
## l, t, r, b to square l, t, r, b
|
62 |
l,t,r,b = bbox
|
@@ -74,6 +77,7 @@ def face_bbox_to_square(bbox):
|
|
74 |
|
75 |
MAX_SEED = np.iinfo(np.int32).max
|
76 |
MAX_IMAGE_SIZE = 1024
|
|
|
77 |
|
78 |
@spaces.GPU
|
79 |
def infer(prompt,
|
@@ -93,7 +97,6 @@ def infer(prompt,
|
|
93 |
scale = 0.8
|
94 |
pipe.set_face_fidelity_scale(scale)
|
95 |
|
96 |
-
face_info_generator = FaceInfoGenerator()
|
97 |
face_info = face_info_generator.get_faceinfo_one_img(image)
|
98 |
face_bbox_square = face_bbox_to_square(face_info["bbox"])
|
99 |
crop_image = image.crop(face_bbox_square)
|
|
|
44 |
)
|
45 |
|
46 |
class FaceInfoGenerator():
|
47 |
+
@spaces.GPU
|
48 |
def __init__(self, root_dir = "./.insightface/"):
|
49 |
self.app = FaceAnalysis(name = 'antelopev2', root = root_dir, providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
|
50 |
self.app.prepare(ctx_id = 0, det_size = (640, 640))
|
51 |
|
52 |
+
@spaces.GPU
|
53 |
def get_faceinfo_one_img(self, face_image):
|
54 |
face_info = self.app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
|
55 |
|
|
|
59 |
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
|
60 |
return face_info
|
61 |
|
62 |
+
@spaces.GPU
|
63 |
def face_bbox_to_square(bbox):
|
64 |
## l, t, r, b to square l, t, r, b
|
65 |
l,t,r,b = bbox
|
|
|
77 |
|
78 |
MAX_SEED = np.iinfo(np.int32).max
|
79 |
MAX_IMAGE_SIZE = 1024
|
80 |
+
face_info_generator = FaceInfoGenerator()
|
81 |
|
82 |
@spaces.GPU
|
83 |
def infer(prompt,
|
|
|
97 |
scale = 0.8
|
98 |
pipe.set_face_fidelity_scale(scale)
|
99 |
|
|
|
100 |
face_info = face_info_generator.get_faceinfo_one_img(image)
|
101 |
face_bbox_square = face_bbox_to_square(face_info["bbox"])
|
102 |
crop_image = image.crop(face_bbox_square)
|