Sadashiv commited on
Commit
af072c5
1 Parent(s): 14b9ebd

image classifier complete

Browse files
app.py CHANGED
@@ -1,5 +1,6 @@
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
@@ -9,6 +10,8 @@ import base64
9
 
10
  app = Flask(__name__)
11
 
 
 
12
  @app.route("/")
13
  @app.route("/home")
14
  def home():
@@ -88,10 +91,36 @@ def fertilizer_recommendation_output():
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')
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  @app.route('/market_price')
96
  def market_price():
97
  return render_template("market_price_input.html")
@@ -100,7 +129,7 @@ def market_price():
100
  def market_price_output():
101
  # input field name is 'selected_state'
102
  user_input = request.form.get('selected_state')
103
- api_key = "579b464db66ec23bdd000001cdd3946e44ce4aad7209ff7b23ac571b"
104
 
105
  # Make a request to the API with the user input
106
  api_url = f'https://api.data.gov.in/resource/9ef84268-d588-465a-a308-a864a43d0070?api-key={api_key}&format=json&filters%5Bstate%5D={user_input}'
@@ -109,8 +138,12 @@ def market_price_output():
109
  if response.status_code == 200:
110
  data = response.json()
111
  data = data['records']
 
 
112
  # Return the JSON data as a response
113
- return render_template('market_price_output.html', data=data)
 
 
114
  else:
115
  return jsonify({'error': 'Unable to fetch data from the API'}), 400
116
 
 
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 config import plant_diseases_classifier_model
4
  from utils import retrieve_image_by_name_from_mongodb, retrieve_data
5
  from flask import Flask, request, render_template, jsonify
6
  import requests
 
10
 
11
  app = Flask(__name__)
12
 
13
+ app.config['UPLOAD_FOLDER'] = 'static/uploaded_image'
14
+
15
  @app.route("/")
16
  @app.route("/home")
17
  def home():
 
91
  return render_template('fertilizer_recommendation_ouput.html', image_data_base64=image_data_base64, label= label[0], fertilizer_details=fertilizer_details)
92
 
93
 
94
+ @app.route('/image_classification', methods=['GET', 'POST'])
95
  def image_classification():
96
  return render_template('image_classification_input.html')
97
 
98
+ @app.route('/image_classification_output', methods=['GET', 'POST'])
99
+ def image_classification_output():
100
+ file = request.files['image_file']
101
+ new_filename = "plant_image.JPG"
102
+ file.save(os.path.join(app.config['UPLOAD_FOLDER'], new_filename))
103
+ file_path = os.path.join(app.config['UPLOAD_FOLDER'], new_filename)
104
+
105
+ # infercing the with the uploaded image
106
+ results = plant_diseases_classifier_model(file_path)
107
+
108
+ #fetching all the labels
109
+ names_dict = results[0].names
110
+
111
+ # fetching the probalility of each class
112
+ probs = results[0].probs.data.tolist()
113
+
114
+ # selecting class with maximum probability
115
+ model_prediction= names_dict[np.argmax(probs)]
116
+
117
+ diseases_details = retrieve_data(database_name=os.getenv("DISEASE_DB_NAME"),
118
+ collection_name=os.getenv("DISEASE_INFO_COLLECTION_NAME"),
119
+ search_query=model_prediction)
120
+
121
+ return render_template("image_classification_output.html", model_prediction=model_prediction, diseases_details=diseases_details)
122
+
123
+
124
  @app.route('/market_price')
125
  def market_price():
126
  return render_template("market_price_input.html")
 
129
  def market_price_output():
130
  # input field name is 'selected_state'
131
  user_input = request.form.get('selected_state')
132
+ api_key = os.getenv("COMMODITY_PRICE_API_KEY")
133
 
134
  # Make a request to the API with the user input
135
  api_url = f'https://api.data.gov.in/resource/9ef84268-d588-465a-a308-a864a43d0070?api-key={api_key}&format=json&filters%5Bstate%5D={user_input}'
 
138
  if response.status_code == 200:
139
  data = response.json()
140
  data = data['records']
141
+ # return render_template('market_price_output.html', data=data)
142
+ if len(data) > 0:
143
  # Return the JSON data as a response
144
+ return render_template('market_price_output.html', data=data)
145
+ else:
146
+ return render_template("market_price_no_data.html")
147
  else:
148
  return jsonify({'error': 'Unable to fetch data from the API'}), 400
149
 
artifacts.py CHANGED
@@ -7,6 +7,8 @@ TRANSFORMER_OJBCET_NAME = "transformer.pkl"
7
  crop_recommendation_artifacts_path = "./crop-recommendation/saved_models"
8
  fertilizer_recommendation_artifacts_path = "./Fertilizer-Recommendation/saved_models"
9
 
 
 
10
 
11
  ## crop recommendation artifacts
12
  latest_crop_recommendation_artifacts = max(os.listdir(crop_recommendation_artifacts_path)) #0, 1, 2
 
7
  crop_recommendation_artifacts_path = "./crop-recommendation/saved_models"
8
  fertilizer_recommendation_artifacts_path = "./Fertilizer-Recommendation/saved_models"
9
 
10
+ plant_diseases_classifier_model_path = "./plant-diseases-classifier/custom_model_weights/best.pt"
11
+
12
 
13
  ## crop recommendation artifacts
14
  latest_crop_recommendation_artifacts = max(os.listdir(crop_recommendation_artifacts_path)) #0, 1, 2
