File size: 1,566 Bytes
f61f146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# config.py
import os
from dotenv import load_dotenv

load_dotenv()

class Config:
    # Model settings
    MODEL_NAME = os.getenv("MODEL_NAME", "buffalo_l")
    # Detection resolution. Lower = faster on CPU, higher = better for small/
    # distant faces. 320x320 is a strong default for close-up webcam/kiosk
    # shots (2-4x faster than 640x640 with negligible accuracy loss at close
    # range). Bump back to 640 via .env (DETECTION_SIZE=640) if you need to
    # recognize faces that are far from the camera.
    _det_size = int(os.getenv("DETECTION_SIZE", "320"))
    DETECTION_SIZE = (_det_size, _det_size)
    # -1 = CPU, 0 = first GPU (requires onnxruntime-gpu instead of onnxruntime)
    CTX_ID = int(os.getenv("CTX_ID", "-1"))
    
    # Recognition settings
    CONFIDENCE_THRESHOLD = float(os.getenv("CONFIDENCE_THRESHOLD", "0.85"))
    
    # Server
    # Hugging Face Spaces requires binding 0.0.0.0:7860 - these defaults work
    # for both Spaces and local runs (override via .env for local testing).
    HOST = os.getenv("HOST", "0.0.0.0")
    PORT = int(os.getenv("PORT", 7860))
    
    # API Key for security between PHP and Python
    API_KEY = os.getenv("API_KEY")
    
    # File paths
    UPLOAD_DIR = os.path.join(os.path.dirname(__file__), "uploads", "temp")

os.makedirs(Config.UPLOAD_DIR, exist_ok=True)

if not Config.API_KEY:
    raise RuntimeError(
        "API_KEY is not set. Create a .env file (see .env.example) with a "
        "strong, random API_KEY before starting the service."
    )