File size: 2,188 Bytes
161ee83
 
1e7b342
161ee83
 
 
 
 
 
 
 
 
 
 
 
 
 
3949045
 
161ee83
3949045
 
161ee83
3949045
 
161ee83
3949045
 
 
35649b4
3949045
 
 
 
 
 
161ee83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c1d5755
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
#Import necessary libraries
from flask import Flask, render_template, request
import webbrowser
import numpy as np
import os

from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.models import load_model

#load model
model =load_model("model/v4_1_pred_stra_dis.h5")

print('@@ Model loaded')


def pred_cot_dieas(cott_plant):
  test_image = load_img(cott_plant, target_size = (150, 150)) # load image 
  print("@@ Got Image for prediction")
  
  test_image = img_to_array(test_image)/255 # convert image to np array and normalize
  test_image = np.expand_dims(test_image, axis = 0) # change dimention 3D to 4D
  
  result = model.predict(test_image).round(3) # predict diseased palnt or not
  print('@@ Raw result = ', result)
  
  pred = np.argmax(result) # get the index of max value
 
  if pred == 0:
    return "Diseased Strawberry Plant", 'angular_leafspot.html'# if index 0 burned leaf
  elif pred == 1:
      return 'Diseased Strawberry Plant', 'grey_mold.html' # # if index 1
  elif pred == 2:
      return 'Diseased Strawberry Plant', 'leaf_spot.html'  # if index 2  fresh leaf
  else:
    return "Diseased Strawberry Plant", 'powdery_mildew_leaf.html' # if index 3

#------------>>pred_cot_dieas<<--end

# Create flask instance
app = Flask(__name__)

# render index.html page
@app.route("/", methods=['GET', 'POST'])
def home():
        return render_template('index1.html')
    
 
# get input image from client then predict class and render respective .html page for solution
@app.route("/predict", methods = ['GET','POST'])
def predict():
     if request.method == 'POST':
        file = request.files['image'] # fet input
        filename = file.filename        
        print("@@ Input posted = ", filename)
        
        file_path = os.path.join('static/user uploaded', filename)
        file.save(file_path)

        print("@@ Predicting class......")
        pred, output_page = pred_cot_dieas(cott_plant=file_path)
              
        return render_template(output_page, pred_output = pred, user_image = file_path)
# For local system & cloud
if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)