-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
157 lines (129 loc) · 4.81 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from flask import Flask,request, render_template
from flask_mysqldb import MySQL
import pickle
import numpy as np
import pandas as pd
app = Flask(__name__)
app.config['MYSQL_HOST']= 'localhost'
app.config['MYSQL_USER']= 'Zehra'
app.config['MYSQL_PASSWORD']= ''
app.config['MYSQL_DB']= 'national'
mysql = MySQL(app)
@app.route('/national2')
def national2():
return render_template('national.html')
@app.route('/gdprate')
def gdp():
return render_template('gdp.html')
@app.route('/export_import')
def expoimport():
return render_template('export_import.html')
@app.route('/national1', methods=['POST'])
def nationalchart():
if request.method == 'POST':
state = request.form['state']
cur = mysql.connection.cursor()
cur.execute("SELECT states1.nationalshare FROM states1 WHERE statename = % s ", (state, ))
fetchdata = cur.fetchall()[0]
fetchdata= fetchdata[0]
cur.close()
return render_template('national.html', data= fetchdata)
@app.route('/gdp', methods=['POST'])
def gdpshare():
if request.method == 'POST':
country = request.form['country']
cur = mysql.connection.cursor()
cur.execute("SELECT gdp.Gdp FROM gdp WHERE Country_Name = % s ", (country, ))
fetchdata = cur.fetchall()[0]
fetchdata= fetchdata[0]
cur.close()
return render_template('gdp.html', data= fetchdata)
@app.route('/export_import_rate', methods=['POST'])
def expoimpo():
if request.method == 'POST':
country = request.form['country']
cur = mysql.connection.cursor()
cur.execute("SELECT export_import.Export FROM export_import WHERE Country = % s ", (country, ))
fetchdata = cur.fetchall()[0]
fetchdata = fetchdata[0]
cur.execute("SELECT export_import.Import FROM export_import WHERE Country = % s ", (country, ))
fetchdata1 = cur.fetchall()[0]
fetchdata1 = fetchdata1[0]
cur.execute("SELECT export_import.Total_Trade FROM export_import WHERE Country = % s ", (country, ))
fetchdata2 = cur.fetchall()[0]
fetchdata2 = fetchdata2[0]
cur.execute("SELECT export_import.value FROM export_import WHERE Country = % s ", (country, ))
fetchdata3 = cur.fetchall()[0]
fetchdata3 = fetchdata3[0]
cur.close()
return render_template('export_import.html', Export= fetchdata, Import=fetchdata1, trade= fetchdata2, value=fetchdata3)
@app.route('/')
def homepage():
return render_template('index.html')
@app.route('/home')
def index():
return render_template('main.html')
@app.route('/land')
def index1():
return render_template('land.html')
@app.route('/Estimator')
def index2():
return render_template('Estimator.html')
@app.route('/predict', methods = ['POST'])
def predict():
if request.method== 'POST':
TGA = request.form['TGA']
TGE = request.form['TGE']
NGA = request.form['NGA']
NGE = request.form['NGE']
HGA = request.form['HGA']
HGE = request.form['HGE']
data =[TGA,TGE,NGA,NGE,HGA,HGE]
data = np.array(data).reshape(-1,6)
Ps= pickle.load(open('decision_tree_model_final.pkl','rb'))
prediction = Ps.predict(data)[0]
if prediction == 4:
pre ="Western"
if prediction == 3:
pre ="Southern"
if prediction == 2:
pre ="Northern"
if prediction == 1:
pre = "NorthEastern"
if prediction == 0:
pre = "Eastern"
return render_template('main.html',prediction= pre)
@app.route('/predict1', methods = ['POST'])
def predict1():
if request.method== 'POST':
NY = request.form['NY']
WY = request.form['WY']
YF = request.form['YF']
data =[NY,WY,YF]
data = np.array(data).reshape(-1,3)
Ps= pickle.load(open('yield_factor.pkl','rb'))
prediction = Ps.predict(data)[0]
if prediction == 0:
pre ="Crop Land"
if prediction == 2:
pre ="grazing Land"
if prediction == 5:
pre ="marine fishing grounds"
if prediction == 4:
pre = "inland fishing grounds"
if prediction == 1:
pre = "forest land"
if prediction == 3:
pre = "infrastructure"
return render_template('land.html',prediction= pre)
@app.route('/predict2', methods = ['POST'])
def estimate():
if request.method== 'POST':
cp = request.form['cp']
data =[cp]
data = np.array(data).reshape(-1,1)
Ps= pickle.load(open('e hack random forest_pkl','rb'))
prediction = Ps.predict(data)[0]
return render_template('Estimator.html',prediction= prediction)
if __name__ == '__main__':
app.run(debug=True)