File size: 2,335 Bytes
366b225 |
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 81 82 83 84 85 86 87 |
try:
from flask import Flask
from flask import Flask, request, render_template, redirect, url_for, session, send_file
from flask_wtf import FlaskForm, RecaptchaField
from wtforms import StringField, SubmitField, RadioField, DateTimeField, SelectField, TextAreaField
from wtforms.validators import DataRequired
from flask import session
from flaskext.markdown import Markdown
from arc_eager import Process
import os
except Exception as e:
print(e)
print("Some Modules are Missing")
app = Flask(__name__)
Markdown(app)
app.config["SECRET_KEY"] = 'mysecretkey'
class Widgets(FlaskForm):
Statement = StringField(label="STATEMENT")
submit = SubmitField(label="Submit")
def foo(value):
print("Work to be done")
@app.after_request
def add_header(r):
"""
Add headers to both force latest IE rendering engine or Chrome Frame,
and also to cache the rendered page for 10 minutes.
"""
r.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
r.headers["Pragma"] = "no-cache"
r.headers["Expires"] = "0"
r.headers['Cache-Control'] = 'public, max-age=0'
return r
@app.route("/", methods=["GET", "POST"])
def home():
form = Widgets()
if request.method == 'POST':
if (form.validate_on_submit()):
val = form.Statement.data
print(val)
session['data'] = val
# return render_template('home.html', form=form)
return redirect('/thanks')
return render_template('home.html', form=form)
@app.route("/thanks", methods=["GET", "POST"])
def thanks():
val = session['data']
txt, err = Process(val)
txt = txt.split('\n')
# newval = foo(val)
ex = [{
"words": [
{"text": "This", "tag": "DT"},
{"text": "is", "tag": "VBZ"},
{"text": "a", "tag": "DT"},
{"text": "sentence", "tag": "NN"}
],
"arcs": [
{"start": 0, "end": 1, "label": "nsubj", "dir": "left"},
{"start": 2, "end": 3, "label": "det", "dir": "left"},
{"start": 1, "end": 3, "label": "attr", "dir": "right"}
]
}]
return render_template('thanks.html',user_image='/static/process.png',text=txt,show= not err)
if __name__ == "__main__":
app.run(debug=True)
|