Aarzoo-Singh2206 commited on
Commit
404f355
Β·
verified Β·
1 Parent(s): a4e8179

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -23
app.py CHANGED
@@ -3,18 +3,11 @@ import tensorflow as tf
3
  from tensorflow.keras.applications.efficientnet import preprocess_input
4
  from tensorflow.keras.preprocessing import image
5
  import numpy as np
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",
@@ -37,29 +30,20 @@ def predict_disease(img):
37
  label = CLASS_NAMES[top_idx]
38
  return f"{label} ({confidence:.2f}%)"
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 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
-
 
3
  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",
 
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"]
 
 
43
  ],
44
+ cache_examples=False,
45
+ allow_flagging="never"
46
  )
47
 
 
48
  if __name__ == "__main__":
49
  interface.launch()