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 share = True 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))) image = "image" label = "label" modelIntf = gr.Interface(fn=classify_image, inputs = image, outputs = label) 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 infoBlock: gr.Markdown("Welcome to the Waste Detective Information Center!") with gr.Row(): inp = gr.Textbox(placeholder = "What type of recyclable did you get?") out = gr.Textbox() btn = gr.Button("How do I recycle this?") btn.click(fn = info, inputs = inp, outputs = out) with gr.Blocks() as impact: 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 that 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, which could lead to increasing the cost of food production. To reduce your impact, store food properly, make meal plans, use a compost bin for foods that can be composed, or only buy what you need.") intf = gr.TabbedInterface([modelIntf, infoBlock, impact], ["Waste Detective", "Info Center", "The Impact of Trash"], "Waste Detective", "ocean") intf.launch(inline = False, share = True)