-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
72 lines (57 loc) · 2.65 KB
/
Copy pathconfig.py
File metadata and controls
72 lines (57 loc) · 2.65 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
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
class Config:
"""Configuration class for Banknote Verifier"""
# Gemini API
GEMINI_API_KEY = os.getenv('GEMINI_API_KEY')
# Application Settings
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
MAX_IMAGE_SIZE = int(os.getenv('MAX_IMAGE_SIZE', '2048'))
# Security Thresholds
STRONG_MATCH_THRESHOLD = float(os.getenv('STRONG_MATCH_THRESHOLD', '0.85'))
WEAK_MATCH_THRESHOLD = float(os.getenv('WEAK_MATCH_THRESHOLD', '0.70'))
MIN_CONFIDENCE_REAL = float(os.getenv('MIN_CONFIDENCE_REAL', '0.80'))
# Feature Configuration
REQUIRED_FEATURES = [
'ashok_pillar', 'gandhi', 'security_thread',
'serial_num_left', 'serial_num_right'
]
OPTIONAL_FEATURES = [
'colorshift', 'devnagri', 'governor',
'latentnum', 'seethrough', 'strips'
]
# Serial Number Validation
ALLOWED_LETTERS = set('ABCDEFGHKLMNPQRSTUVW')
@classmethod
def validate_config(cls):
"""Validate that all required configuration is present"""
errors = []
if not cls.GEMINI_API_KEY:
errors.append("GEMINI_API_KEY is required. Please set it in .env file")
if cls.STRONG_MATCH_THRESHOLD <= cls.WEAK_MATCH_THRESHOLD:
errors.append("STRONG_MATCH_THRESHOLD must be greater than WEAK_MATCH_THRESHOLD")
if cls.MIN_CONFIDENCE_REAL < 0 or cls.MIN_CONFIDENCE_REAL > 1:
errors.append("MIN_CONFIDENCE_REAL must be between 0 and 1")
return errors
@classmethod
def get_serial_format(cls, denomination: int) -> dict:
"""Get serial number format for denomination"""
formats = {
10: {"pattern": r'^(\d{2})([A-Z])\s(\d{6})$', "description": "NNL NNNNNN"},
20: {"pattern": r'^(\d{2})([A-Z])\s(\d{6})$', "description": "NNL NNNNNN"},
50: {"pattern": r'^(\d)([A-Z]{2})\s(\d{5})$', "description": "NLL NNNNN"},
100: {"pattern": r'^(\d)([A-Z]{2})\s(\d{5})$', "description": "NLL NNNNN"},
200: {"pattern": r'^(\d)([A-Z]{2})\s(\d{5})$', "description": "NLL NNNNN"},
500: {"pattern": r'^(\d)([A-Z]{2})\s(\d{5})$', "description": "NLL NNNNN"}
}
return formats.get(denomination, {"pattern": "", "description": "Unknown"})
# Validate configuration on import
config_errors = Config.validate_config()
if config_errors:
print("❌ Configuration errors:")
for error in config_errors:
print(f" - {error}")
print("Please check your .env file and fix the issues.")