Spaces:
Sleeping
Sleeping
Commit ·
a746dfb
1
Parent(s): bf5e7b1
Classifier model change
Browse files
app.py
CHANGED
|
@@ -52,7 +52,6 @@ def classify_image(image):
|
|
| 52 |
all_prompts = []
|
| 53 |
prompt_to_category = {}
|
| 54 |
|
| 55 |
-
# Build prompt list
|
| 56 |
for category, prompts in CLIP_LABELS.items():
|
| 57 |
for p in prompts:
|
| 58 |
all_prompts.append(p)
|
|
@@ -155,121 +154,178 @@ def explain_recycling(class_label):
|
|
| 155 |
|
| 156 |
|
| 157 |
# ------------------ PIPELINE ------------------
|
| 158 |
-
|
| 159 |
-
"cardboard": {
|
| 160 |
-
"Recycling type": "Paper
|
| 161 |
-
"Disposal": "Flatten
|
| 162 |
-
"Tips": "
|
| 163 |
-
"Extra": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
},
|
| 165 |
"glass": {
|
| 166 |
"Recycling type": "Glass recycling",
|
| 167 |
-
"Disposal": "Rinse glass bottles and jars
|
| 168 |
-
"Tips": "
|
| 169 |
-
"Extra": "
|
| 170 |
},
|
| 171 |
"metal": {
|
| 172 |
"Recycling type": "Metal recycling",
|
| 173 |
-
"Disposal": "
|
| 174 |
-
"Tips": "
|
| 175 |
-
"Extra": "
|
| 176 |
},
|
| 177 |
-
"
|
| 178 |
-
"Recycling type": "
|
| 179 |
-
"Disposal": "
|
| 180 |
-
"Tips": "
|
| 181 |
-
"Extra": "
|
| 182 |
},
|
| 183 |
-
"
|
| 184 |
-
"Recycling type": "
|
| 185 |
-
"Disposal": "
|
| 186 |
-
"Tips": "
|
| 187 |
-
"Extra": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
},
|
| 189 |
-
"trash": {
|
| 190 |
"Recycling type": "General waste / landfill",
|
| 191 |
-
"Disposal": "
|
| 192 |
-
"Tips": "
|
| 193 |
-
"Extra": "
|
| 194 |
}
|
| 195 |
}
|
|
|
|
| 196 |
waste_analyzation_v2 = {
|
| 197 |
-
"cardboard": {
|
| 198 |
-
"Recycling type": "Paper
|
| 199 |
-
"Disposal": "
|
| 200 |
-
"Tips": "Keep
|
| 201 |
-
"Extra": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
},
|
| 203 |
"glass": {
|
| 204 |
"Recycling type": "Glass recycling",
|
| 205 |
-
"Disposal": "
|
| 206 |
-
"Tips": "
|
| 207 |
-
"Extra": "
|
| 208 |
},
|
| 209 |
"metal": {
|
| 210 |
"Recycling type": "Metal recycling",
|
| 211 |
-
"Disposal": "
|
| 212 |
-
"Tips": "
|
| 213 |
-
"Extra": "Large metal
|
| 214 |
},
|
| 215 |
-
"
|
| 216 |
-
"Recycling type": "
|
| 217 |
-
"Disposal": "
|
| 218 |
-
"Tips": "
|
| 219 |
-
"Extra": "
|
| 220 |
},
|
| 221 |
-
"
|
| 222 |
-
"Recycling type": "
|
| 223 |
-
"Disposal": "
|
| 224 |
-
"Tips": "
|
| 225 |
-
"Extra": "
|
| 226 |
},
|
| 227 |
-
"
|
| 228 |
-
"Recycling type": "
|
| 229 |
-
"Disposal": "
|
| 230 |
-
"Tips": "
|
| 231 |
-
"Extra": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
}
|
| 233 |
}
|
|
|
|
| 234 |
waste_analyzation_v3 = {
|
| 235 |
-
"cardboard": {
|
| 236 |
-
"Recycling type": "Paper
|
| 237 |
-
"Disposal": "
|
| 238 |
-
"Tips": "Avoid
|
| 239 |
-
"Extra": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
},
|
| 241 |
"glass": {
|
| 242 |
"Recycling type": "Glass recycling",
|
| 243 |
-
"Disposal": "
|
| 244 |
-
"Tips": "
|
| 245 |
-
"Extra": "Glass
|
| 246 |
},
|
| 247 |
"metal": {
|
| 248 |
"Recycling type": "Metal recycling",
|
| 249 |
-
"Disposal": "
|
| 250 |
-
"Tips": "
|
| 251 |
-
"Extra": "Metal
|
| 252 |
},
|
| 253 |
-
"
|
| 254 |
-
"Recycling type": "
|
| 255 |
-
"Disposal": "Place
|
| 256 |
-
"Tips": "Avoid
|
| 257 |
-
"Extra": "
|
| 258 |
},
|
| 259 |
-
"
|
| 260 |
-
"Recycling type": "
|
| 261 |
-
"Disposal": "
|
| 262 |
-
"Tips": "
|
| 263 |
-
"Extra": "
|
| 264 |
},
|
| 265 |
-
"
|
| 266 |
-
"Recycling type": "
|
| 267 |
-
"Disposal": "
|
| 268 |
-
"Tips": "
|
| 269 |
-
"Extra": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
}
|
| 271 |
}
|
| 272 |
-
|
|
|
|
| 273 |
|
| 274 |
top_label = None
|
| 275 |
|
|
|
|
| 52 |
all_prompts = []
|
| 53 |
prompt_to_category = {}
|
| 54 |
|
|
|
|
| 55 |
for category, prompts in CLIP_LABELS.items():
|
| 56 |
for p in prompts:
|
| 57 |
all_prompts.append(p)
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
# ------------------ PIPELINE ------------------
|
| 157 |
+
waste_analyzation_v1 = {
|
| 158 |
+
"paper/cardboard": {
|
| 159 |
+
"Recycling type": "Paper & Cardboard recycling",
|
| 160 |
+
"Disposal": "Flatten boxes and place clean paper or cardboard into the paper recycling bin.",
|
| 161 |
+
"Tips": "Remove tape, staples, and plastic covers before recycling.",
|
| 162 |
+
"Extra": "Wet or food-stained paper should not be recycled."
|
| 163 |
+
},
|
| 164 |
+
"plastic": {
|
| 165 |
+
"Recycling type": "Plastic recycling",
|
| 166 |
+
"Disposal": "Rinse plastic containers and place accepted plastics into the recycling bin.",
|
| 167 |
+
"Tips": "Check the recycling code on the plastic item.",
|
| 168 |
+
"Extra": "Soft plastics may require special drop-off locations."
|
| 169 |
},
|
| 170 |
"glass": {
|
| 171 |
"Recycling type": "Glass recycling",
|
| 172 |
+
"Disposal": "Rinse glass bottles and jars and place them in the glass recycling container.",
|
| 173 |
+
"Tips": "Remove lids and caps before disposal.",
|
| 174 |
+
"Extra": "Broken glass may not be accepted in curbside programs."
|
| 175 |
},
|
| 176 |
"metal": {
|
| 177 |
"Recycling type": "Metal recycling",
|
| 178 |
+
"Disposal": "Clean aluminum cans and metal containers before recycling.",
|
| 179 |
+
"Tips": "Crushing cans helps save space.",
|
| 180 |
+
"Extra": "Do not include batteries or electronics."
|
| 181 |
},
|
| 182 |
+
"organic waste": {
|
| 183 |
+
"Recycling type": "Organic / compost waste",
|
| 184 |
+
"Disposal": "Place food scraps and organic matter into compost or organic waste bins.",
|
| 185 |
+
"Tips": "Avoid mixing organic waste with plastics.",
|
| 186 |
+
"Extra": "Composting reduces landfill emissions."
|
| 187 |
},
|
| 188 |
+
"hazardous waste": {
|
| 189 |
+
"Recycling type": "Hazardous waste",
|
| 190 |
+
"Disposal": "Take batteries and chemicals to designated hazardous waste facilities.",
|
| 191 |
+
"Tips": "Never place hazardous items in regular trash.",
|
| 192 |
+
"Extra": "Improper disposal can cause fires or pollution."
|
| 193 |
+
},
|
| 194 |
+
"electronic waste": {
|
| 195 |
+
"Recycling type": "Electronic waste recycling",
|
| 196 |
+
"Disposal": "Drop off electronic devices at certified e-waste centers.",
|
| 197 |
+
"Tips": "Remove batteries if possible before disposal.",
|
| 198 |
+
"Extra": "Many electronics contain recyclable metals."
|
| 199 |
+
},
|
| 200 |
+
"textile": {
|
| 201 |
+
"Recycling type": "Textile recycling",
|
| 202 |
+
"Disposal": "Donate usable clothing or place textiles in textile recycling bins.",
|
| 203 |
+
"Tips": "Clean items before donation or recycling.",
|
| 204 |
+
"Extra": "Damaged textiles may be repurposed into insulation."
|
| 205 |
},
|
| 206 |
+
"general trash": {
|
| 207 |
"Recycling type": "General waste / landfill",
|
| 208 |
+
"Disposal": "Dispose of non-recyclable items in regular trash bins.",
|
| 209 |
+
"Tips": "Avoid mixing recyclables with trash.",
|
| 210 |
+
"Extra": "Reducing waste helps the environment."
|
| 211 |
}
|
| 212 |
}
|
| 213 |
+
|
| 214 |
waste_analyzation_v2 = {
|
| 215 |
+
"paper/cardboard": {
|
| 216 |
+
"Recycling type": "Paper recycling",
|
| 217 |
+
"Disposal": "Place dry paper and cardboard into the paper recycling container.",
|
| 218 |
+
"Tips": "Keep paper clean and dry.",
|
| 219 |
+
"Extra": "Pizza boxes with grease stains should go to trash or compost."
|
| 220 |
+
},
|
| 221 |
+
"plastic": {
|
| 222 |
+
"Recycling type": "Plastic recycling",
|
| 223 |
+
"Disposal": "Sort plastics by type and recycle accepted items.",
|
| 224 |
+
"Tips": "Remove food residue before recycling.",
|
| 225 |
+
"Extra": "Some plastics cannot be recycled curbside."
|
| 226 |
},
|
| 227 |
"glass": {
|
| 228 |
"Recycling type": "Glass recycling",
|
| 229 |
+
"Disposal": "Recycle bottles and jars after rinsing.",
|
| 230 |
+
"Tips": "Avoid mixing ceramics with glass.",
|
| 231 |
+
"Extra": "Glass can be recycled indefinitely."
|
| 232 |
},
|
| 233 |
"metal": {
|
| 234 |
"Recycling type": "Metal recycling",
|
| 235 |
+
"Disposal": "Recycle metal cans and containers once cleaned.",
|
| 236 |
+
"Tips": "Steel and aluminum are both recyclable.",
|
| 237 |
+
"Extra": "Large metal items may need special pickup."
|
| 238 |
},
|
| 239 |
+
"organic waste": {
|
| 240 |
+
"Recycling type": "Compostable waste",
|
| 241 |
+
"Disposal": "Dispose of organic materials in compost bins.",
|
| 242 |
+
"Tips": "Cut large food scraps into smaller pieces.",
|
| 243 |
+
"Extra": "Composting improves soil quality."
|
| 244 |
},
|
| 245 |
+
"hazardous waste": {
|
| 246 |
+
"Recycling type": "Hazardous materials disposal",
|
| 247 |
+
"Disposal": "Bring hazardous items to approved collection points.",
|
| 248 |
+
"Tips": "Store batteries safely before disposal.",
|
| 249 |
+
"Extra": "Never burn or crush batteries."
|
| 250 |
},
|
| 251 |
+
"electronic waste": {
|
| 252 |
+
"Recycling type": "E-waste recycling",
|
| 253 |
+
"Disposal": "Recycle electronics through authorized recyclers.",
|
| 254 |
+
"Tips": "Back up and wipe data before disposal.",
|
| 255 |
+
"Extra": "E-waste contains valuable recoverable materials."
|
| 256 |
+
},
|
| 257 |
+
"textile": {
|
| 258 |
+
"Recycling type": "Clothing & textile recycling",
|
| 259 |
+
"Disposal": "Donate or recycle unwanted clothes responsibly.",
|
| 260 |
+
"Tips": "Separate wearable and damaged items.",
|
| 261 |
+
"Extra": "Textiles can be reused or downcycled."
|
| 262 |
+
},
|
| 263 |
+
"general trash": {
|
| 264 |
+
"Recycling type": "Landfill waste",
|
| 265 |
+
"Disposal": "Throw away items that cannot be recycled.",
|
| 266 |
+
"Tips": "Reduce waste whenever possible.",
|
| 267 |
+
"Extra": "Landfills should be a last resort."
|
| 268 |
}
|
| 269 |
}
|
| 270 |
+
|
| 271 |
waste_analyzation_v3 = {
|
| 272 |
+
"paper/cardboard": {
|
| 273 |
+
"Recycling type": "Paper & cardboard recycling",
|
| 274 |
+
"Disposal": "Recycle clean paper-based materials.",
|
| 275 |
+
"Tips": "Avoid recycling paper mixed with plastic.",
|
| 276 |
+
"Extra": "Paper fibers can only be recycled a few times."
|
| 277 |
+
},
|
| 278 |
+
"plastic": {
|
| 279 |
+
"Recycling type": "Plastic recycling",
|
| 280 |
+
"Disposal": "Recycle only plastics accepted locally.",
|
| 281 |
+
"Tips": "Flatten bottles to save space.",
|
| 282 |
+
"Extra": "Plastic recycling rules vary by region."
|
| 283 |
},
|
| 284 |
"glass": {
|
| 285 |
"Recycling type": "Glass recycling",
|
| 286 |
+
"Disposal": "Recycle glass containers after rinsing.",
|
| 287 |
+
"Tips": "Sort by color if required.",
|
| 288 |
+
"Extra": "Glass recycling saves raw materials."
|
| 289 |
},
|
| 290 |
"metal": {
|
| 291 |
"Recycling type": "Metal recycling",
|
| 292 |
+
"Disposal": "Recycle clean metal containers.",
|
| 293 |
+
"Tips": "Do not include pressurized containers.",
|
| 294 |
+
"Extra": "Metal recycling saves energy."
|
| 295 |
},
|
| 296 |
+
"organic waste": {
|
| 297 |
+
"Recycling type": "Organic waste composting",
|
| 298 |
+
"Disposal": "Place biodegradable waste into compost bins.",
|
| 299 |
+
"Tips": "Avoid adding oils or meat if not accepted.",
|
| 300 |
+
"Extra": "Organic waste can be turned into fertilizer."
|
| 301 |
},
|
| 302 |
+
"hazardous waste": {
|
| 303 |
+
"Recycling type": "Hazardous waste handling",
|
| 304 |
+
"Disposal": "Dispose of hazardous items at certified facilities.",
|
| 305 |
+
"Tips": "Handle with care and keep away from heat.",
|
| 306 |
+
"Extra": "Improper disposal poses health risks."
|
| 307 |
},
|
| 308 |
+
"electronic waste": {
|
| 309 |
+
"Recycling type": "Electronic recycling",
|
| 310 |
+
"Disposal": "Recycle electronic devices properly.",
|
| 311 |
+
"Tips": "Check local e-waste programs.",
|
| 312 |
+
"Extra": "E-waste contains toxic substances."
|
| 313 |
+
},
|
| 314 |
+
"textile": {
|
| 315 |
+
"Recycling type": "Textile reuse & recycling",
|
| 316 |
+
"Disposal": "Donate or recycle textiles responsibly.",
|
| 317 |
+
"Tips": "Reuse clothing whenever possible.",
|
| 318 |
+
"Extra": "Fast fashion contributes to waste."
|
| 319 |
+
},
|
| 320 |
+
"general trash": {
|
| 321 |
+
"Recycling type": "General disposal",
|
| 322 |
+
"Disposal": "Dispose of non-recyclables in trash.",
|
| 323 |
+
"Tips": "Sort waste correctly before disposal.",
|
| 324 |
+
"Extra": "Reducing waste helps the planet."
|
| 325 |
}
|
| 326 |
}
|
| 327 |
+
|
| 328 |
+
analysis = [waste_analyzation_v3, waste_analyzation_v2, waste_analyzation_v1]
|
| 329 |
|
| 330 |
top_label = None
|
| 331 |
|