-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (34 loc) · 1.23 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
from flask import Flask, request, render_template, redirect, url_for, session
from main.run import parse, interpret, transpile
app = Flask(__name__)
app.secret_key = "secretsecret"
@app.before_request
def initialize_history():
if "history" not in session:
session["history"] = []
@app.route("/")
def index():
return render_template("index.html", history=session["history"])
@app.route("/evaluate", methods=["POST"])
def evaluate():
expression = request.form["expression"]
input_tree = parse(expression) # generate input tree
latex_input = transpile(input_tree) # generate latex code for input representation
output_tree = interpret(input_tree) # interpret expression
latex_output = transpile(
output_tree
) # generate latex code for output representation
result = {
"expression": expression,
"latex_input": latex_input,
"latex_output": latex_output,
}
session["history"].append(result)
session.modified = True
return redirect(url_for("index"))
@app.route("/clear_history", methods=["POST"])
def clear_history():
session["history"] = []
return redirect(url_for("index"))
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)