Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
# π
|
| 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
|
| 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
|
| 47 |
-
allow_flagging="never"
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
# πΌοΈ Show image examples using Gradio v4+ Examples class
|
| 51 |
-
interface.examples = gr.Examples(
|
| 52 |
examples=[
|
| 53 |
-
["
|
| 54 |
-
["
|
| 55 |
-
["examples/20211231_162315 (Custom).jpg"],
|
| 56 |
-
["examples/0021_0060.jpg"]
|
| 57 |
],
|
| 58 |
-
|
| 59 |
-
|
| 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()
|
|
|