Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
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 |
|