加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化