fertilizer recommendation complete
Browse files- app.py +36 -1
- config.py +7 -1
- templates/fertilizer_recommendation_input.html +1 -1
- templates/fertilizer_recommendation_ouput.html +2 -2
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from config import crop_model, crop_pipeline_encoder, crop_label_encoder
|
|
|
2 |
from utils import retrieve_image_by_name_from_mongodb, retrieve_data
|
3 |
from flask import Flask, request, render_template, jsonify
|
4 |
import requests
|
@@ -49,10 +50,44 @@ def crop_recommendation_output():
|
|
49 |
return render_template('crop_recommendation_output.html', image_data_base64=image_data_base64, input_file_name=label[0], crop_details=crop_details)
|
50 |
|
51 |
|
52 |
-
@app.route('/fertilizer_recommendation')
|
53 |
def fertilizer_recommendation():
|
54 |
return render_template('fertilizer_recommendation_input.html')
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
@app.route('/image_classification')
|
57 |
def image_classification():
|
58 |
return render_template('image_classification_input.html')
|
|
|
1 |
from config import crop_model, crop_pipeline_encoder, crop_label_encoder
|
2 |
+
from config import fertilizer_model, fertilizer_pipeline_encoder, fertilizer_label_encoder
|
3 |
from utils import retrieve_image_by_name_from_mongodb, retrieve_data
|
4 |
from flask import Flask, request, render_template, jsonify
|
5 |
import requests
|
|
|
50 |
return render_template('crop_recommendation_output.html', image_data_base64=image_data_base64, input_file_name=label[0], crop_details=crop_details)
|
51 |
|
52 |
|
53 |
+
@app.route('/fertilizer_recommendation', methods=['GET', 'POST'])
|
54 |
def fertilizer_recommendation():
|
55 |
return render_template('fertilizer_recommendation_input.html')
|
56 |
|
57 |
+
@app.route('/fertilizer_recommendation_output', methods=['GET', 'POST'])
|
58 |
+
def fertilizer_recommendation_output():
|
59 |
+
temperature = request.form.get("temperature")
|
60 |
+
humidity = request.form.get("humidity")
|
61 |
+
moisture = request.form.get("moisture")
|
62 |
+
nitrogen = request.form.get("nitrogen")
|
63 |
+
potassium = request.form.get("potassium")
|
64 |
+
phosphorous = request.form.get("phosphorous")
|
65 |
+
soil_type = request.form.get("soil_type")
|
66 |
+
crop_type = request.form.get("crop_type")
|
67 |
+
|
68 |
+
input_data = [int(temperature), int(humidity), int(moisture), soil_type, crop_type, int(nitrogen), int(potassium), int(phosphorous)]
|
69 |
+
input_array = np.array(input_data).reshape(-1, 8)
|
70 |
+
|
71 |
+
transformed_data = fertilizer_pipeline_encoder.transform(input_array)
|
72 |
+
model_prediction = fertilizer_model.predict(transformed_data).astype(int)
|
73 |
+
|
74 |
+
label = fertilizer_label_encoder.inverse_transform(model_prediction)
|
75 |
+
|
76 |
+
# retrieving the image from mongodb dabase
|
77 |
+
image_data = retrieve_image_by_name_from_mongodb(database_name=os.getenv("FERTILIZER_DB_NAME"),
|
78 |
+
collection_name=os.getenv("FERTILIZER_IMAGE_COLLECTION_NAME"),
|
79 |
+
file_name=str(label[0]))
|
80 |
+
|
81 |
+
# encoding the byte data recieved from the mongodb
|
82 |
+
image_data_base64 = base64.b64encode(image_data).decode('utf-8')
|
83 |
+
|
84 |
+
# retrieving text data from mongodb
|
85 |
+
fertilizer_details = retrieve_data(database_name=os.getenv("FERTILIZER_DB_NAME"), collection_name= os.getenv("FERTILIZER_INFO_COLLECTION_NAME"), search_query=label[0])
|
86 |
+
|
87 |
+
|
88 |
+
return render_template('fertilizer_recommendation_ouput.html', image_data_base64=image_data_base64, label= label[0], fertilizer_details=fertilizer_details)
|
89 |
+
|
90 |
+
|
91 |
@app.route('/image_classification')
|
92 |
def image_classification():
|
93 |
return render_template('image_classification_input.html')
|
config.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
from artifacts import crop_model_path, crop_transformer_path, crop_target_encoder_path
|
|
|
|
|
2 |
from utils import load_model_and_encoders
|
3 |
|
4 |
crop_model, crop_pipeline_encoder, crop_label_encoder = load_model_and_encoders(model_path=crop_model_path,
|
5 |
transformer_path=crop_transformer_path,
|
6 |
-
target_encoder_path=crop_target_encoder_path)
|
|
|
|
|
|
|
|
|
|
1 |
from artifacts import crop_model_path, crop_transformer_path, crop_target_encoder_path
|
2 |
+
from artifacts import fertilizer_model_path, fertilizer_transformer_path, fertilizer_target_encoder_path
|
3 |
+
|
4 |
from utils import load_model_and_encoders
|
5 |
|
6 |
crop_model, crop_pipeline_encoder, crop_label_encoder = load_model_and_encoders(model_path=crop_model_path,
|
7 |
transformer_path=crop_transformer_path,
|
8 |
+
target_encoder_path=crop_target_encoder_path)
|
9 |
+
|
10 |
+
fertilizer_model, fertilizer_pipeline_encoder, fertilizer_label_encoder = load_model_and_encoders(model_path=fertilizer_model_path,
|
11 |
+
transformer_path=fertilizer_transformer_path,
|
12 |
+
target_encoder_path=fertilizer_target_encoder_path)
|
templates/fertilizer_recommendation_input.html
CHANGED
@@ -8,7 +8,7 @@
|
|
8 |
<div
|
9 |
class="container-fluid recommendation-input-container d-flex justify-content-center"
|
10 |
>
|
11 |
-
<form class="row g-3" method="
|
12 |
<h3 class="text-center">AI-Powered Fertilizer Recommendations</h3>
|
13 |
<div class="col-md-4" name="temperature">
|
14 |
<label for="temperature" class="form-label">Temperature</label>
|
|
|
8 |
<div
|
9 |
class="container-fluid recommendation-input-container d-flex justify-content-center"
|
10 |
>
|
11 |
+
<form class="row g-3" method="POST" action="/fertilizer_recommendation_output">
|
12 |
<h3 class="text-center">AI-Powered Fertilizer Recommendations</h3>
|
13 |
<div class="col-md-4" name="temperature">
|
14 |
<label for="temperature" class="form-label">Temperature</label>
|
templates/fertilizer_recommendation_ouput.html
CHANGED
@@ -22,8 +22,8 @@
|
|
22 |
<div
|
23 |
class="col-md-6 text d-flex flex-column justify-content-center align-items-center"
|
24 |
>
|
25 |
-
<h1 class="text-center">{{
|
26 |
-
<p class="text-center">{{
|
27 |
</div>
|
28 |
</div>
|
29 |
<a href="{{url_for('fertilizer_recommendation')}}" class="btn btn-primary" role="button"
|
|
|
22 |
<div
|
23 |
class="col-md-6 text d-flex flex-column justify-content-center align-items-center"
|
24 |
>
|
25 |
+
<h1 class="text-center">{{label.upper()}}</h1>
|
26 |
+
<p class="text-center">{{fertilizer_details}}</p>
|
27 |
</div>
|
28 |
</div>
|
29 |
<a href="{{url_for('fertilizer_recommendation')}}" class="btn btn-primary" role="button"
|