Files changed (2) hide show
  1. classifier.py +29 -3
  2. knowledge_base.py +16 -3
classifier.py CHANGED
@@ -126,7 +126,7 @@ class GarbageClassifier:
126
  {"type": "image", "image": processed_image},
127
  {
128
  "type": "text",
129
- "text": "Please classify the garbage in this image and explain your reasoning.",
130
  },
131
  ],
132
  },
@@ -174,8 +174,33 @@ class GarbageClassifier:
174
  # Convert response to lowercase for matching
175
  response_lower = response.lower()
176
 
177
- # Look for exact category matches first
178
- for category in categories:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  if category.lower() in response_lower:
180
  return category
181
 
@@ -231,6 +256,7 @@ class GarbageClassifier:
231
  if any(keyword in response_lower for keyword in keywords):
232
  return category
233
 
 
234
  return "Unable to classify"
235
 
236
  def _format_response(self, classification: str, full_response: str) -> str:
 
126
  {"type": "image", "image": processed_image},
127
  {
128
  "type": "text",
129
+ "text": "Please classify what you see in this image. If it shows garbage/waste items, classify them according to the garbage classification standards. If it shows people, living things, or other non-waste items, classify it as 'Unable to classify' and explain why it's not garbage.",
130
  },
131
  ],
132
  },
 
174
  # Convert response to lowercase for matching
175
  response_lower = response.lower()
176
 
177
+ # First check for "Unable to classify" indicators
178
+ unable_indicators = [
179
+ "unable to classify",
180
+ "cannot classify",
181
+ "not garbage",
182
+ "not waste",
183
+ "person",
184
+ "people",
185
+ "human",
186
+ "face",
187
+ "living",
188
+ "alive",
189
+ "animal",
190
+ "functioning",
191
+ "in use",
192
+ "working",
193
+ "furniture",
194
+ "appliance",
195
+ "electronic device",
196
+ ]
197
+
198
+ if any(indicator in response_lower for indicator in unable_indicators):
199
+ return "Unable to classify"
200
+
201
+ # Look for exact category matches (excluding "Unable to classify" since we handled it above)
202
+ waste_categories = [cat for cat in categories if cat != "Unable to classify"]
203
+ for category in waste_categories:
204
  if category.lower() in response_lower:
205
  return category
206
 
 
256
  if any(keyword in response_lower for keyword in keywords):
257
  return category
258
 
259
+ # If no clear classification found, default to "Unable to classify"
260
  return "Unable to classify"
261
 
262
  def _format_response(self, classification: str, full_response: str) -> str:
knowledge_base.py CHANGED
@@ -3,6 +3,8 @@ class GarbageClassificationKnowledge:
3
  def get_system_prompt():
4
  return """You are a professional garbage classification expert. You need to carefully observe the items in the picture, analyze their materials, properties and uses, and then make accurate judgments according to garbage classification standards.
5
 
 
 
6
  Garbage classification standards:
7
 
8
  **Recyclable Waste**:
@@ -31,10 +33,19 @@ Garbage classification standards:
31
  - Large bones, hard shells, hard fruit pits (coconut shells, durian shells, walnut shells, corn cobs, etc.)
32
  - Hair, pet waste, cat litter, etc.
33
 
34
- Please observe the items in the image carefully according to the above classification standards, provide accurate garbage classification results, and briefly explain the classification reasoning. Format your response as:
 
 
 
 
 
 
 
 
 
35
 
36
- **Classification**: [Category Name]
37
- **Reasoning**: [Brief explanation of why this item belongs to this category]"""
38
 
39
  @staticmethod
40
  def get_categories():
@@ -43,6 +54,7 @@ Please observe the items in the image carefully according to the above classific
43
  "Food/Kitchen Waste",
44
  "Hazardous Waste",
45
  "Other Waste",
 
46
  ]
47
 
48
  @staticmethod
@@ -52,4 +64,5 @@ Please observe the items in the image carefully according to the above classific
52
  "Food/Kitchen Waste": "Organic waste from food preparation and consumption",
53
  "Hazardous Waste": "Items containing harmful substances that require special disposal",
54
  "Other Waste": "Items that don't fit into other categories and go to general waste",
 
55
  }
 
3
  def get_system_prompt():
4
  return """You are a professional garbage classification expert. You need to carefully observe the items in the picture, analyze their materials, properties and uses, and then make accurate judgments according to garbage classification standards.
5
 
6
+ IMPORTANT: You should ONLY classify items that are actually garbage/waste. If the image contains people, living things, furniture, electronics in use, or other non-waste items, you should classify it as "Unable to classify" and explain that it's not garbage.
7
+
8
  Garbage classification standards:
9
 
10
  **Recyclable Waste**:
 
33
  - Large bones, hard shells, hard fruit pits (coconut shells, durian shells, walnut shells, corn cobs, etc.)
34
  - Hair, pet waste, cat litter, etc.
35
 
36
+ **Unable to classify**:
37
+ - People, human faces, human body parts
38
+ - Living animals, pets
39
+ - Furniture, appliances, electronics in normal use
40
+ - Buildings, landscapes, vehicles
41
+ - Any item that is not intended to be discarded as waste
42
+
43
+ Please observe the items in the image carefully according to the above classification standards. If the image shows garbage/waste items, provide accurate garbage classification results. If the image does NOT show garbage/waste (e.g., people, living things, functioning items), classify it as "Unable to classify" and explain why it's not garbage.
44
+
45
+ Format your response as:
46
 
47
+ **Classification**: [Category Name or "Unable to classify"]
48
+ **Reasoning**: [Brief explanation of why this item belongs to this category, or why it cannot be classified as garbage]"""
49
 
50
  @staticmethod
51
  def get_categories():
 
54
  "Food/Kitchen Waste",
55
  "Hazardous Waste",
56
  "Other Waste",
57
+ "Unable to classify",
58
  ]
59
 
60
  @staticmethod
 
64
  "Food/Kitchen Waste": "Organic waste from food preparation and consumption",
65
  "Hazardous Waste": "Items containing harmful substances that require special disposal",
66
  "Other Waste": "Items that don't fit into other categories and go to general waste",
67
+ "Unable to classify": "Items that are not garbage/waste, such as people, living things, or functioning objects",
68
  }