-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarter.py
57 lines (37 loc) · 1.48 KB
/
starter.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
"""This file starts the microservice"""
from flask import Flask, json, jsonify, request
import data_process
import method
with open('./config.json') as config_file:
CONFIG = json.load(config_file)
app = Flask(__name__)
@app.route("/hitec/classify/concepts/lda/run", methods=["POST"])
def post_classification_result():
app.logger.debug('/hitec/classify/concepts/lda/run called')
content = json.loads(request.data.decode('utf-8'))
app.logger.info(content)
# save content
dataset = content["dataset"]["documents"]
# get parameter
params = content["params"]
# start pre-processing
dataset = data_process.preprocess(dataset, stemming=params["stemming"] == "true")
# start concept detection
topics, doc_topic, metrics = method.train_eval(dataset, int(params["n_topics"]), int(params["iterations"]),
int(params["chunksize"]), int(params["passes"]),
params["fix_random"] == "true")
# prepare results
res = dict()
res.update({"topics": topics})
res.update({"doc_topic": doc_topic})
res.update({"metrics": metrics})
# send results back
return jsonify(res)
@app.route("/hitec/classify/concepts/lda/status", methods=["GET"])
def get_status():
status = {
"status": "operational",
}
return jsonify(status)
if __name__ == "__main__":
app.run(debug=False, threaded=False, host=CONFIG['HOST'], port=CONFIG['PORT'])