You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.5 KiB
73 lines
2.5 KiB
from pathlib import Path
|
|
import warnings
|
|
|
|
# Suppress numpy deprecation warnings from InsightFace
|
|
warnings.filterwarnings("ignore", message=".*rcond parameter will change.*")
|
|
warnings.filterwarnings("ignore", category=FutureWarning, module="insightface")
|
|
import gradio as gr
|
|
import numpy as np
|
|
from typing import Optional, Tuple, List
|
|
import cv2
|
|
from datetime import datetime
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
from src.domain.entities import Face, VerificationResult, IdentificationResult
|
|
from src.domain.repositories import FaceRepository
|
|
from src.infrastructure.database.mongodb import MongoDBFaceRepository
|
|
from src.infrastructure.storage.chromadb import ChromaDBVectorStore
|
|
from src.infrastructure.storage.filesystem import FileSystemStorage
|
|
from src.application.use_cases import (
|
|
RegisterFaceUseCase,
|
|
VerifyFaceUseCase,
|
|
IdentifyFaceUseCase
|
|
)
|
|
from src.application.services import FaceRecognitionService
|
|
from src.infrastructure.ml.detectors import RetinaFaceDetector
|
|
from src.infrastructure.ml.recognizers import SFaceRecognizer
|
|
from src.presentation.gradio_app import create_gradio_interface
|
|
from src.infrastructure.config import Settings
|
|
|
|
settings = Settings()
|
|
|
|
def initialize_app():
|
|
"""Initialize the application synchronously"""
|
|
face_repository = MongoDBFaceRepository(settings.MONGODB_URL, settings.MONGODB_DB)
|
|
vector_store = ChromaDBVectorStore(settings.CHROMA_HOST, settings.CHROMA_PORT)
|
|
file_storage = FileSystemStorage(settings.UPLOAD_DIR)
|
|
|
|
detector = RetinaFaceDetector()
|
|
recognizer = SFaceRecognizer()
|
|
|
|
face_service = FaceRecognitionService(
|
|
face_repository=face_repository,
|
|
vector_store=vector_store,
|
|
verification_threshold=settings.VERIFICATION_THRESHOLD,
|
|
identification_threshold=settings.IDENTIFICATION_THRESHOLD
|
|
)
|
|
|
|
register_use_case = RegisterFaceUseCase(face_service)
|
|
verify_use_case = VerifyFaceUseCase(face_service)
|
|
identify_use_case = IdentifyFaceUseCase(face_service)
|
|
|
|
return create_gradio_interface(
|
|
register_use_case=register_use_case,
|
|
verify_use_case=verify_use_case,
|
|
identify_use_case=identify_use_case
|
|
)
|
|
|
|
def main():
|
|
"""Main function to start the application"""
|
|
app = initialize_app()
|
|
app.launch(
|
|
server_name="0.0.0.0",
|
|
server_port=8080,
|
|
share=False,
|
|
debug=True,
|
|
show_error=True,
|
|
quiet=False,
|
|
prevent_thread_lock=False,
|
|
max_threads=40
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
main() |