-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
153 lines (108 loc) · 4.03 KB
/
app.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import os, sys, traceback
from flask import Flask
from flask.ext.cors import CORS
from flask.ext.restful import Api
from flask.ext.mail import Mail
from flask.ext.mongoengine import MongoEngine
from flask import render_template
import uuid
from boto.mturk.connection import MTurkConnection
from celery import Celery
import redis
app = Flask(__name__)
app.config.from_object(os.environ['APP_SETTINGS'])
api = Api(app)
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={"/taboo": {"origins": "*"},
"/train": {"origins": "*"}})
print "Loading mail extension"
sys.stdout.flush()
mail = Mail(app)
print "Loading redis and mongo"
#print "Flush the cache"
app.redis = redis.Redis.from_url(app.config['REDIS_URL'])
#app.redis.flushdb()
db = MongoEngine(app)
print "Loading Celery"
def make_celery(app):
#celery = Celery(app.import_name, backend=app.config['REDIS_URL'],
# broker=app.config['REDIS_URL'])
celery = Celery(app.import_name, broker=app.config['RABBITMQ_BIGWIG_URL'])
celery.conf.update(app.config)
TaskBase = celery.Task
class ContextTask(TaskBase):
abstract = True
def __call__(self, *args, **kwargs):
with app.app_context():
return TaskBase.__call__(self, *args, **kwargs)
celery.Task = ContextTask
return celery
celery = make_celery(app)
app.celery = celery
print "Loading logging"
sys.stdout.flush()
if not app.debug:
import logging
app.logger.addHandler(logging.StreamHandler())
app.logger.setLevel(logging.ERROR)
print "Finished loading server."
sys.stdout.flush()
@app.route('/')
def hello():
return render_template('index.html')
@app.route('/status/<job_id>')
def status(job_id):
return render_template(
'status.html',
job_id = job_id)
@app.route('/experiment_status/<experiment_id>')
def experiment_status(experiment_id):
return render_template(
'experiment_status.html',
experiment_id = experiment_id)
@app.route('/test/<task_id>/<task_category_id>')
def test(task_id, task_category_id):
return render_template(
'test.html',
task_id = task_id,
task_category_id = task_category_id)
from api.taboo_api import ComputeTabooApi
api.add_resource(ComputeTabooApi, '/taboo')
from api.train_api import GatherExtractorApi
api.add_resource(GatherExtractorApi, '/gather')
from api.train_api import RestartApi
api.add_resource(RestartApi, '/restart')
from api.train_api import PauseApi
api.add_resource(PauseApi, '/pause')
from api.train_api import JobStatusApi
api.add_resource(JobStatusApi, '/status')
from api.train_api import GatherStatusApi
api.add_resource(GatherStatusApi, '/gather_status')
from api.train_api import RetrainExtractorApi
api.add_resource(RetrainExtractorApi, '/retrain')
from api.train_api import RetrainStatusApi
api.add_resource(RetrainStatusApi, '/retrain_status')
from api.test_api import TestExtractorApi
api.add_resource(TestExtractorApi, '/test')
from api.test_api import CrossValidationExtractorApi
api.add_resource(CrossValidationExtractorApi, '/cv')
from api.util_api import MoveJobsFromRedisToMongoApi
api.add_resource(MoveJobsFromRedisToMongoApi, '/move')
from api.util_api import GetJobInfoApi
api.add_resource(GetJobInfoApi, '/get_job_info')
from api.util_api import TestGenerateUIApi
api.add_resource(TestGenerateUIApi, '/test_generate_ui')
from api.util_api import TestModifyUIApi
api.add_resource(TestModifyUIApi, '/test_modify_ui')
from api.util_api import TestLabelUIApi
api.add_resource(TestLabelUIApi, '/test_label_ui')
from api.util_api import ChangeBudgetApi
api.add_resource(ChangeBudgetApi, '/change_budget')
from api.util_api import CleanUpApi
api.add_resource(CleanUpApi, '/cleanup')
from api.experiment_api import ExperimentApi
api.add_resource(ExperimentApi, '/experiment')
from api.experiment_api import ExperimentStatusApi
api.add_resource(ExperimentStatusApi, '/get_experiment_status')
from api.experiment_api import ExperimentAnalyzeApi
api.add_resource(ExperimentAnalyzeApi, '/analyze_experiment')