NagashreePai commited on
Commit
3c39f03
·
verified ·
1 Parent(s): a174a2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -10
app.py CHANGED
@@ -36,16 +36,44 @@ model.load_state_dict(filtered_checkpoint, strict=False)
36
  model.to(device)
37
  model.eval()
38
 
39
- # ✅ Correct class names list (ordered by folder names)
40
  class_names = [
41
- "Chinee apple", "Lantana", "Negative", "Parkinsonia", "Parthenium",
42
- "Prickly acacia", "Rubber vine", "Siam weed", "Snake weed",
43
- "Black grass", "Charlock", "Cleavers", "Common Chickweed", "Common Wheat",
44
- "Fat Hen", "Loose Silky-bent", "Maize", "Scentless Mayweed",
45
- "Shepherds purse", "Small-flowered Cranesbill", "Sugar beet",
46
- "Carpetweeds", "Crabgrass", "Eclipta", "Goosegrass", "Morningglory",
47
- "Nutsedge", "PalmerAmaranth", "Pricky Sida", "Purslane", "Ragweed",
48
- "Sicklepod", "SpottedSpurge", "SpurredAnoda", "Swinecress", "Waterhemp"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 as a weed with class-{predicted_class}\nConfidence: {confidence:.2f}%"
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(