Pranjal-psytech commited on
Commit
d7c9890
1 Parent(s): ddd6e3d
Files changed (1) hide show
  1. app.py +13 -12
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
- response = requests.get("file")
21
- img = Image.open(BytesIO(response.content))
22
 
23
- # Resize and preprocess the image
24
- img_resized = img.convert("RGB").resize((256, 256))
25
- img_array = np.array(img_resized) / 255.0
26
- img_array = np.expand_dims(img_array, axis=0)
27
 
28
- # Make predictions
29
- pred = model.predict(img_array)
30
 
31
- predicted_class = CLASS_NAMES[np.argmax(pred[0])]
32
- confidence = float(np.max(pred[0]))
33
 
34
- # Return the predicted class and confidence score
35
- return {"class": predicted_class, "confidence": confidence,"predict":pred[0]}
 
 
 
 
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)