main.py
quoc14
python
9 months ago
1.5 kB
4
Indexable
FaceRC
from face_engine.engine import FaceEngine import numpy as np import gradio as gr face_engine = FaceEngine() def enroll_new_person(pil_image): check_exist = face_engine.get_id(pil_image) if check_exist == None: return f"Khuôn mặt đăng ký thành công với ID là {face_engine.save_to_db(pil_image)}" return f"Khuôn mặt đã tồn tại với ID là {check_exist}" enroll = gr.Interface(enroll_new_person, gr.Image(), "text") def verify(pil_image_1, pil_image_2): cosine_similarity = face_engine.compute_cosine_similarity(pil_image_1, pil_image_2) if cosine_similarity > face_engine.threshold: return f"Hai ảnh khuôn mặt của cùng một người, điểm tương đồng : {cosine_similarity}" return f"Hai ảnh khuôn mặt của hai người khác nhau, điểm tương đồng : {cosine_similarity}" verification = gr.Interface(verify, [gr.Image(),gr.Image()], "text") def identify(pil_image): check_exist = face_engine.get_id(pil_image) if check_exist == None: return "Khuôn mặt không tồn tại trong hệ thống" return f"Khuôn mặt được đăng ký với ID là {check_exist}" identification = gr.Interface(identify, gr.Image(), "text") demo = gr.TabbedInterface([enroll, verification, identification],["Enroll", "Verification", "Identification"]) if __name__ == "__main__": face_engine.reset_csv() # Comment this for deploying demo.launch()
Editor is loading...
Leave a Comment