Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,18 @@ 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
model = tf.keras.models.load_model("efficientnet_final_model.keras")
|
| 8 |
|
|
|
|
| 9 |
CLASS_NAMES = [
|
| 10 |
"Pomegranate__diseased", "mango_Sooty Mould", "mango_Powdery Mildew",
|
| 11 |
"mango_Healthy", "mango_Gall Midge", "mango_Die Back",
|
|
@@ -16,6 +25,7 @@ CLASS_NAMES = [
|
|
| 16 |
"lime_Scab", "lime_Anthracnose", "lime_Sooty Mould"
|
| 17 |
]
|
| 18 |
|
|
|
|
| 19 |
def predict_disease(img):
|
| 20 |
img = img.resize((160, 160))
|
| 21 |
img_array = image.img_to_array(img)
|
|
@@ -29,12 +39,13 @@ def predict_disease(img):
|
|
| 29 |
|
| 30 |
return f"{label} ({confidence:.2f}%)"
|
| 31 |
|
|
|
|
| 32 |
interface = gr.Interface(
|
| 33 |
fn=predict_disease,
|
| 34 |
inputs=gr.Image(type="pil"),
|
| 35 |
outputs="text",
|
| 36 |
-
title="Fruit Leaf Disease Classifier
|
| 37 |
-
description="Upload
|
| 38 |
examples=[
|
| 39 |
["examples/Phytopthora.jpg"],
|
| 40 |
["examples/RedRust.jpg"],
|
|
|
|
| 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 |
+
# π 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",
|
|
|
|
| 25 |
"lime_Scab", "lime_Anthracnose", "lime_Sooty Mould"
|
| 26 |
]
|
| 27 |
|
| 28 |
+
# π Prediction function
|
| 29 |
def predict_disease(img):
|
| 30 |
img = img.resize((160, 160))
|
| 31 |
img_array = image.img_to_array(img)
|
|
|
|
| 39 |
|
| 40 |
return f"{label} ({confidence:.2f}%)"
|
| 41 |
|
| 42 |
+
# ποΈ Gradio Interface
|
| 43 |
interface = gr.Interface(
|
| 44 |
fn=predict_disease,
|
| 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"],
|