-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (39 loc) · 1.33 KB
/
app.py
File metadata and controls
55 lines (39 loc) · 1.33 KB
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
from flask import Flask,url_for,render_template,request
import spacy
from spacy import displacy
nlp = spacy.load('CrimeNER')
import json
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)
# def analyze_text(text):
# return nlp(text)
@app.route('/')
def index():
# raw_text = "Bill Gates is An American Computer Scientist since 1986"
# docx = nlp(raw_text)
# html = displacy.render(docx,style="ent")
# html = html.replace("\n\n","\n")
# result = HTML_WRAPPER.format(html)
return render_template('index.html')
@app.route('/extract',methods=["GET","POST"])
def extract():
if request.method == 'POST':
raw_text = request.form['rawtext']
docx = nlp(raw_text)
html = displacy.render(docx,style="ent")
html = html.replace("\n\n","\n")
result = HTML_WRAPPER.format(html)
return render_template('result.html',rawtext=raw_text,result=result)
@app.route('/previewer')
def previewer():
return render_template('previewer.html')
@app.route('/preview',methods=["GET","POST"])
def preview():
if request.method == 'POST':
newtext = request.form['newtext']
result = newtext
return render_template('preview.html',newtext=newtext,result=result)
if __name__ == '__main__':
app.run(debug=True)