-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapps.py
38 lines (30 loc) · 1.03 KB
/
apps.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
from flask import Flask, render_template
from flask import request
from flask import redirect, url_for
from flask import session
from flask import jsonify
from relation_extraction.process_data import RE_DataEncoder
import relation_extraction.predict as re_model
app = Flask(__name__)
app.secret_key = b"abc5b2db26e723e327dd0b30c377fb6ec709973aa3184b750e4e3e32adc22f9e"
@app.route("/", methods=["GET"])
def index():
return render_template("home.html")
@app.route("/tokenize")
def tokenize():
sentence=request.args.get("sentence")
session["sentence"]=sentence
sentence_token = re_model.sentence_token(sentence)
return jsonify(
{"sentence_token": sentence_token}
)
@app.route("/predict")
def predict():
e1pos = request.args.getlist("e1pos[]")
e2pos = request.args.getlist("e2pos[]")
result = re_model.predict(session["sentence"], e1pos, e2pos)
return jsonify(
{"e1": result[0], "type": result[1], "e2": result[2], "acc": result[3]}
)
if __name__ == "__main__":
app.run(debug=True)