Spaces:
Sleeping
Sleeping
gradio
Browse files



app.py
CHANGED
|
@@ -1,15 +1,16 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
# Categories
|
| 4 |
compostable = ["vegetable", "fruit", "food", "leaves"]
|
| 5 |
recyclable = ["plastic", "paper", "glass", "metal", "bottle", "can"]
|
| 6 |
harmful = ["syringe", "battery", "medical", "chemical"]
|
| 7 |
|
| 8 |
-
# Bin images
|
| 9 |
bin_images = {
|
| 10 |
-
"Compostable": "stock-vector-bin-recycle-plastic-green-wheelie-bin-for-waste-isolated-on-white-background-green-bin-with-1306559440.jpg",
|
| 11 |
-
"Recyclable": "blue-recycling-bin-with-recycle-symbol-for-waste-management-and-sustainability-png.png",
|
| 12 |
-
"Harmful": "medical-waste-bin.jpeg"
|
| 13 |
}
|
| 14 |
|
| 15 |
def classify_waste(item):
|
|
@@ -21,14 +22,14 @@ def classify_waste(item):
|
|
| 21 |
elif item in harmful:
|
| 22 |
return "⚠️ Harmful/Non-Decomposable Waste", bin_images["Harmful"]
|
| 23 |
else:
|
| 24 |
-
#
|
| 25 |
return "✅ Compostable Waste", bin_images["Compostable"]
|
| 26 |
|
| 27 |
# Gradio UI
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=classify_waste,
|
| 30 |
inputs="text",
|
| 31 |
-
outputs=["text", "
|
| 32 |
title="♻️ Eco-Friendly Waste Classifier",
|
| 33 |
description="Enter a waste item (e.g., vegetable, plastic, syringe) and see which bin it belongs to!"
|
| 34 |
)
|
|
@@ -36,3 +37,4 @@ iface = gr.Interface(
|
|
| 36 |
if __name__ == "__main__":
|
| 37 |
iface.launch()
|
| 38 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
|
| 4 |
# Categories
|
| 5 |
compostable = ["vegetable", "fruit", "food", "leaves"]
|
| 6 |
recyclable = ["plastic", "paper", "glass", "metal", "bottle", "can"]
|
| 7 |
harmful = ["syringe", "battery", "medical", "chemical"]
|
| 8 |
|
| 9 |
+
# Bin images stored in 'bins/' folder
|
| 10 |
bin_images = {
|
| 11 |
+
"Compostable": "bins/stock-vector-bin-recycle-plastic-green-wheelie-bin-for-waste-isolated-on-white-background-green-bin-with-1306559440.jpg",
|
| 12 |
+
"Recyclable": "bins/blue-recycling-bin-with-recycle-symbol-for-waste-management-and-sustainability-png.png",
|
| 13 |
+
"Harmful": "bins/medical-waste-bin.jpeg"
|
| 14 |
}
|
| 15 |
|
| 16 |
def classify_waste(item):
|
|
|
|
| 22 |
elif item in harmful:
|
| 23 |
return "⚠️ Harmful/Non-Decomposable Waste", bin_images["Harmful"]
|
| 24 |
else:
|
| 25 |
+
# Unknown items treated as compostable
|
| 26 |
return "✅ Compostable Waste", bin_images["Compostable"]
|
| 27 |
|
| 28 |
# Gradio UI
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=classify_waste,
|
| 31 |
inputs="text",
|
| 32 |
+
outputs=["text", gr.Image(type="auto")], # Make sure output type is an image
|
| 33 |
title="♻️ Eco-Friendly Waste Classifier",
|
| 34 |
description="Enter a waste item (e.g., vegetable, plastic, syringe) and see which bin it belongs to!"
|
| 35 |
)
|
|
|
|
| 37 |
if __name__ == "__main__":
|
| 38 |
iface.launch()
|
| 39 |
|
| 40 |
+
|