Spaces:
Sleeping
Sleeping
gradio
Browse files
app.py
CHANGED
|
@@ -1,46 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
categories = ["Recyclable", "Compostable", "Trash", "Harmful"]
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# Compostable: fruits & vegetables
|
| 8 |
-
if ("banana" in desc or "apple" in desc or "fruit" in desc or
|
| 9 |
-
"vegetable" in desc or "vegetables" in desc or "veg" in desc or
|
| 10 |
-
"veg waste" in desc or "food" in desc or "peel" in desc or "leaf" in desc):
|
| 11 |
-
category = "Compostable"
|
| 12 |
-
|
| 13 |
-
# Harmful: medical + batteries
|
| 14 |
-
elif "syringe" in desc or "needle" in desc or "battery" in desc or "cell" in desc:
|
| 15 |
-
category = "Harmful"
|
| 16 |
-
|
| 17 |
-
# Recyclable
|
| 18 |
-
elif "plastic" in desc or "bottle" in desc or "can" in desc or "metal" in desc:
|
| 19 |
-
category = "Recyclable"
|
| 20 |
-
elif "paper" in desc and "greasy" not in desc:
|
| 21 |
-
category = "Recyclable"
|
| 22 |
-
|
| 23 |
-
# Trash
|
| 24 |
-
elif "pizza box" in desc or "styrofoam" in desc or "chip bag" in desc:
|
| 25 |
-
category = "Trash"
|
| 26 |
-
|
| 27 |
-
# Fallback
|
| 28 |
-
else:
|
| 29 |
-
category = random.choice(categories)
|
| 30 |
-
|
| 31 |
-
elif image:
|
| 32 |
-
# Placeholder – replace with ML image model later
|
| 33 |
-
category = random.choice(categories)
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
else:
|
| 36 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
"Recyclable": "♻️ Rinse before recycling. Check local rules for plastics.",
|
| 41 |
-
"Compostable": "🌱 Add to compost bin or green waste collection.",
|
| 42 |
-
"Trash": "🗑️ Not recyclable. Consider reusable alternatives.",
|
| 43 |
-
"Harmful": "⚠️ Special disposal needed. Take syringes, needles, and batteries to hazardous waste collection centers."
|
| 44 |
-
}
|
| 45 |
|
| 46 |
-
return category, tips.get(category, "Check local disposal guidelines.")
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
def classify_waste(waste_item):
|
| 4 |
+
compostable = ["fruit", "vegetable", "vegetables", "food", "paper", "leaves"]
|
| 5 |
+
harmful = ["syringe", "battery", "chemical", "plastic"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
if waste_item.lower() in compostable:
|
| 8 |
+
return "✅ Compostable Waste"
|
| 9 |
+
elif waste_item.lower() in harmful:
|
| 10 |
+
return "⚠️ Harmful & Non-Compostable"
|
| 11 |
else:
|
| 12 |
+
return "♻️ General Waste"
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=classify_waste,
|
| 16 |
+
inputs=gr.Textbox(label="Enter Waste Item"),
|
| 17 |
+
outputs=gr.Label(label="Waste Category"),
|
| 18 |
+
title="Waste Classification App",
|
| 19 |
+
description="Type a waste item (e.g., 'fruit', 'vegetable', 'battery', 'syringe') and get its category."
|
| 20 |
+
)
|
| 21 |
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|