Aarzoo-Singh2206 commited on
Commit
f533d30
ยท
verified ยท
1 Parent(s): 404f355

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -4,10 +4,10 @@ from tensorflow.keras.applications.efficientnet import preprocess_input
4
  from tensorflow.keras.preprocessing import image
5
  import numpy as np
6
 
7
- # ๐Ÿง  Load model
8
  model = tf.keras.models.load_model("efficientnet_final_model.keras")
9
 
10
- # ๐Ÿƒ Class names
11
  CLASS_NAMES = [
12
  "Pomegranate__diseased", "mango_Sooty Mould", "mango_Powdery Mildew",
13
  "mango_Healthy", "mango_Gall Midge", "mango_Die Back",
@@ -18,25 +18,32 @@ CLASS_NAMES = [
18
  "lime_Scab", "lime_Anthracnose", "lime_Sooty Mould"
19
  ]
20
 
21
- # ๐Ÿ” Prediction function
22
  def predict_disease(img):
 
23
  img = img.resize((160, 160))
24
  img_array = image.img_to_array(img)
25
  img_array = preprocess_input(img_array)
26
  img_array = np.expand_dims(img_array, axis=0)
 
 
27
  prediction = model.predict(img_array)[0]
 
 
28
  top_idx = np.argmax(prediction)
29
  confidence = prediction[top_idx] * 100
30
  label = CLASS_NAMES[top_idx]
31
- return f"{label} ({confidence:.2f}%)"
 
 
32
 
33
- # ๐ŸŽ›๏ธ Gradio interface
34
  interface = gr.Interface(
35
  fn=predict_disease,
36
  inputs=gr.Image(type="pil"),
37
  outputs="text",
38
  title="๐ŸŒฟ Fruit Leaf Disease Classifier",
39
- description="Upload a fruit or leaf image to identify the disease.",
40
  examples=[
41
  ["Phytopthora.jpg"],
42
  ["RedRust.jpg"]
@@ -45,5 +52,6 @@ interface = gr.Interface(
45
  allow_flagging="never"
46
  )
47
 
 
48
  if __name__ == "__main__":
49
- interface.launch()
 
4
  from tensorflow.keras.preprocessing import image
5
  import numpy as np
6
 
7
+ # Load trained model
8
  model = tf.keras.models.load_model("efficientnet_final_model.keras")
9
 
10
+ # Class labels
11
  CLASS_NAMES = [
12
  "Pomegranate__diseased", "mango_Sooty Mould", "mango_Powdery Mildew",
13
  "mango_Healthy", "mango_Gall Midge", "mango_Die Back",
 
18
  "lime_Scab", "lime_Anthracnose", "lime_Sooty Mould"
19
  ]
20
 
21
+ # Predict function
22
  def predict_disease(img):
23
+ print("๐Ÿ–ผ๏ธ Image received")
24
  img = img.resize((160, 160))
25
  img_array = image.img_to_array(img)
26
  img_array = preprocess_input(img_array)
27
  img_array = np.expand_dims(img_array, axis=0)
28
+
29
+ print(f"๐Ÿ“Š Model input shape: {img_array.shape}")
30
  prediction = model.predict(img_array)[0]
31
+ print(f"๐Ÿ”ฎ Raw prediction: {prediction}")
32
+
33
  top_idx = np.argmax(prediction)
34
  confidence = prediction[top_idx] * 100
35
  label = CLASS_NAMES[top_idx]
36
+ result = f"{label} ({confidence:.2f}%)"
37
+ print(f"โœ… Final Result: {result}")
38
+ return result
39
 
40
+ # Gradio interface
41
  interface = gr.Interface(
42
  fn=predict_disease,
43
  inputs=gr.Image(type="pil"),
44
  outputs="text",
45
  title="๐ŸŒฟ Fruit Leaf Disease Classifier",
46
+ description="Upload a fruit or leaf image to predict its disease type.",
47
  examples=[
48
  ["Phytopthora.jpg"],
49
  ["RedRust.jpg"]
 
52
  allow_flagging="never"
53
  )
54
 
55
+ # Launch with share link
56
  if __name__ == "__main__":
57
+ interface.launch(share=True)