File size: 1,837 Bytes
3c7a8b5
 
 
 
 
e34f818
f533d30
3c7a8b5
 
f533d30
3c7a8b5
 
 
 
 
 
 
 
 
 
f533d30
3c7a8b5
f533d30
3c7a8b5
 
 
 
f533d30
 
3c7a8b5
f533d30
 
3c7a8b5
 
 
f533d30
 
 
3c7a8b5
f533d30
3c7a8b5
 
 
 
e34f818
f533d30
3c7a8b5
404f355
 
ab2be80
404f355
 
3c7a8b5
 
f533d30
3c7a8b5
f533d30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import tensorflow as tf
from tensorflow.keras.applications.efficientnet import preprocess_input
from tensorflow.keras.preprocessing import image
import numpy as np

# Load trained model
model = tf.keras.models.load_model("efficientnet_final_model.keras")

# Class labels
CLASS_NAMES = [
    "Pomegranate__diseased", "mango_Sooty Mould", "mango_Powdery Mildew", 
    "mango_Healthy", "mango_Gall Midge", "mango_Die Back", 
    "mango_Cutting Weevil", "mango_Bacterial Canker", "mango_Anthracnose",
    "guava_Healthy", "guava_Red Rust", "guava_Sooty Mould", 
    "guava_Algal Leaf Spot", "guava_Rust", "lime_Greening", 
    "lime_Canker", "lime_Healthy", "lime_Die Back", 
    "lime_Scab", "lime_Anthracnose", "lime_Sooty Mould"
]

# Predict function
def predict_disease(img):
    print("๐Ÿ–ผ๏ธ Image received")
    img = img.resize((160, 160))
    img_array = image.img_to_array(img)
    img_array = preprocess_input(img_array)
    img_array = np.expand_dims(img_array, axis=0)
    
    print(f"๐Ÿ“Š Model input shape: {img_array.shape}")
    prediction = model.predict(img_array)[0]
    print(f"๐Ÿ”ฎ Raw prediction: {prediction}")
    
    top_idx = np.argmax(prediction)
    confidence = prediction[top_idx] * 100
    label = CLASS_NAMES[top_idx]
    result = f"{label} ({confidence:.2f}%)"
    print(f"โœ… Final Result: {result}")
    return result

# Gradio interface
interface = gr.Interface(
    fn=predict_disease,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="๐ŸŒฟ Fruit Leaf Disease Classifier",
    description="Upload a fruit or leaf image to predict its disease type.",
    examples=[
        ["Phytopthora.jpg"],
        ["RedRust.jpg"]
    ],
    cache_examples=False,
    allow_flagging="never"
)

# Launch with share link
if __name__ == "__main__":
    interface.launch(share=True)