-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
42 lines (35 loc) · 1.77 KB
/
server.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
import sys
from tornado.ioloop import IOLoop
from tornado.web import Application
from yamlparams.utils import Hparam
from loguru import logger
from models.implicitALS.dataloader import Loader
from models.implicitALS.singleton import SharedModel
from http_utils import recs, updating, misc
def make_app():
base_recs_config = dict(SharedModel=SharedModel,
config=config)
urls = [('/topPopular', recs.TopPopularRecommendationHandler, dict(top_popular=top_popular, **base_recs_config)),
('/explorations', recs.ExplorationRecommendationsHandler, dict(explorations_categies=explorations_categies,
**base_recs_config)),
('/recommend', recs.RecommendHandler, dict(top_popular=top_popular, **base_recs_config)),
('/similarItems', recs.SimilarItemsHandler, base_recs_config),
('/personalSimilarItems', recs.PersonalSimilarItemsHandler, base_recs_config),
('/rateItem', updating.RateItemHandler, base_recs_config),
('/recalculate', updating.RecalculateHandler, dict(loader=loader, **base_recs_config)),
('/healthcheck', misc.HealthcheckHandler)]
return Application(urls)
if __name__ == "__main__":
if len(sys.argv) < 2:
raise AttributeError('Use config name to define model config')
cfg_path = sys.argv[1]
config = Hparam(cfg_path)
logger.add('logs/' + config.name + '-usage.log')
loader = Loader(config.path)
updating.recalculate_handler.prepare_model(loader, config)
explorations_categies = updating.load_explorations_model(config.explorations_path)
top_popular = loader.get_top_popular()
app = make_app()
print("READY")
app.listen(5000)
IOLoop.instance().start()