config.py CHANGED
@@ -1,7 +1,9 @@
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,
@@ -9,4 +11,6 @@ crop_model, crop_pipeline_encoder, crop_label_encoder = load_model_and_encoders(
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)
 
 
 
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
+ from artifacts import plant_diseases_classifier_model_path
4
 
5
  from utils import load_model_and_encoders
6
+ from ultralytics import YOLO
7
 
8
  crop_model, crop_pipeline_encoder, crop_label_encoder = load_model_and_encoders(model_path=crop_model_path,
9
  transformer_path=crop_transformer_path,
 
11
 
12
  fertilizer_model, fertilizer_pipeline_encoder, fertilizer_label_encoder = load_model_and_encoders(model_path=fertilizer_model_path,
13
  transformer_path=fertilizer_transformer_path,
14
+ target_encoder_path=fertilizer_target_encoder_path)
15
+
16
+ plant_diseases_classifier_model = YOLO(plant_diseases_classifier_model_path)
requirements.txt CHANGED
@@ -4,4 +4,5 @@ requests
4
  numpy
5
  python-dotenv
6
  scikit-learn
7
- dill
 
 
4
  numpy
5
  python-dotenv
6
  scikit-learn
7
+ dill
8
+ ultralytics
static/uploaded_image/plant_image.JPG CHANGED
templates/index.html CHANGED
@@ -229,8 +229,7 @@
229
  <div class="card-body">
230
  <h5 class="card-title">Crop Recommendation</h5>
231
  <p class="card-text">
232
- Some quick example text to build on the card title and make up the
233
- bulk of the card's content.
234
  </p>
235
  <a href="{{url_for('crop_recommendation')}}" class="btn btn-primary"
236
  >Visit Page</a
@@ -248,8 +247,7 @@
248
  <div class="card-body">
249
  <h5 class="card-title">Fertilizer Recommendation</h5>
250
  <p class="card-text">
251
- Some quick example text to build on the card title and make up the
252
- bulk of the card's content.
253
  </p>
254
  <a
255
  href="{{url_for('fertilizer_recommendation')}}"
@@ -269,8 +267,7 @@
269
  <div class="card-body">
270
  <h5 class="card-title">Dieases Classification</h5>
271
  <p class="card-text">
272
- Some quick example text to build on the card title and make up the
273
- bulk of the card's content.
274
  </p>
275
  <a
276
  href="{{url_for('image_classification')}}"
@@ -290,8 +287,7 @@
290
  <div class="card-body">
291
  <h5 class="card-title">Market Price</h5>
292
  <p class="card-text">
293
- Some quick example text to build on the card title and make up the
294
- bulk of the card's content.
295
  </p>
296
  <a href="{{url_for('market_price')}}" class="btn btn-primary"
297
  >Visit Page</a
@@ -307,8 +303,8 @@
307
  <div class="container text-center">
308
  <p>Connect on Social Media</p>
309
  <div class="social-icons">
310
- <a href="#"><img src="/static/images/github-logo.png" alt="" /></a>
311
- <a href="#"><img src="/static/images/linkedin-icon.png" alt="" /></a>
312
  </div>
313
  </div>
314
  </section>
@@ -320,7 +316,7 @@
320
  <div class="col-md-4 footer-box">
321
  <img src="/static/images/logo.png" alt="" />
322
  <p class="addition-info">
323
- Please Try all the features and comment and share
324
  </p>
325
  </div>
326
  </div>
 
229
  <div class="card-body">
230
  <h5 class="card-title">Crop Recommendation</h5>
231
  <p class="card-text">
232
+ <b>Harvesting Insights:</b> Transforming Farming with AI-Driven Crop Recommendations
 
233
  </p>
234
  <a href="{{url_for('crop_recommendation')}}" class="btn btn-primary"
235
  >Visit Page</a
 
247
  <div class="card-body">
248
  <h5 class="card-title">Fertilizer Recommendation</h5>
249
  <p class="card-text">
250
+ <b>Fertile Future:</b> Enhancing Agriculture with AI-Driven Fertilizer Recommendations
 
251
  </p>
252
  <a
253
  href="{{url_for('fertilizer_recommendation')}}"
 
267
  <div class="card-body">
268
  <h5 class="card-title">Dieases Classification</h5>
269
  <p class="card-text">
270
+ <b>Sight to Insight:</b> Advancing Farming through Image-Based Disease Identification
 
271
  </p>
272
  <a
273
  href="{{url_for('image_classification')}}"
 
287
  <div class="card-body">
288
  <h5 class="card-title">Market Price</h5>
289
  <p class="card-text">
290
+ <b>Price Insights:</b> Commodity Markets in Indian States with Real-time Government Data
 
291
  </p>
292
  <a href="{{url_for('market_price')}}" class="btn btn-primary"
293
  >Visit Page</a
 
303
  <div class="container text-center">
304
  <p>Connect on Social Media</p>
305
  <div class="social-icons">
306
+ <a href="https://github.com/07Sada"><img src="/static/images/github-logo.png" alt="" /></a>
307
+ <a href="https://www.linkedin.com/in/sadashiv-nandanikar/"><img src="/static/images/linkedin-icon.png" alt="" /></a>
308
  </div>
309
  </div>
310
  </section>
 
316
  <div class="col-md-4 footer-box">
317
  <img src="/static/images/logo.png" alt="" />
318
  <p class="addition-info">
319
+ I wholeheartedly encourage you to explore all the features and kindly request your valuable feedback. Your insights are highly valued.
320
  </p>
321
  </div>
322
  </div>