-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
71 lines (53 loc) · 2.17 KB
/
settings.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
from dotenv import load_dotenv
from pathlib import Path
import os, logging, atexit
import tensorflow as tf
import globals
from globals import fix_file_path
from telegrammanager.telegrammanager import TelegramManager
from rasamodelhandler import RasaModelHandler
TG_STORAGE_PATH = fix_file_path("./storage/telegram/", True)
TG_CHATLOG_PATH = fix_file_path("./storage/chatlogs/", True)
TG_DOWNLOADS_PATH = fix_file_path("./storage/downloads/", True)
RASA_MODEL_PATH = fix_file_path("./rasa/models/basic_model/", False)
def init_api_keys():
env_path = Path('/home/marc/University/Chatbot') / '.env'
load_dotenv(dotenv_path=env_path, verbose=True)
#load_dotenv(".env", verbose=True)
global TELEGRAM_API_KEY, GOOGLE_DISTANCE_MATRIX_API_KEY
GOOGLE_DISTANCE_MATRIX_API_KEY = os.getenv("GOOGLE_DISTANCE_MATRIX_API_KEY")
TELEGRAM_API_KEY = os.getenv("TELEGRAM_API_KEY")
def init():
init_api_keys()
# surpress TensorFlow Warnings
tf.logging.set_verbosity(tf.logging.FATAL)
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("planner").setLevel(logging.INFO)
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("rasa").setLevel(logging.INFO)
atexit.register(exit_handler)
# if possible restore TelegramManager state
globals.debug("loading telegram manager...")
global tel_man
tel_man = TelegramManager( api_key=TELEGRAM_API_KEY )
try:
tel_man.restore(TG_STORAGE_PATH)
except Exception:
pass
globals.debug("loading done!")
# if possible restore RASA-Model
globals.debug("loading rasa model...")
global rasa_model
rasa_model = RasaModelHandler(RASA_MODEL_PATH)
globals.debug("loading done!")
def exit_handler():
globals.debug("exiting server...")
globals.debug("saving telegram chatlogs...")
tel_man.store_chatlog(TG_CHATLOG_PATH)
globals.debug("saving done!")
globals.debug("saving telegram manager...")
tel_man.store(TG_STORAGE_PATH)
globals.debug("saving done!")
globals.debug("exiting done!")