-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
86 lines (77 loc) · 2.21 KB
/
app.py
File metadata and controls
86 lines (77 loc) · 2.21 KB
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
from flask import Flask , jsonify
from flask.globals import request
from flask.helpers import send_file
import numpy as np
import pandas as pd
import ast
import json
import requests
from matplotlib import pyplot as plt
app= Flask(__name__)
@app.route('/NL_Question', methods= ['POST'])
#recieve the NL Question and forward it to the model
def parse_Question():
NL_Question = request.form.get('NL_Question')
print(NL_Question)
url = 'http://509ff9514fa1.ngrok.io/question'
r = requests.post(url, data= {'nl_question': NL_Question})
return r.json()
@app.route('/barChart', methods= ['POST'])
def bar_req():
req_data = eval(request.form.get('data'))
axesOrder = eval(request.form.get('axesOrder'))
acol1 =[]
acol2 =[]
for x in req_data:
acol1.append(x[0])
acol2.append(x[1])
if(axesOrder==1):
Bchart = barChart(acol1, acol2)
else:
Bchart = barChart(acol2, acol1)
return Bchart
@app.route('/pieChart', methods=['POST'])
def pie_req():
req_data = eval(request.form.get('data'))
axesOrder = eval(request.form.get('axesOrder'))
print(type(req_data))
acol1 =[]
acol2 =[]
for x in req_data:
acol1.append(x[0])
acol2.append(x[1])
if(axesOrder == 1):
PChart = pieChart(acol1, acol2)
else:
PChart = pieChart(acol2, acol1)
return PChart
@app.route('/lineChart', methods= ['POST'])
def line_req():
req_data = eval(request.form.get('data'))
axesOrder = eval(request.form.get('axesOrder'))
print(type(req_data))
acol1 =[]
acol2 =[]
for x in req_data:
acol1.append(x[0])
acol2.append(x[1])
if(axesOrder == 1):
lChart = lineChart(acol1, acol2)
else:
lChart = lineChart(acol2, acol1)
return lChart
def barChart(columns , data):
plt.bar(columns, data)
plt.savefig('barfoo.png')
plt.clf()
return send_file('barfoo.png')
def pieChart(columns, data):
plt.pie(data,labels =columns, autopct ='%1.1f%%')
plt.savefig('piefoo.png')
plt.clf()
return send_file('piefoo.png')
def lineChart(columns, data):
plt.plot(columns, data)
plt.savefig('lineFoo.png')
plt.clf()
return send_file('lineFoo.png')