wastedetective / app.py
MeghanaM4's picture
actually fix indentation error
13878f1 verified
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
from fastai.vision.all import *
import gradio as gr
learn = load_learner('wastedetective.pkl')
categories = ('Batteries', 'Organic Matter', 'Primary', 'Tertiary', 'Metals')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
def info(type):
if type == 'Primary':
return "Your recyclable type is Primary, which makes up the most recyclable materials. You're in luck, your material can just be put in your curbside blue bin, or wherever you usually recycle."
elif type == 'Tertiary':
return "Tertiary items are the least recyclable materials. These materials may hard to recycle because of residue (such as adhesive or liquid), so make sure to clean your recyclable before you put it curbside. These items are usually used as feedstock (raw material to supply or fuel a machine or industrial process) in a process to make new chemicals and fuels."
elif type == 'Metals':
return "Metals should be transported to your local scrapyard, which, according to your location is at New World Recycling, 1079 E 5th Ave, Columbus, OH."
elif type == 'Organic Matter':
return "Organic Matter! You're in luck, all you have to do to dispose of this is put it outside. Composting is a great way to safely get rid of food products and greatly improves your plants' soil health and enriches its diversity."
elif type == 'Batteries':
return "Batteries can be disposed of in a myriad of ways. Standard AA or AAA dead batteries can be thrown in the trash, but lithium-ion or computer batteries take special care. Visit your local battery disposal center and ensure that your batteries aren't leaking harmful acids."
else:
return "Sorry, we don't recognize that type of recyclable. Go to the Waste Detective page and see what type your trash is!"
with gr.Blocks() as intf:
with gr.Tabs():
with gr.TabItem("Waste Detective"):
gr.Markdown("Upload an image of your recyclable and find out its type!")
with gr.Row():
img_input = gr.Image(type="pil")
label_output = gr.Label(num_top_classes=5)
img_input.change(fn=classify_image, inputs=img_input, outputs=label_output)
with gr.TabItem("Info Center"):
gr.Markdown("Welcome to the Waste Detective Information Center!")
inp = gr.Textbox(placeholder="What type of recyclable did you get?")
out = gr.Textbox(lines=5)
btn = gr.Button("How do I recycle this?")
btn.click(fn=info, inputs=inp, outputs=out)
with gr.TabItem("The Impact of Trash"):
with gr.Accordion("Plastic Bags", False):
gr.Markdown("Over 80 percent of landfills are plastic bags, the largest margin by far. Plastic bags break down into tiny toxic particles that contaminate soil and waterways when they're not recycled properly. They also enter the food chain when animals accidentally ingest them.")
with gr.Accordion("Soda Cans", False):
gr.Markdown("Around 1.3 percent of landfills are cans, and 6,700 thousand cans are made per second. You can reduce waste from cans by using reusable bottles/cups for beverages on-the-go.")
with gr.Accordion("Glass", False):
gr.Markdown("About 31 percent of landfills is glass, and it's one of the more dangerous wastes because it doesn't biodegrade at all. The biodegradation-less nature of glass isn't harmful to our environment, it takes a million years for glass to break down. Instead of being used for something productive, it sits and does nothing.")
with gr.Accordion("Food Waste", False):
gr.Markdown("The EPA estimates that 24 percent of landfills are food waste. When certain types of food are not recycled, it contributes to significant environmental damage because it releases methane, wasting valuable resources that make the food. To reduce your impact, store food properly, make meal plans, use a compost bin for foods that can be composted, or only buy what you need.")
intf.launch()