detectionpro commited on
Commit
1e7b342
·
verified ·
1 Parent(s): 1b3abb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -1,6 +1,6 @@
1
  #Import necessary libraries
2
  from flask import Flask, render_template, request
3
-
4
  import numpy as np
5
  import os
6
 
@@ -13,27 +13,32 @@ model =load_model("model/v4_1_pred_stra_dis.h5")
13
 
14
  print('@@ Model loaded')
15
 
 
 
16
 
17
  def pred_cot_dieas(cott_plant):
18
- test_image = load_img(cott_plant, target_size = (150, 150)) # load image
19
- print("@@ Got Image for prediction")
20
 
21
- test_image = img_to_array(test_image)/255 # convert image to np array and normalize
22
- test_image = np.expand_dims(test_image, axis = 0) # change dimention 3D to 4D
23
 
24
- result = model.predict(test_image).round(3) # predict diseased palnt or not
25
- print('@@ Raw result = ', result)
26
 
27
- pred = np.argmax(result) # get the index of max value
28
-
29
- if pred == 0:
30
- return "Diseased Strawberry Plant", 'http://localhost/typroject/diseases-anthracnose-fruit-rot/' # if index 0 burned leaf
31
- elif pred == 1:
32
- return 'Diseased Strawberry Plant', 'grey_mold.html' # # if index 1
33
- elif pred == 2:
34
- return 'Diseased Strawberry Plant', 'leaf_spot.html' # if index 2 fresh leaf
35
- else:
36
- return "Diseased Strawberry Plant", 'powdery_mildew_leaf.html' # if index 3
 
 
 
37
 
38
  #------------>>pred_cot_dieas<<--end
39
 
 
1
  #Import necessary libraries
2
  from flask import Flask, render_template, request
3
+ import webbrowser
4
  import numpy as np
5
  import os
6
 
 
13
 
14
  print('@@ Model loaded')
15
 
16
+ def open_url_in_browser(url):
17
+ webbrowser.open_new(url)
18
 
19
  def pred_cot_dieas(cott_plant):
20
+ test_image = load_img(cott_plant, target_size=(150, 150)) # load image
21
+ print("@@ Got Image for prediction")
22
 
23
+ test_image = img_to_array(test_image)/255 # convert image to np array and normalize
24
+ test_image = np.expand_dims(test_image, axis=0) # change dimension 3D to 4D
25
 
26
+ result = model.predict(test_image).round(3) # predict diseased plant or not
27
+ print('@@ Raw result = ', result)
28
 
29
+ pred = np.argmax(result) # get the index of max value
30
+
31
+ if pred == 0:
32
+ url = 'http://localhost/typroject/diseases-anthracnose-fruit-rot/' # if index 0 burned leaf
33
+ elif pred == 1:
34
+ url = 'grey_mold.html' # if index 1
35
+ elif pred == 2:
36
+ url = 'leaf_spot.html' # if index 2 fresh leaf
37
+ else:
38
+ url = 'powdery_mildew_leaf.html' # if index 3
39
+
40
+ open_url_in_browser(url)
41
+ return "Diseased Strawberry Plant", url
42
 
43
  #------------>>pred_cot_dieas<<--end
44