first commit

This commit is contained in:
zhh
2025-10-17 16:04:42 +08:00
parent ad4dccfe49
commit d8d558e185
11 changed files with 510 additions and 88 deletions

31
refacer_server.py Normal file
View File

@@ -0,0 +1,31 @@
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}")