/
Paff
/
declarant
Обзор
Документация
Войти
/
Paff
/
declarant
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
web/config.py
62 строки
3 KB
1pash1985-gif
feat: use Yandex Vision OCR as primary certificate scan fallback
09 авг 2026, 23:51
09 авг 2026, 23:51
7bf6a5c
Код
Авторство
О чём код?
"""Конфигурация веб-приложения.""" import os # Пароль для входа (можно менять через переменную окружения) ACCESS_PASSWORD = os.environ.get('DECLARANT_PASSWORD', 'declarant2026') # Секрет для сессий Flask SECRET_KEY = os.environ.get('SECRET_KEY', 'super-secret-key-change-me') # File storage: use Docker volume (/app/data) in production, local dir in dev. # REPORTS_DIR is set to /app/data/reports in Dockerfile; uploads go in /app/data/uploads. _reports_dir = os.environ.get('REPORTS_DIR', '') if _reports_dir: UPLOAD_FOLDER = os.path.join(os.path.dirname(_reports_dir), 'uploads') else: UPLOAD_FOLDER = os.path.join(os.path.dirname(__file__), 'uploads') # Максимальный размер загрузки (100 MB) MAX_CONTENT_LENGTH = 100 * 1024 * 1024 # DeepSeek API DEEPSEEK_API_KEY = os.environ.get('DEEPSEEK_API_KEY', 'sk-540f9e711cbb41e4b43241ab3d873ed5') DEEPSEEK_BASE_URL = 'https://api.deepseek.com' # Reasoning models (deepseek-v4-flash, deepseek-v4-pro) exhaust ALL max_tokens on # reasoning_tokens for complex invoices, producing empty content. deepseek-chat is # non-reasoning and produces reliable JSON output (~30s vs 100s+ for reasoning models). DEEPSEEK_MODEL = os.environ.get('DEEPSEEK_MODEL', 'deepseek-chat') # Kimi K3 API (Moonshot) KIMI_API_KEY = os.environ.get('KIMI_API_KEY', 'sk-poRN6uORsFmQthQ76TsSgk2VLJbZbu6f0HoVldmRubGfFuLk') KIMI_BASE_URL = 'https://api.moonshot.ai/v1' # Разрешённые расширения ALLOWED_EXTENSIONS = {'.pdf', '.xls', '.xlsx', '.xlsm', '.doc', '.zip', '.rar'} # --- AI Ensemble: DeepSeek + Kimi --- # Master switch. When False, the legacy single-model path is used. ENSEMBLE_ENABLED = os.environ.get('ENSEMBLE_ENABLED', 'true').lower() in ('1', 'true', 'yes') # Number of debate rounds when models disagree (0 = only parallel call + arbitration). # Benchmark results (2026-07-27): rounds=1 is optimal (60-120s vs 250s+ for rounds=2). ENSEMBLE_DEBATE_MAX_ROUNDS = int(os.environ.get('ENSEMBLE_DEBATE_MAX_ROUNDS', '1')) # Per-task toggles. Only used when ENSEMBLE_ENABLED is True. ENSEMBLE_ENABLE_PARSING = os.environ.get('ENSEMBLE_ENABLE_PARSING', 'true').lower() in ('1', 'true', 'yes') ENSEMBLE_ENABLE_EUROPA = os.environ.get('ENSEMBLE_ENABLE_EUROPA', 'true').lower() in ('1', 'true', 'yes') ENSEMBLE_ENABLE_IMPORT = os.environ.get('ENSEMBLE_ENABLE_IMPORT', 'true').lower() in ('1', 'true', 'yes') # Total timeout (seconds) for the full ensemble call including debates. # Benchmark results: 120s is sufficient for most files (avg 60-90s per file). ENSEMBLE_TIMEOUT_SECONDS = int(os.environ.get('ENSEMBLE_TIMEOUT_SECONDS', '120')) # AI ensemble as primary table-filling method (Таблица европа / Таблица импорт). # When True, DeepSeek + Kimi jointly decide cell mapping before regex fallback. ENSEMBLE_ENABLE_FILL = os.environ.get('ENSEMBLE_ENABLE_FILL', 'true').lower() in ('1', 'true', 'yes') # Timeout for table-filling ensemble (larger — more items than single-invoice parse). ENSEMBLE_FILL_TIMEOUT_SECONDS = int(os.environ.get('ENSEMBLE_FILL_TIMEOUT_SECONDS', '180')) # Yandex Vision OCR (for scanned certificate pages fallback) YANDEX_OCR_API_KEY = os.environ.get('YANDEX_OCR_API_KEY', '') YANDEX_OCR_FOLDER_ID = os.environ.get('YANDEX_OCR_FOLDER_ID', '')