-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
72 lines (58 loc) · 2.05 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
import json
from _ast import alias
from flask import Flask, render_template, jsonify, request
import os
import alias
app = Flask(__name__, template_folder='templates')
app.config['STATIC_FOLDER'] = 'static'
static_file_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static')
af = None;
@app.route('/')
def demo():
return render_template('index.html')
@app.route('/framework/<af_id>', methods=['POST'])
def framework(af_id):
global af
af = alias.read_tgf(static_file_dir + '/examples/' + af_id + '.tgf')
return alias.get_json(af)
@app.route('/extension/<ext_id>', methods=['POST'])
def extension(ext_id):
global af
if af is not None:
if ext_id == 'Stable':
return json.dumps([list(v) for v in af.get_stable_extension()])
if ext_id == 'Complete':
return json.dumps([list(v) for v in af.get_complete_extension()])
if ext_id == 'Preferred':
return json.dumps([list(v) for v in af.get_preferred_extension()])
else:
return "Please select argumentation framework first"
@app.route('/upload_file', methods=['POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
global af
file.save(os.path.join("./upload/", file.filename))
af = alias.read_tgf("./upload/" + file.filename)
return alias.get_json(af)
@app.route('/addArgument/<arg>', methods=['GET'])
def add_argument(arg):
global af
if af is None:
af = alias.ArgumentationFramework('Test')
af.add_argument(arg)
return alias.get_json(af)
@app.route('/addAttack/<attacker>/<attacked>', methods=['GET'])
def add_attack(attacker, attacked):
global af
if af is None:
af = alias.ArgumentationFramework('Test')
af.add_attack((attacker, attacked))
return alias.get_json(af)
@app.route('/newFramework', methods=['GET'])
def new_framework():
global af
af = alias.ArgumentationFramework('Test')
return alias.get_json(af)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int('5000'), debug=True)