aniket-manhas commited on
Commit
1a1e641
·
1 Parent(s): 545cf41

first commit

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +39 -0
  3. plant_disease_classifier.keras +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ plant_disease_classifier.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ from tensorflow.keras import models
5
+ from tensorflow.keras.applications.efficientnet import preprocess_input
6
+
7
+ # Step 1: Load the entire model (no need to manually load weights)
8
+ model = models.load_model("plant_disease_classifier.keras") # Load the saved model directly
9
+
10
+ # Step 2: Define class names in the correct order
11
+ class_names = ['Early Blight', 'Late Blight', 'Healthy'] # Ensure this matches the training order
12
+
13
+ # Step 3: Define prediction function
14
+ def predict(image: Image.Image):
15
+ image = image.convert("RGB")
16
+ image = image.resize((256, 256))
17
+ image_array = np.array(image, dtype=np.float32)
18
+ image_array = np.expand_dims(image_array, axis=0)
19
+ image_array = preprocess_input(image_array)
20
+
21
+ predictions = model.predict(image_array)
22
+ predicted_index = np.argmax(predictions)
23
+ confidence = float(predictions[0][predicted_index]) * 100
24
+ predicted_class = class_names[predicted_index]
25
+
26
+ return {predicted_class: confidence}
27
+
28
+ # Step 4: Define Gradio interface
29
+ interface = gr.Interface(
30
+ fn=predict,
31
+ inputs=gr.Image(type="pil"),
32
+ outputs=gr.Label(num_top_classes=3),
33
+ title="Plant Disease Classifier",
34
+ description="Upload an image of a plant leaf to identify the disease."
35
+ )
36
+
37
+ # Step 5: Launch the app
38
+ if __name__ == "__main__":
39
+ interface.launch()
plant_disease_classifier.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2799cf634baa82b2f16db4beef66dfd57d3f4b0b2ba0fd5e1563df7f4c202b98
3
+ size 47916878