-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·61 lines (52 loc) · 1.43 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
#!/usr/bin/env python3
from flask import Flask, jsonify, render_template, request, current_app
import schemepy
import schemepy.reader as rd
import schemepy.evaluator as ev
import imp
import time
import sys
sys.setrecursionlimit(100000)
DEBUG = True
SECRET_KEY = '$(secret_key)'
app = Flask(__name__)
app.config.from_object(__name__)
env = ev.get_root_environment()
@app.route('/_interpret')
def evaluate():
global env
statement = request.args.get('statement')
ev = imp.reload(schemepy.evaluator)
env = ev.get_root_environment()
try:
start = time.time()
expression = rd.parse(statement)
current_app.logger.info(expression)
res = ev.evaluate(expression, env)
end = time.time() - start
current_app.logger.info(end)
res= str(res)
except Exception as e:
expression = rd.parse(statement)
res = e
res= str(res)
return jsonify(result=res)
@app.route('/_interpretDirect')
def direct():
statement = request.args.get('statement')
try:
expression = rd.parse(statement)
res = ev.evaluate(expression, env)
res = str(res)
current_app.logger.info(res)
except Exception as e:
res = e
return jsonify(result=res)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
if __name__ == '__main__':
app.run(debug=True)