haxerwddle commited on
Commit
a746dfb
·
1 Parent(s): bf5e7b1

Classifier model change

Browse files
Files changed (1) hide show
  1. app.py +136 -80
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
- waste_analyzation = {
159
- "cardboard": {
160
- "Recycling type": "Paper/Cardboard recycling",
161
- "Disposal": "Flatten the cardboard boxes and remove any non-paper packing materials before placing them in the recycling bin.",
162
- "Tips": "Keep cardboard dry and clean to ensure it can be recycled efficiently.",
163
- "Extra": "Avoid using waxed or heavily coated cardboard, as it may not be recyclable."
 
 
 
 
 
 
164
  },
165
  "glass": {
166
  "Recycling type": "Glass recycling",
167
- "Disposal": "Rinse glass bottles and jars, remove lids, and place them in a dedicated glass recycling container.",
168
- "Tips": "Avoid breaking the glass; broken pieces can be hazardous and may complicate processing.",
169
- "Extra": "Colored glass is often recycled separately; check local recycling rules."
170
  },
171
  "metal": {
172
  "Recycling type": "Metal recycling",
173
- "Disposal": "Rinse aluminum cans and steel containers, remove labels if possible, and put them in the metal recycling bin.",
174
- "Tips": "Crush cans to save space and facilitate transport.",
175
- "Extra": "Avoid contaminating with food waste to improve recycling efficiency."
176
  },
177
- "paper": {
178
- "Recycling type": "Paper recycling",
179
- "Disposal": "Sort newspapers, office paper, and magazines into the paper recycling bin; remove plastic coatings and staples.",
180
- "Tips": "Shred sensitive documents but keep shredded paper in a bag to avoid scattering.",
181
- "Extra": "Do not recycle wet or food-stained paper."
182
  },
183
- "plastic": {
184
- "Recycling type": "Plastic recycling",
185
- "Disposal": "Rinse plastic bottles, containers, and packaging, and place them in the plastic recycling bin.",
186
- "Tips": "Check recycling codes; some plastics (like #3 PVC) are not widely recyclable.",
187
- "Extra": "Remove caps and labels when possible to improve sorting efficiency."
 
 
 
 
 
 
 
 
 
 
 
 
188
  },
189
- "trash": {
190
  "Recycling type": "General waste / landfill",
191
- "Disposal": "Place non-recyclable items in the regular trash bin; avoid mixing with recyclables.",
192
- "Tips": "Separate hazardous materials like batteries, electronics, or chemicals for special disposal.",
193
- "Extra": "Try to reduce overall waste by reusing and composting when possible."
194
  }
195
  }
 
196
  waste_analyzation_v2 = {
197
- "cardboard": {
198
- "Recycling type": "Paper/Cardboard recycling",
199
- "Disposal": "Fold or cut cardboard into smaller flat pieces so it fits properly in recycling bins.",
200
- "Tips": "Keep cardboard free from oils or food stains to avoid contaminating the batch.",
201
- "Extra": "Cardboard with shiny or laminated surfaces may need separate processing."
 
 
 
 
 
 
202
  },
203
  "glass": {
204
  "Recycling type": "Glass recycling",
205
- "Disposal": "Remove lids and caps, lightly rinse, and place glass containers into the glass-only bin.",
206
- "Tips": "Do not place broken drinking glasses or ceramics with recyclable glass—they melt at different temperatures.",
207
- "Extra": "Some regions require taking glass to drop-off centers instead of curbside bins."
208
  },
209
  "metal": {
210
  "Recycling type": "Metal recycling",
211
- "Disposal": "Empty metal containers and place them in the metal bin; labels may stay on.",
212
- "Tips": "Keep metal separate from electronics or batteries, which require special facilities.",
213
- "Extra": "Large metal objects like appliances may require bulk recycling pickup."
214
  },
215
- "paper": {
216
- "Recycling type": "Paper recycling",
217
- "Disposal": "Place clean, dry paper products such as envelopes and notebooks into paper bins.",
218
- "Tips": "Do not recycle coated paper (e.g., laminated or plastic-lined pages).",
219
- "Extra": "Paper with heavy ink coverage might be processed separately."
220
  },
221
- "plastic": {
222
- "Recycling type": "Plastic recycling",
223
- "Disposal": "Clean and drain plastic bottles or tubs, then place them in the plastics bin.",
224
- "Tips": "Flatten plastic bottles to reduce volume unless your local guidelines say otherwise.",
225
- "Extra": "Some plastics like polystyrene foam require special drop-off locations."
226
  },
227
- "trash": {
228
- "Recycling type": "General waste / landfill",
229
- "Disposal": "Dispose of unrecyclable materials in regular waste; secure loose items in bags.",
230
- "Tips": "Separate hazardous or toxic waste like paint, solvents, or chemicals.",
231
- "Extra": "Reduce landfill impact by choosing reusable products whenever possible."
 
 
 
 
 
 
 
 
 
 
 
 
232
  }
233
  }
 
234
  waste_analyzation_v3 = {
235
- "cardboard": {
236
- "Recycling type": "Paper/Cardboard recycling",
237
- "Disposal": "Remove packing tape when possible and place cardboard in dry storage until pickup day.",
238
- "Tips": "Avoid leaving cardboard outdoors where rain could weaken fibers and ruin recyclability.",
239
- "Extra": "Food-contaminated cardboard can often be composted instead of recycled."
 
 
 
 
 
 
240
  },
241
  "glass": {
242
  "Recycling type": "Glass recycling",
243
- "Disposal": "Sort by color only if required locally; rinse lightly and drop into the proper bin.",
244
- "Tips": "Handle carefully to avoid breakage, as shattered glass is often not recyclable in curbside programs.",
245
- "Extra": "Glass jars with metal clasps or rubber seals may need partial disassembly before recycling."
246
  },
247
  "metal": {
248
  "Recycling type": "Metal recycling",
249
- "Disposal": "Ensure metal food cans are clean and empty before placing in the recycling bin.",
250
- "Tips": "Rinse cans briefly—no need for perfect cleaning—as this prevents pests and odors.",
251
- "Extra": "Metal lids from jars should be recycled separately from the glass container."
252
  },
253
- "paper": {
254
- "Recycling type": "Paper recycling",
255
- "Disposal": "Place paper in the appropriate bin; keep shredded paper in a paper bag if accepted.",
256
- "Tips": "Avoid mixing paper with wet waste like food scraps to maintain recyclability.",
257
- "Extra": "Sticky notes and small scraps may or may not be accepted depending on the facility."
258
  },
259
- "plastic": {
260
- "Recycling type": "Plastic recycling",
261
- "Disposal": "Recycle only plastics accepted by your local program; rinse and drain them completely.",
262
- "Tips": "Avoid recycling small plastic pieces under 2 inches—they may jam sorting machinery.",
263
- "Extra": "Hard-to-recycle plastics may be collected through special community programs."
264
  },
265
- "trash": {
266
- "Recycling type": "General waste / landfill",
267
- "Disposal": "Place all non-recyclables in the trash bin; tie bags securely to avoid leakage.",
268
- "Tips": "Do not place batteries, electronics, or sharp objects directly into household trash.",
269
- "Extra": "Consider composting organic waste to reduce household trash volume."
 
 
 
 
 
 
 
 
 
 
 
 
270
  }
271
  }
272
- analysis = [waste_analyzation_v3, waste_analyzation_v2, waste_analyzation]
 
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