-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
84 lines (65 loc) · 2.46 KB
/
config.py
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
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
class Config:
# Base directory
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# Data paths
DATA_DIR = os.path.join(BASE_DIR, 'Data')
KNOWLEDGE_BASE_PATH = os.path.join(DATA_DIR, 'knowledge_base.json')
DATA_SOURCES = [
os.path.join(DATA_DIR, 'data_source1.json'),
os.path.join(DATA_DIR, 'data_source2.json')
]
# Model paths
MODELS_DIR = os.path.join(BASE_DIR, 'Models')
LEMMATIZER_MODEL = os.path.join(MODELS_DIR, 'lemmatizer_model.pkl')
VECTORIZER_MODEL = os.path.join(MODELS_DIR, 'vectorizer_model.pkl')
NAIVE_BAYES_MODEL = os.path.join(MODELS_DIR, 'naive_bayes_model.pkl')
# Utils paths
UTILS_DIR = os.path.join(BASE_DIR, 'Utils')
STOP_WORDS_FILE = os.path.join(UTILS_DIR, 'stop_words.txt')
# Output paths
OUTPUT_DIR = os.path.join(BASE_DIR, 'Output')
PROGRESS_FILE = os.path.join(OUTPUT_DIR, 'progress.json')
TOPIC_MODEL_VISUALIZATION = os.path.join(OUTPUT_DIR, 'topic_model_visualization.png')
# Model parameters
NUM_TOPICS = 5
# NLP settings
MAX_SUMMARY_LENGTH = 200
MIN_SUMMARY_LENGTH = 50
# Processing settings
BATCH_SIZE = 100
MAX_WORKERS = 4
# API keys
API_KEY = os.getenv('SUM_API_KEY', '')
# Flask settings
SECRET_KEY = os.getenv('FLASK_SECRET_KEY', 'default_secret_key')
DEBUG = os.getenv('FLASK_DEBUG', 'True').lower() in ('true', '1', 't')
# Logging settings
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
@classmethod
def init_app(cls):
# Ensure directories exist
for directory in [cls.DATA_DIR, cls.MODELS_DIR, cls.UTILS_DIR, cls.OUTPUT_DIR]:
os.makedirs(directory, exist_ok=True)
# Validate critical paths
critical_paths = [cls.KNOWLEDGE_BASE_PATH, cls.STOP_WORDS_FILE, cls.LEMMATIZER_MODEL, cls.VECTORIZER_MODEL, cls.NAIVE_BAYES_MODEL]
for path in critical_paths:
if not os.path.exists(path):
raise FileNotFoundError(f"Critical file not found: {path}")
class DevelopmentConfig(Config):
DEBUG = True
class ProductionConfig(Config):
DEBUG = False
class TestingConfig(Config):
TESTING = True
config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig,
'default': DevelopmentConfig
}
# Set the active configuration
active_config = config[os.getenv('FLASK_ENV', 'default')]