-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.py
32 lines (24 loc) · 969 Bytes
/
api.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
import ast
import json
from flask import Flask, Response, jsonify, request
import search
app = Flask(__name__)
# app.config['JSON_AS_ASCII'] = False
@app.route("/query", methods=["POST"])
def query():
data = ast.literal_eval(request.data.decode("utf-8"))
question = data["question"]
# question = request.form["question"]
answer = search.ask(question)
answer = search.add_link(answer)
data = {"answer": answer}
json_string = json.dumps(data, ensure_ascii=False)
# print(json_string)
# creating a Response object to set the content type and the encoding
response = Response(json_string, content_type="application/json; charset=utf-8")
response.headers.add("Access-Control-Allow-Origin", "*")
print(response, response.data)
return response
if __name__ == "__main__":
# app.run(host="0.0.0.0", port = 8080, debug = True, ssl_context=('cert.pem', 'key.pem'))
app.run(host="0.0.0.0", port=8080, debug=True)