-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
95 lines (86 loc) · 3.17 KB
/
config.py
File metadata and controls
95 lines (86 loc) · 3.17 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
from dotenv import load_dotenv
import os
load_dotenv()
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
# Static paths
ROOT_DIR: Path = Path(__file__).parent
MODELS_DIR: Path = ROOT_DIR / "models"
TEMP_DIR: Path = ROOT_DIR / "temp_files"
UPLOADS_DIR: Path = ROOT_DIR / "uploads"
STATIC_DIR: Path = ROOT_DIR / "static"
LOG_DIR: Path = ROOT_DIR / "logs"
# From .env with defaults
CALLBACK_URL: str = os.getenv("CALLBACK_URL", "http://localhost:3026/api/sense/face-match-webhook")
API_VERSION: str = os.getenv("API_VERSION", "1.0.0")
CALLBACK_TIMEOUT: int = os.getenv("CALLBACK_TIMEOUT", 30)
MAX_UPLOAD_SIZE: int = os.getenv("MAX_UPLOAD_SIZE", 10485760)
# BANKING-GRADE: Stricter thresholds for financial security
# DOCUMENT_THRESHOLDS: dict = {
# "passport": 0.30, # Banking grade - stricter
# "national_id": 0.30, # Banking grade - stricter
# "drivers_license": 0.35, # Banking grade - stricter
# "voter_id": 0.40, # Banking grade - stricter
# "pan_card": 0.40, # Banking grade - stricter
# "aadhaar": 0.35, # Banking grade - stricter
# "unknown": 0.4 # Banking grade - stricter
# }
DOCUMENT_THRESHOLDS: dict = {
"passport": {
"similarity": 0.80, # cosine similarity ≥ 0.80 → match
"distance": 0.20 # cosine distance ≤ 0.20 → match
},
"national_id": {
"similarity": 0.80,
"distance": 0.20
},
"drivers_license": {
"similarity": 0.75,
"distance": 0.25
},
"aadhaar": {
"similarity": 0.75,
"distance": 0.25
},
"pan_card": {
"similarity": 0.70,
"distance": 0.30
},
"voter_id": {
"similarity": 0.65,
"distance": 0.35
},
"unknown": {
"similarity": 0.65,
"distance": 0.35
}
}
# BANKING: Security limits
MAX_CONCURRENT_REQUESTS: int = 3 # Lower for banking security
MAX_QUEUE_SIZE: int = 10 # Lower for banking security
DOWNLOAD_TIMEOUT: int = 30 # Shorter timeout
MAX_IMAGE_SIZE: int = 5242880 # 5MB max for banking
ENHANCEMENT_PARAMS: dict = {
"passport": {
"brightness_boost": 1.3,
"contrast_boost": 1.4,
"denoise_strength": 5,
"sharpen_strength": 1.2,
"gamma": 1.2
},
"default": {
"brightness_boost": 1.3,
"contrast_boost": 1.3,
"denoise_strength": 5,
"sharpen_strength": 1.1,
"gamma": 1.2
}
}
# Initialize settings and create required directories
settings = Settings()
# SECURITY: Ensure all directories exist with proper permissions
for directory in [settings.MODELS_DIR, settings.TEMP_DIR, settings.UPLOADS_DIR,
settings.STATIC_DIR, settings.LOG_DIR]:
directory.mkdir(exist_ok=True, mode=0o755)