forked from vp-1234ms/YANTRA-HACK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
221 lines (202 loc) · 10.3 KB
/
application.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from flask import Flask, request, render_template,app
from PIL import Image
import numpy as np
import os
from tensorflow import keras
from tensorflow.keras import layers
application = Flask(__name__)
app=application
@app.route('/')
def index():
return render_template('home.html')
@app.route('/upload', methods=['POST'])
def upload():
if 'image' not in request.files:
return 'No image uploaded'
new_image_path = r"img/image.jpg"
input_width, input_height = 224, 224
image = request.files['image']
# Save the image to a specific path
image.save('img/image.jpg')
st = request.form['crop']
if(st=="Apple"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
# Set the desired dimensions for the input images
input_width, input_height = 224, 224
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("AppleFruit")
prediction = model.predict(img_array)
class_label = "Apple With Black Rot" if prediction[0][0] < 0.5 else "Healthy Apple"
return class_label
# Provide the path to a new image for prediction
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Potato"):
# Make predictions on a new image using the saved model
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Potato Fruit")
prediction = model.predict(img_array)
class_label = "Potato With Early Blight" if prediction[0][0] < 0.5 else "Healthy Potato"
return class_label
# Provide the path to a new image for prediction
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Tomato"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Tomato Fruit")
prediction = model.predict(img_array)
class_label = "Tomato backtorial Spot" if prediction[0][0] < 0.5 else "Healthy Tomato"
return class_label
# Provide the path to a new image for prediction
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Cron"):
# Make predictions on a new image using the saved model
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Potato Fruit")
prediction = model.predict(img_array)
class_label = "Corn With Common Rust" if prediction[0][0] < 0.5 else "Healthy Corn"
return class_label
# Provide the path to a new image for prediction
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Bell Pepper"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Potato Fruit")
prediction = model.predict(img_array)
class_label = "Bell Pepper With Bactorial Spot" if prediction[0][0] < 0.5 else "Healthy Bell Pepper"
return class_label
# Provide the path to a new image for prediction
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Strawberry"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Strawberry Fruit")
prediction = model.predict(img_array)
class_label = "Strawberry With Leaf Scorch" if prediction[0][0] < 0.5 else "Healthy Strawberry"
return class_label
# Provide the path to a new image for prediction
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Cherry"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Cherry Fruit")
prediction = model.predict(img_array)
class_label = "Cherry With Powder Mildrew" if prediction[0][0] < 0.5 else "Healthy Cherry"
return class_label
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Peach"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Peach Fruit")
prediction = model.predict(img_array)
class_label = "Peach With Bacterial Spot" if prediction[0][0] < 0.5 else "Healthy Peach"
return class_label
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Citrus"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("Potato Fruit")
prediction = model.predict(img_array)
class_label = "Citrus With Black Spot" if prediction[0][0] < 0.5 else "Healthy Citrus"
return class_label
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Grape"):
# Make predictions on a new image
def predict_image(image_path):
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
prediction = model10.predict(img_array)
model = keras.models.load_model("Potao Fruit")
class_label = "Grape With Black Measles" if prediction[0][0] < 0.5 else "Healthy Grape"
return class_label
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
elif(st=="Hibiscus"):
# Make predictions on a new image using the saved model
def predict_image(image_path):
# Set the desired dimensions for the input images
input_width, input_height = 224, 224
img = Image.open(image_path)
img = img.resize((input_width, input_height))
img_array = np.array(img)
img_array = img_array / 255.0 # Normalize pixel values between 0 and 1
img_array = np.expand_dims(img_array, axis=0) # Add an extra dimension for batch
model = keras.models.load_model("AppleFruit")
prediction = model.predict(img_array)
class_label = "Hibiscus With Disease" if prediction[0][0] < 0.5 else "Healthy Hibiscus"
return class_label
# Provide the path to a new image for prediction
new_image_path = r"img/image.jpg"
prediction = predict_image(new_image_path)
print("Prediction:", prediction)
return render_template('result.html',pred=prediction)
if __name__ == '__main__':
app.run(host='0.0.0.0')