Pranjal-psytech
commited on
Commit
•
d7c9890
1
Parent(s):
ddd6e3d
"request"
Browse files
app.py
CHANGED
@@ -17,22 +17,23 @@ CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
|
|
17 |
|
18 |
def classify_image(request):
|
19 |
# Open the file using requests
|
20 |
-
|
21 |
-
img = Image.open(BytesIO(response.content))
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
img_array = np.expand_dims(img_array, axis=0)
|
27 |
|
28 |
-
#
|
29 |
-
pred = model.predict(img_array)
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
# Resize the image to the desired size
|
37 |
# new_size = (256, 256)
|
38 |
# img_resized = image.resize(new_size)
|
|
|
17 |
|
18 |
def classify_image(request):
|
19 |
# Open the file using requests
|
20 |
+
image = request.files["file"]
|
|
|
21 |
|
22 |
+
image = np.array(
|
23 |
+
Image.open(image).convert("RGB").resize((256, 256)) # image resizing
|
24 |
+
)
|
|
|
25 |
|
26 |
+
image = image/255 # normalize the image in 0 to 1 range
|
|
|
27 |
|
28 |
+
img_array = tf.expand_dims(img, 0)
|
29 |
+
predictions = model.predict(img_array)
|
30 |
|
31 |
+
print("Predictions:",predictions)
|
32 |
+
|
33 |
+
predicted_class = class_names[np.argmax(predictions[0])]
|
34 |
+
confidence = round(100 * (np.max(predictions[0])), 2)
|
35 |
+
|
36 |
+
return {"class": predicted_class, "confidence": confidence}
|
37 |
# Resize the image to the desired size
|
38 |
# new_size = (256, 256)
|
39 |
# img_resized = image.resize(new_size)
|