Pranjal-psytech commited on
Commit
9483b80
2 Parent(s): 9818966 13a0e35

Merge branch 'main' of https://huggingface.co/spaces/Pranjal-666/Potato-leaf-disease-detection

Browse files
Files changed (1) hide show
  1. app.py +31 -19
app.py CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
4
  from PIL import Image
5
  from io import BytesIO
6
  import matplotlib.pyplot as plt
7
-
8
 
9
  # Load the trained TensorFlow model using the Keras API
10
  model = tf.keras.models.load_model("potatoesV3.h5")
@@ -32,24 +32,36 @@ def classify_image(file):
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
-
37
- # def classify_image(image):
38
- # # Open the image using Pillow
39
- # img = Image.fromarray(image.astype('uint8'), 'RGB')
40
- # new_size = (256, 256)
41
- # img_resized = img.resize(new_size)
42
- # #img_array = np.array(img_resized)
43
- # #img_scaled = img_array / 255.0
44
- # img_array = np.expand_dims(img_resized, axis=0)
45
- # pred = model.predict(img_array)
46
-
47
- # predicted_class = CLASS_NAMES[np.argmax(pred[0])]
48
- # confidence = float(np.max(pred[0]))
49
-
50
- # # Return the predicted class and confidence score
51
- # return {"class": predicted_class, "confidence": confidence,"predict":pred[0]}
52
-
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  examples=[os.path.join(os.path.dirname(__file__),'7227b3db-c212-4370-8b42-443eea1577aa___RS_Early.B 7306.JPG','7456db33-766c-4a68-b924-ddf69d579981___RS_Early.B 6723.JPG','7486e823-64f7-4e43-ab51-26261b077fc2___RS_Early.B 6785.JPG','8829e413-5a7a-4680-b873-e71dfa9dbfe4___RS_LB 3974.JPG','9001b18c-b659-4c56-9dfb-0d0bf64a7b4a___RS_LB 4987.JPG','9009c86e-1205-4694-b0bb-ef7cf78dd104___RS_LB 3995.JPG','Potato_healthy-76-_0_2420.jpg','Potato_healthy-76-_0_6833.jpg','Potato_healthy-76-_0_7539.jpg')]
55
 
 
4
  from PIL import Image
5
  from io import BytesIO
6
  import matplotlib.pyplot as plt
7
+ import os
8
 
9
  # Load the trained TensorFlow model using the Keras API
10
  model = tf.keras.models.load_model("potatoesV3.h5")
 
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)
39
+
40
+ # # Convert the image to a numpy array
41
+ # img_array = np.array(img_resized)
42
+
43
+ # # Rescale the image pixel values to [0, 1]
44
+ # img_scaled = img_array / 255.0
45
+
46
+ # #img_array = np.array(img_scaled)
47
+ # img_array = np.expand_dims(img_scaled, axis=0)
48
+ # pred = model.predict(img_array)
49
+
50
+ # # Display the rescaled image
51
+ # #plt.imshow(img_array)
52
+
53
+ # # Format the predicted class and confidence score
54
+ # predicted_class = CLASS_NAMES[np.argmax(pred[0])]
55
+ # confidence = float(np.max(pred[0]))
56
+
57
+ # # Return the predicted class and confidence score
58
+ # return {"class": predicted_class, "confidence": confidence,"predict":pred[0]}
59
+ # img = (BytesIO(image))
60
+ # img = img.resize((256, 256))
61
+ # img_array = np.array(img)
62
+ # img_array = np.expand_dims(img_array, axis=0)
63
+ # pred = model.predict(img_array)
64
+ # return pred[0][0]
65
 
66
  examples=[os.path.join(os.path.dirname(__file__),'7227b3db-c212-4370-8b42-443eea1577aa___RS_Early.B 7306.JPG','7456db33-766c-4a68-b924-ddf69d579981___RS_Early.B 6723.JPG','7486e823-64f7-4e43-ab51-26261b077fc2___RS_Early.B 6785.JPG','8829e413-5a7a-4680-b873-e71dfa9dbfe4___RS_LB 3974.JPG','9001b18c-b659-4c56-9dfb-0d0bf64a7b4a___RS_LB 4987.JPG','9009c86e-1205-4694-b0bb-ef7cf78dd104___RS_LB 3995.JPG','Potato_healthy-76-_0_2420.jpg','Potato_healthy-76-_0_6833.jpg','Potato_healthy-76-_0_7539.jpg')]
67