Deepakbusa commited on
Commit
e5fa0b5
·
verified ·
1 Parent(s): d15f5d7

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +9 -12
  2. app.py +40 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,12 +1,9 @@
1
- ---
2
- title: Waste Classifier
3
- emoji: 📚
4
- colorFrom: blue
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.34.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # ♻️ Live Waste Classifier
2
+
3
+ This app uses a Hugging Face pretrained model (`prithivMLmods/Recycling-Net-11`) to classify real-time webcam images into **Recyclable** and **Non-Recyclable** categories.
4
+
5
+ ## Model Labels
6
+ - **Recyclable**: cardboard, glass, metal, paper, plastic, can, carton
7
+ - **Non-Recyclable**: food waste, trash, garbage, organic
8
+
9
+ Made with 🤗 Hugging Face + Gradio
 
 
 
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoImageProcessor, SiglipForImageClassification
2
+ from PIL import Image
3
+ import torch
4
+ import gradio as gr
5
+
6
+ model_name = "prithivMLmods/Recycling-Net-11"
7
+ processor = AutoImageProcessor.from_pretrained(model_name)
8
+ model = SiglipForImageClassification.from_pretrained(model_name)
9
+
10
+ recyclable_labels = ["cardboard", "glass", "metal", "paper", "plastic", "can", "carton"]
11
+ non_recyclable_labels = ["food waste", "trash", "garbage", "organic"]
12
+
13
+ id2label = model.config.id2label
14
+
15
+ def classify_webcam(image):
16
+ if image is None:
17
+ return "No Image", None
18
+
19
+ inputs = processor(images=image, return_tensors="pt")
20
+ with torch.no_grad():
21
+ logits = model(**inputs).logits
22
+ probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
23
+
24
+ pred_idx = max(range(len(probs)), key=lambda i: probs[i])
25
+ pred_label = id2label[pred_idx].lower()
26
+ label_type = "Recyclable" if any(w in pred_label for w in recyclable_labels) else "Non-Recyclable"
27
+ confidence = f"{probs[pred_idx]*100:.1f}%"
28
+ return f"{label_type} ({pred_label}, {confidence})"
29
+
30
+ demo = gr.Interface(
31
+ fn=classify_webcam,
32
+ inputs=gr.Image(source="webcam", tool="editor", streaming=False),
33
+ outputs="text",
34
+ live=True,
35
+ title="♻️ Live Waste Classifier",
36
+ description="Classifies waste items as Recyclable or Non-Recyclable using a Hugging Face model."
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ Pillow
4
+ gradio