32 lines
1.2 KiB
Python
Executable File
32 lines
1.2 KiB
Python
Executable File
from refacer import Refacer
|
|
from utils.minio_client import oss_get_image, minio_client
|
|
|
|
|
|
class ReFaceServer:
|
|
def __init__(self):
|
|
self.force_cpu = False
|
|
self.threshold = 0.2
|
|
self.colab_performance = False
|
|
self.refacer = Refacer(force_cpu=self.force_cpu, colab_performance=self.colab_performance)
|
|
|
|
def run(self, input_list, dest_face, facetoreplace):
|
|
dest_img = oss_get_image(oss_client=minio_client, path=dest_face, data_type="cv2")
|
|
if dest_img is None:
|
|
raise ValueError(f"Destination face image not found: {dest_face}")
|
|
|
|
origin_img = None
|
|
if facetoreplace:
|
|
origin_img = oss_get_image(oss_client=minio_client, path=facetoreplace, data_type="cv2")
|
|
if origin_img is None:
|
|
raise ValueError(f"Face to replace image not found: {facetoreplace}")
|
|
|
|
disable_similarity = origin_img is None
|
|
|
|
faces_config = [{
|
|
'origin': origin_img,
|
|
'destination': dest_img,
|
|
'threshold': self.threshold
|
|
}]
|
|
self.refacer.prepare_faces(faces_config, disable_similarity=disable_similarity)
|
|
print(f"Processing images from: {input_dir}")
|