Aarzoo-Singh2206 commited on
Commit
4747019
Β·
verified Β·
1 Parent(s): bc255c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -6,15 +6,15 @@ import numpy as np
6
  import zipfile
7
  import os
8
 
9
- # πŸ”“ Unzip examples.zip if not already extracted
10
  if not os.path.exists("examples") and os.path.exists("examples.zip"):
11
  with zipfile.ZipFile("examples.zip", 'r') as zip_ref:
12
  zip_ref.extractall("examples")
13
 
14
- # 🧠 Load trained model
15
  model = tf.keras.models.load_model("efficientnet_final_model.keras")
16
 
17
- # πŸƒ Class names
18
  CLASS_NAMES = [
19
  "Pomegranate__diseased", "mango_Sooty Mould", "mango_Powdery Mildew",
20
  "mango_Healthy", "mango_Gall Midge", "mango_Die Back",
@@ -31,12 +31,10 @@ def predict_disease(img):
31
  img_array = image.img_to_array(img)
32
  img_array = preprocess_input(img_array)
33
  img_array = np.expand_dims(img_array, axis=0)
34
-
35
  prediction = model.predict(img_array)[0]
36
  top_idx = np.argmax(prediction)
37
  confidence = prediction[top_idx] * 100
38
  label = CLASS_NAMES[top_idx]
39
-
40
  return f"{label} ({confidence:.2f}%)"
41
 
42
  # πŸŽ›οΈ Gradio Interface
@@ -45,16 +43,23 @@ interface = gr.Interface(
45
  inputs=gr.Image(type="pil"),
46
  outputs="text",
47
  title="🌿 Fruit Leaf Disease Classifier",
48
- description="Upload a fruit or leaf image to predict its disease type.",
 
 
 
 
 
49
  examples=[
50
- ["examples/Phytopthora.jpg"],
51
- ["examples/RedRust.jpg"],
52
- ["examples/HealthyMangoLeaf.jpg"],
53
- ["examples/LimeLeafSpotted.jpg"]
54
  ],
55
- cache_examples=False # βœ… Fixes caching issue on Hugging Face
 
56
  )
57
 
 
58
  if __name__ == "__main__":
59
  interface.launch()
60
 
 
6
  import zipfile
7
  import os
8
 
9
+ # πŸ”“ Automatically unzip example images if needed
10
  if not os.path.exists("examples") and os.path.exists("examples.zip"):
11
  with zipfile.ZipFile("examples.zip", 'r') as zip_ref:
12
  zip_ref.extractall("examples")
13
 
14
+ # 🧠 Load model
15
  model = tf.keras.models.load_model("efficientnet_final_model.keras")
16
 
17
+ # πŸƒ Disease class labels
18
  CLASS_NAMES = [
19
  "Pomegranate__diseased", "mango_Sooty Mould", "mango_Powdery Mildew",
20
  "mango_Healthy", "mango_Gall Midge", "mango_Die Back",
 
31
  img_array = image.img_to_array(img)
32
  img_array = preprocess_input(img_array)
33
  img_array = np.expand_dims(img_array, axis=0)
 
34
  prediction = model.predict(img_array)[0]
35
  top_idx = np.argmax(prediction)
36
  confidence = prediction[top_idx] * 100
37
  label = CLASS_NAMES[top_idx]
 
38
  return f"{label} ({confidence:.2f}%)"
39
 
40
  # πŸŽ›οΈ Gradio Interface
 
43
  inputs=gr.Image(type="pil"),
44
  outputs="text",
45
  title="🌿 Fruit Leaf Disease Classifier",
46
+ description="Upload an image of a fruit or leaf to detect its disease type.",
47
+ allow_flagging="never"
48
+ )
49
+
50
+ # πŸ–ΌοΈ Show image examples using Gradio v4+ Examples class
51
+ interface.examples = gr.Examples(
52
  examples=[
53
+ ["examples/Phytopthora (97).jpg"],
54
+ ["examples/Red Rust(60).jpg"],
55
+ ["examples/20211231_162315 (Custom).jpg"],
56
+ ["examples/0021_0060.jpg"]
57
  ],
58
+ inputs=interface.input_components,
59
+ cache_examples=False
60
  )
61
 
62
+ # πŸš€ Launch the app
63
  if __name__ == "__main__":
64
  interface.launch()
65