-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
80 lines (59 loc) · 2.15 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
import json
import nltk
import requests
import spacy
from flask import Flask, redirect, render_template, request, url_for
from spacy import displacy
from coref import Display
from important_words.main import important_words
HTML_WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem">{}</div>"""
from flaskext.markdown import Markdown
app = Flask(__name__)
Markdown(app)
m = important_words()
d = Display()
tokenizer = nltk.data.load("tokenizers/punkt/english.pickle")
raw_text = "Fill me in!"
@app.route("/")
def index():
return redirect(url_for("extract"))
@app.route("/postmethod", methods=["GET", "POST"])
def get_post_javascript_data():
jsdata = request.form["javascript_data"]
print(jsdata)
return "<p>Hello, World!</p>"
@app.route("/extract", methods=["GET", "POST"])
def extract():
global raw_text
minimum_display_score = 80
html = """<div class="entities" style="line-height: 2.5; direction: ltr"> Fill me in! </div>"""
if request.method == "POST":
raw_text = request.form["rawtext"]
minimum_display_score = int(request.form["minimum_score"])
m.set_minimum_score_to_display(minimum_display_score / 100)
html = m.pred(raw_text)
html = html.replace("\n\n", "\n")
result = HTML_WRAPPER.format(html)
return render_template(
"result.html",
rawtext=raw_text,
result=result,
minimum_score=minimum_display_score,
)
@app.route("/coref", methods=["GET", "POST"])
def coref():
global raw_text
html = """<div class="entities" style="line-height: 2.5; direction: ltr"> Fill me in! </div>"""
if request.method == "POST":
raw_text = request.form["rawtext"]
sentences = tokenizer.tokenize(raw_text)
corefs = json.loads(
requests.post("http://localhost:9000/predict", json=sentences).text
)
d = Display()
html = d.run(corefs, sentences)
html = html.replace("\n\n", "\n")
result = HTML_WRAPPER.format(html)
return render_template("coref_result.html", rawtext=raw_text, result=result)
if __name__ == "__main__":
app.run(debug=True)