Update app.py
Browse files
app.py
CHANGED
@@ -49,25 +49,30 @@ def predict_disease(image):
|
|
49 |
Preprocesses the image, performs prediction, and returns the predicted class with confidence score.
|
50 |
"""
|
51 |
# Resize and preprocess image
|
52 |
-
|
|
|
53 |
img = tf.expand_dims(img, axis=0) # Add batch dimension
|
54 |
|
55 |
# Predict probabilities
|
56 |
-
prediction = model.predict(img)
|
57 |
labels = ['Early Blight', 'Late Blight', 'Healthy']
|
58 |
-
|
59 |
-
#
|
60 |
-
|
61 |
-
confidence = prediction.max()
|
62 |
-
return f"Prediction: {predicted_class}, Confidence: {confidence:.2%}"
|
63 |
|
64 |
# ... (Rest of your code) ...
|
65 |
|
66 |
iface = gr.Interface(
|
67 |
fn=predict_disease,
|
68 |
-
inputs=gr.Image(), #
|
69 |
-
outputs=
|
70 |
-
title="Potato Disease
|
71 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
)
|
73 |
-
iface.launch(share=True)
|
|
|
49 |
Preprocesses the image, performs prediction, and returns the predicted class with confidence score.
|
50 |
"""
|
51 |
# Resize and preprocess image
|
52 |
+
# Resize and preprocess the image
|
53 |
+
img = tf.image.resize(image, [256, 256])
|
54 |
img = tf.expand_dims(img, axis=0) # Add batch dimension
|
55 |
|
56 |
# Predict probabilities
|
57 |
+
prediction = model.predict(img)[0] # Extract first element (batch of size 1)
|
58 |
labels = ['Early Blight', 'Late Blight', 'Healthy']
|
59 |
+
|
60 |
+
# Create a dictionary of class probabilities
|
61 |
+
class_probs = {label: float(prob) for label, prob in zip(labels, prediction)}
|
|
|
|
|
62 |
|
63 |
# ... (Rest of your code) ...
|
64 |
|
65 |
iface = gr.Interface(
|
66 |
fn=predict_disease,
|
67 |
+
inputs=gr.Image(type="numpy", tool="editor"), # Allow image editing
|
68 |
+
outputs=gr.Label(num_top_classes=3), # Display all three probabilities
|
69 |
+
title="Potato Disease Classifier ππ₯",
|
70 |
+
description=(
|
71 |
+
"Upload an image of a potato leaf, and I'll classify it as one of the following:\n"
|
72 |
+
"- **Early Blight** π±\n"
|
73 |
+
"- **Late Blight** π§οΈ\n"
|
74 |
+
"- **Healthy** π\n\n"
|
75 |
+
"Check out the probability bars for more details!"
|
76 |
+
),
|
77 |
)
|
78 |
+
iface.launch(share=True)
|