Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,16 +36,44 @@ model.load_state_dict(filtered_checkpoint, strict=False)
|
|
| 36 |
model.to(device)
|
| 37 |
model.eval()
|
| 38 |
|
| 39 |
-
# ✅
|
| 40 |
class_names = [
|
| 41 |
-
"Chinee apple",
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
"
|
| 45 |
-
"
|
| 46 |
-
"
|
| 47 |
-
"
|
| 48 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
]
|
| 50 |
|
| 51 |
# 🔁 Image transform
|
|
@@ -70,7 +98,7 @@ def predict(img):
|
|
| 70 |
if predicted_class.lower() == "negative":
|
| 71 |
return f"⚠️ This image is predicted as Negative.\nConfidence: {confidence:.2f}%"
|
| 72 |
|
| 73 |
-
return f"✅ Predicted
|
| 74 |
|
| 75 |
# 🎨 Gradio Interface
|
| 76 |
interface = gr.Interface(
|
|
|
|
| 36 |
model.to(device)
|
| 37 |
model.eval()
|
| 38 |
|
| 39 |
+
# ✅ class_names mapped according to confusion matrix order
|
| 40 |
class_names = [
|
| 41 |
+
"Chinee apple", # class1
|
| 42 |
+
"Common Wheat", # class14
|
| 43 |
+
"Fat Hen", # class15
|
| 44 |
+
"Loose Silky-bent", # class16
|
| 45 |
+
"Maize", # class17
|
| 46 |
+
"Scentless Mayweed", # class18
|
| 47 |
+
"Shepherds purse", # class19
|
| 48 |
+
"Lantana", # class2
|
| 49 |
+
"Small-flowered Cranesbill",# class20
|
| 50 |
+
"Sugar beet", # class21
|
| 51 |
+
"Carpetweeds", # class22
|
| 52 |
+
"Crabgrass", # class23
|
| 53 |
+
"Eclipta", # class24
|
| 54 |
+
"Goosegrass", # class25
|
| 55 |
+
"Morningglory", # class26
|
| 56 |
+
"Nutsedge", # class27
|
| 57 |
+
"PalmerAmaranth", # class28
|
| 58 |
+
"Pricky Sida", # class29
|
| 59 |
+
"Negative", # class3
|
| 60 |
+
"Purslane", # class30
|
| 61 |
+
"Ragweed", # class31
|
| 62 |
+
"Sicklepod", # class32
|
| 63 |
+
"SpottedSpurge", # class33
|
| 64 |
+
"SpurredAnoda", # class34
|
| 65 |
+
"Swinecress", # class35
|
| 66 |
+
"Waterhemp", # class36
|
| 67 |
+
"Parkinsonia", # class4
|
| 68 |
+
"Parthenium", # class5
|
| 69 |
+
"Prickly acacia", # class6
|
| 70 |
+
"Rubber vine", # class7
|
| 71 |
+
"Siam weed", # class8
|
| 72 |
+
"Snake weed", # class9
|
| 73 |
+
"Black grass", # class10
|
| 74 |
+
"Charlock", # class11
|
| 75 |
+
"Cleavers", # class12
|
| 76 |
+
"Common Chickweed" # class13
|
| 77 |
]
|
| 78 |
|
| 79 |
# 🔁 Image transform
|
|
|
|
| 98 |
if predicted_class.lower() == "negative":
|
| 99 |
return f"⚠️ This image is predicted as Negative.\nConfidence: {confidence:.2f}%"
|
| 100 |
|
| 101 |
+
return f"✅ Predicted class: {predicted_class}\nConfidence: {confidence:.2f}%"
|
| 102 |
|
| 103 |
# 🎨 Gradio Interface
|
| 104 |
interface = gr.Interface(
|