NitinBot001 commited on
Commit
95efb1d
·
verified ·
1 Parent(s): c3bd413

Update AgriGo/app.py

Browse files
Files changed (1) hide show
  1. AgriGo/app.py +71 -71
AgriGo/app.py CHANGED
@@ -1,71 +1,71 @@
1
- from flask import Flask, render_template, request, send_from_directory
2
- import random, os
3
- from werkzeug.utils import secure_filename
4
- from functions import img_predict, get_diseases_classes, get_crop_recommendation, get_fertilizer_recommendation, soil_types, Crop_types, crop_list
5
-
6
-
7
- app = Flask(__name__)
8
- random.seed(0)
9
- app.config['SECRET_KEY'] = os.urandom(24)
10
-
11
- UPLOAD_FOLDER = 'uploads'
12
- STATIC_FOLDER = 'static'
13
-
14
- dir_path = os.path.dirname(os.path.realpath(__file__))
15
-
16
- @app.route('/', methods=['GET', 'POST'])
17
- def index():
18
- return render_template('index.html')
19
-
20
- @app.route('/crop-recommendation', methods=['GET', 'POST'])
21
- def crop_recommendation():
22
- if request.method == "POST":
23
- to_predict_list = request.form.to_dict()
24
- to_predict_list = list(to_predict_list.values())
25
- to_predict_list = list(map(float, to_predict_list))
26
- result = get_crop_recommendation(to_predict_list)
27
- return render_template("recommend_result.html", result=result)
28
- else:
29
- return render_template('crop-recommend.html')
30
-
31
- @app.route('/fertilizer-recommendation', methods=['GET', 'POST'])
32
- def fertilizer_recommendation():
33
- if request.method == "POST":
34
- to_predict_list = request.form.to_dict()
35
- to_predict_list = list(to_predict_list.values())
36
- to_predict_list = list(map(float, to_predict_list))
37
- result = get_fertilizer_recommendation(
38
- num_features=to_predict_list[:-2],
39
- cat_features=to_predict_list[-2:]
40
- )
41
- return render_template("recommend_result.html", result=result)
42
- else:
43
- return render_template(
44
- 'fertilizer-recommend.html',
45
- soil_types=enumerate(soil_types),
46
- crop_types=enumerate(Crop_types)
47
- )
48
-
49
-
50
- @app.route('/crop-disease', methods=['POST','GET'])
51
- def find_crop_disease():
52
- if request.method=="GET":
53
- return render_template('crop-disease.html', crops=crop_list)
54
- else:
55
- file = request.files["file"]
56
- crop = request.form["crop"]
57
-
58
- basepath = os.path.dirname(__file__)
59
- file_path = os.path.join(basepath,'uploads', secure_filename(file.filename))
60
- file.save(file_path)
61
- prediction = img_predict(file_path, crop)
62
- result = get_diseases_classes(crop, prediction)
63
-
64
- return render_template('disease-prediction-result.html', image_file_name=file.filename, result=result)
65
-
66
- @app.route('/uploads/<filename>')
67
- def send_file(filename):
68
- return send_from_directory(UPLOAD_FOLDER, filename)
69
-
70
- if __name__ == '__main__':
71
- app.run(debug=True)
 
1
+ from flask import Flask, render_template, request, send_from_directory
2
+ import random, os
3
+ from werkzeug.utils import secure_filename
4
+ from functions import img_predict, get_diseases_classes, get_crop_recommendation, get_fertilizer_recommendation, soil_types, Crop_types, crop_list
5
+
6
+
7
+ app = Flask(__name__)
8
+ random.seed(0)
9
+ app.config['SECRET_KEY'] = os.urandom(24)
10
+
11
+ UPLOAD_FOLDER = 'uploads'
12
+ STATIC_FOLDER = 'static'
13
+
14
+ dir_path = os.path.dirname(os.path.realpath(__file__))
15
+
16
+ @app.route('/', methods=['GET', 'POST'])
17
+ def index():
18
+ return render_template('index.html')
19
+
20
+ @app.route('/crop-recommendation', methods=['GET', 'POST'])
21
+ def crop_recommendation():
22
+ if request.method == "POST":
23
+ to_predict_list = request.form.to_dict()
24
+ to_predict_list = list(to_predict_list.values())
25
+ to_predict_list = list(map(float, to_predict_list))
26
+ result = get_crop_recommendation(to_predict_list)
27
+ return render_template("recommend_result.html", result=result)
28
+ else:
29
+ return render_template('crop-recommend.html')
30
+
31
+ @app.route('/fertilizer-recommendation', methods=['GET', 'POST'])
32
+ def fertilizer_recommendation():
33
+ if request.method == "POST":
34
+ to_predict_list = request.form.to_dict()
35
+ to_predict_list = list(to_predict_list.values())
36
+ to_predict_list = list(map(float, to_predict_list))
37
+ result = get_fertilizer_recommendation(
38
+ num_features=to_predict_list[:-2],
39
+ cat_features=to_predict_list[-2:]
40
+ )
41
+ return render_template("recommend_result.html", result=result)
42
+ else:
43
+ return render_template(
44
+ 'fertilizer-recommend.html',
45
+ soil_types=enumerate(soil_types),
46
+ crop_types=enumerate(Crop_types)
47
+ )
48
+
49
+
50
+ @app.route('/crop-disease', methods=['POST','GET'])
51
+ def find_crop_disease():
52
+ if request.method=="GET":
53
+ return render_template('crop-disease.html', crops=crop_list)
54
+ else:
55
+ file = request.files["file"]
56
+ crop = request.form["crop"]
57
+
58
+ basepath = os.path.dirname(__file__)
59
+ file_path = os.path.join(basepath,'uploads', secure_filename(file.filename))
60
+ file.save(file_path)
61
+ prediction = img_predict(file_path, crop)
62
+ result = get_diseases_classes(crop, prediction)
63
+
64
+ return render_template('disease-prediction-result.html', image_file_name=file.filename, result=result)
65
+
66
+ @app.route('/uploads/<filename>')
67
+ def send_file(filename):
68
+ return send_from_directory(UPLOAD_FOLDER, filename)
69
+
70
+ if __name__ == '__main__':
71
+ app.run(debug=True,port=7860)