-
Notifications
You must be signed in to change notification settings - Fork 2
/
views.py
102 lines (90 loc) · 3.19 KB
/
views.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from flask import Blueprint, render_template, request, jsonify
from processImage import processImg
from cohereApi import getReturnMsg
views = Blueprint(__name__, "views")
retImg = ''
resp = []
msgLst = []
msgcount = 0
forums = []
@views.route("/", methods = ['POST','GET'])
def home():
global forums
if request.method == 'POST':
msg = request.form['fr']
print(msg)
if len(forums)==0 or msg!=forums[-1]:
forums.append(msg)
return render_template("index.html", frm = forums, frmln = len(forums))
else:
return render_template("index.html", frm = forums,frmln = len(forums))
@views.route("/plots", methods = ['POST','GET'])
def plots():
global retImg
if request.method == 'POST':
try:
msg = request.form['fr']
print(msg)
if len(forums)==0 or msg!=forums[-1]:
forums.append(msg)
except:
try:
img = request.form['imageData']
# print(img)
retImg = processImg(img)
except:
print('no image processed')
return render_template("plots.html",retImg = '', frm = forums, frmln = len(forums))
else:
return render_template("plots.html",retImg = '', frm = forums, frmln = len(forums))
@views.route('/get_image_data')
def get_image_data():
image_data = retImg
return jsonify(image_data=image_data)
@views.route("/test", methods = ['POST','GET'])
def tests():
global forums
if request.method == 'POST':
msg = request.form['fr']
print(msg)
if len(forums)==0 or msg!=forums[-1]:
forums.append(msg)
return render_template("test.html", frm = forums, frmln = len(forums))
else:
return render_template("test.html", frm = forums,frmln = len(forums))
@views.route("/chatbot", methods = ['POST','GET'])
def chatbot():
global resp, msgcount, msgLst
if request.method == 'POST':
try:
ff = request.form['fr']
print(ff)
if len(forums)==0 or ff!=forums[-1]:
forums.append(ff)
except:
try:
msg = request.form['qns']
if len(resp)==0 or msg!=msgLst[-1]:
msgLst.append(msg)
resp.append(getReturnMsg(msg))
msgcount = msgcount+1
except:
print('no message')
return render_template("chatbot.html", arg0=resp, arg1 = msgcount, arg2 = msgLst, frm = forums, frmln = len(forums))
else:
return render_template("chatbot.html", arg0=resp, arg1 = msgcount, arg2 = msgLst, frm = forums, frmln = len(forums))
# return render_template("chatbot.html")
@views.route("/base", methods = ['POST','GET'])
def bases():
return render_template("base.html")
@views.route("/info", methods = ['POST','GET'])
def info():
global forums
if request.method == 'POST':
msg = request.form['fr']
print(msg)
if len(forums)==0 or msg!=forums[-1]:
forums.append(msg)
return render_template("info.html", frm = forums, frmln = len(forums))
else:
return render_template("info.html", frm = forums,frmln = len(forums))