-
Notifications
You must be signed in to change notification settings - Fork 0
/
untitled.py
43 lines (35 loc) · 1.31 KB
/
untitled.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
import json
from flask import Flask, Response, request
from BM25.TextCleaning import cleanStringAndLemmatize, wordslist2string, changeback
app = Flask(__name__)
def jsonVanilla(js,status):
resp = Response( js ,status = status, mimetype='application/json')
return resp
def errorResponseVanilla(description,status):
return Response(json.dumps({"error":description}) ,status = status)
@app.route('/')
#right now just doing one product, vmax
def match():
try:
print(request)
myjson = request.get_json(force=True)
print("this is ",myjson)
except Exception as inst:
print(type(inst),inst.args,inst,"get getTSEs get json Fail!")
return errorResponseVanilla("getTSEs "+str(type(inst)), status=500)
try:
print(myjson["problem_description"])
probdesc = wordslist2string(cleanStringAndLemmatize(myjson["problem_description"]))
predictions = temp.queryalgorithm(probdesc)
predictions = [changeback(prediction) for prediction in predictions]
except Exception as inst:
return errorResponseVanilla("getTSEs "+str(type(inst)), status=500)
data = {
"error":"",
"TSEs": predictions
}
print(data)
js = json.dumps(data)
return jsonVanilla(js,status=200)
if __name__ == '__main__':
app.run(debug = True)