-
Notifications
You must be signed in to change notification settings - Fork 73
/
config.py
59 lines (45 loc) · 1.3 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
import logging
import os
class Config:
class AppEnvType:
DEV = 'dev'
PRODUCTION = 'production'
TEST = 'test'
APP_NAME = '12306-ocr'
APP_ENV = AppEnvType.PRODUCTION
LOADED = False
PROJECT_DIR = os.path.abspath(__file__ + '/../') + '/'
CONFIG_FILE = PROJECT_DIR + 'config.toml'
IMAGE_MODEL_FILE = PROJECT_DIR + 'ocr/image.model.h5'
TEXT_MODEL_FILE = PROJECT_DIR + 'ocr/text.model.h5'
TEXTS_FILE = PROJECT_DIR + 'ocr/texts.txt'
WEB = {
'host': '0.0.0.0',
'port': 8000
}
OCR = {
}
@classmethod
def load(cls):
"""
Load configs from toml file
:return:
"""
import toml
configs = toml.load(cls.CONFIG_FILE)
web = configs.get('web', {})
cls.WEB.update(web)
ocr = configs.get('ocr', {})
cls.OCR.update(ocr)
if not Config.LOADED:
Config.load()
# Logger
def set_up_logger():
logger = logging.getLogger(Config.APP_NAME)
logger.setLevel(logging.DEBUG if Config.APP_ENV == Config.AppEnvType.DEV else logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
Logger = set_up_logger()