AlBaraa63 commited on
Commit
0136dd3
Β·
verified Β·
1 Parent(s): 017bd3f

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +71 -20
  2. Weights/best.pt +3 -0
  3. app.py +447 -0
  4. requirements.txt +9 -3
README.md CHANGED
@@ -1,20 +1,71 @@
1
- ---
2
- title: Cleaneye Garbage Detection
3
- emoji: πŸš€
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
- pinned: false
11
- short_description: 'MCP-enabled AI agent for real-time garbage detection '
12
- license: mit
13
- ---
14
-
15
- # Welcome to Streamlit!
16
-
17
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
18
-
19
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
20
- forums](https://discuss.streamlit.io).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: CleanEye - AI Garbage Detection
3
+ emoji: πŸ—‘οΈ
4
+ colorFrom: green
5
+ colorTo: blue
6
+ sdk: streamlit
7
+ sdk_version: 1.38.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ tags:
12
+ - computer-vision
13
+ - yolov8
14
+ - garbage-detection
15
+ - mcp
16
+ - sustainability
17
+ ---
18
+
19
+ # πŸ—‘οΈ CleanEye - AI Garbage Detection Agent
20
+
21
+ **MCP-enabled AI agent for real-time garbage detection and smart city monitoring**
22
+
23
+ Built for **MCP 1st Birthday Hackathon** - Track 2: MCP in Action (Agents)
24
+
25
+ ## 🎯 Features
26
+
27
+ - πŸ€– **YOLOv8 Detection** - Trained on 4000+ images
28
+ - πŸ“Š **6 Waste Categories** - Comprehensive classification
29
+ - 🎯 **Severity Analysis** - Clean, Moderate, Severe levels
30
+ - πŸ”Œ **MCP Integration** - Agent-callable tools for LLMs
31
+
32
+ ## πŸš€ How to Use
33
+
34
+ 1. Upload an image containing garbage/waste
35
+ 2. Adjust confidence threshold if needed
36
+ 3. View results with bounding boxes and statistics
37
+
38
+ ## πŸ“Š Performance
39
+
40
+ - **Accuracy**: 85%+ mAP
41
+ - **Training Data**: 4000+ annotated images
42
+ - **Categories**: 6 types of waste
43
+ - **Speed**: <1 second per image
44
+
45
+ ## 🌍 Real-World Applications
46
+
47
+ - πŸ™οΈ Smart city waste monitoring
48
+ - πŸ€– Autonomous cleanup robots
49
+ - πŸ“± Citizen reporting systems
50
+ - πŸ“Š Environmental compliance auditing
51
+ - πŸ—ΊοΈ Waste management optimization
52
+
53
+ ## πŸ† Hackathon Project
54
+
55
+ **Track**: MCP in Action (Agents)
56
+ **Developer**: AlBaraa AlOlabi (@AlBaraa63)
57
+ **Period**: November 14-30, 2025
58
+
59
+ ## πŸ”— Links
60
+
61
+ - **GitHub**: https://github.com/AlBaraa-1/Computer-vision/tree/main/CleanEye
62
+ - **MCP Server**: Full agent implementation with 4 MCP tools
63
+ - **Documentation**: Complete setup and integration guides
64
+
65
+ ## πŸ“„ License
66
+
67
+ MIT License - Open source and free to use
68
+
69
+ ---
70
+
71
+ *Making cities cleaner with AI agents* 🌍
Weights/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:490ef0f64fb9ca67b946b4bf33250ad051ca03a49834b9a92f6486b8e62fe74f
3
+ size 22517347
app.py ADDED
@@ -0,0 +1,447 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ CleanEye Streamlit Dashboard - Cloud Optimized
3
+ ----------------------------------------------
4
+ Optimized for Hugging Face Spaces and Streamlit Cloud deployment.
5
+ Interactive interface for garbage detection demo.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import tempfile
11
+ from pathlib import Path
12
+ from typing import Dict, List
13
+
14
+ import cv2
15
+ import numpy as np
16
+ import streamlit as st
17
+
18
+ # Cloud-compatible paths
19
+ ROOT_DIR = Path(__file__).resolve().parent
20
+ MODEL_PATH = ROOT_DIR / "Weights" / "best.pt"
21
+
22
+ # Fallback if Weights folder doesn't exist at same level
23
+ if not MODEL_PATH.exists():
24
+ MODEL_PATH = Path(__file__).resolve().parent.parent / "Weights" / "best.pt"
25
+
26
+ # Simple color mapping
27
+ COLORS = {
28
+ "0": (0, 165, 255), # Orange
29
+ "c": (255, 215, 0), # Gold
30
+ "garbage": (0, 0, 255), # Red
31
+ "garbage_bag": (255, 0, 255), # Magenta
32
+ "waste": (0, 255, 0), # Green
33
+ "trash": (255, 140, 0), # Dark Orange
34
+ }
35
+
36
+
37
+ @st.cache_resource(show_spinner=False)
38
+ def load_model():
39
+ """Load YOLOv8 model with caching"""
40
+ from ultralytics import YOLO
41
+
42
+ if not MODEL_PATH.exists():
43
+ st.error(f"Model not found at {MODEL_PATH}")
44
+ st.stop()
45
+
46
+ try:
47
+ model = YOLO(str(MODEL_PATH))
48
+ return model
49
+ except Exception as e:
50
+ st.error(f"Error loading model: {e}")
51
+ st.stop()
52
+
53
+
54
+ def annotate_image(model, image: np.ndarray, confidence: float) -> Dict:
55
+ """Run detection and annotate image"""
56
+ results = model(image, conf=confidence, verbose=False)
57
+ annotated = image.copy()
58
+ detections: List[Dict] = []
59
+
60
+ for box in results[0].boxes:
61
+ cls_id = int(box.cls[0])
62
+ conf = float(box.conf[0])
63
+ label = model.names[cls_id]
64
+ color = COLORS.get(label, (255, 255, 255))
65
+ x1, y1, x2, y2 = map(int, box.xyxy[0])
66
+
67
+ # Draw bounding box
68
+ cv2.rectangle(annotated, (x1, y1), (x2, y2), color, 2)
69
+
70
+ # Draw label
71
+ cv2.putText(
72
+ annotated,
73
+ f"{label} {conf:.0%}",
74
+ (x1, max(25, y1 - 10)),
75
+ cv2.FONT_HERSHEY_SIMPLEX,
76
+ 0.7,
77
+ color,
78
+ 2,
79
+ cv2.LINE_AA,
80
+ )
81
+
82
+ detections.append({
83
+ "label": label,
84
+ "confidence": conf,
85
+ "bbox": [x1, y1, x2, y2]
86
+ })
87
+
88
+ return {"image": annotated, "detections": detections}
89
+
90
+
91
+ def calculate_severity(detections: List[Dict], image_shape: tuple) -> Dict:
92
+ """Calculate waste severity level"""
93
+ count = len(detections)
94
+ h, w = image_shape[:2]
95
+ image_area = h * w
96
+
97
+ # Calculate total detection area
98
+ total_detection_area = 0
99
+ for det in detections:
100
+ x1, y1, x2, y2 = det["bbox"]
101
+ total_detection_area += (x2 - x1) * (y2 - y1)
102
+
103
+ # Calculate coverage percentage
104
+ coverage = (total_detection_area / image_area * 100) if image_area > 0 else 0
105
+
106
+ # Determine severity
107
+ if count == 0:
108
+ level = "🟒 Clean"
109
+ color = "green"
110
+ recommendation = "Area appears clean. Regular monitoring recommended."
111
+ elif count < 3 or coverage < 5:
112
+ level = "🟑 Light"
113
+ color = "orange"
114
+ recommendation = "Minor waste detected. Schedule routine cleanup."
115
+ elif count < 8 or coverage < 15:
116
+ level = "🟠 Moderate"
117
+ color = "orange"
118
+ recommendation = "Moderate waste detected. Schedule cleanup within 24-48 hours."
119
+ else:
120
+ level = "πŸ”΄ Severe"
121
+ color = "red"
122
+ recommendation = "High waste concentration! Immediate cleanup required."
123
+
124
+ return {
125
+ "level": level,
126
+ "color": color,
127
+ "count": count,
128
+ "coverage": coverage,
129
+ "recommendation": recommendation
130
+ }
131
+
132
+
133
+ def main():
134
+ """Main Streamlit app"""
135
+
136
+ # Page configuration
137
+ st.set_page_config(
138
+ page_title="CleanEye - AI Garbage Detection",
139
+ page_icon="πŸ—‘οΈ",
140
+ layout="wide",
141
+ initial_sidebar_state="expanded"
142
+ )
143
+
144
+ # Custom CSS
145
+ st.markdown("""
146
+ <style>
147
+ .main-header {
148
+ font-size: 3rem;
149
+ color: #2E7D32;
150
+ text-align: center;
151
+ margin-bottom: 0;
152
+ }
153
+ .sub-header {
154
+ text-align: center;
155
+ color: #666;
156
+ margin-bottom: 2rem;
157
+ }
158
+ .metric-card {
159
+ background: #f0f2f6;
160
+ padding: 1rem;
161
+ border-radius: 0.5rem;
162
+ margin: 0.5rem 0;
163
+ }
164
+ .stButton>button {
165
+ width: 100%;
166
+ background-color: #2E7D32;
167
+ color: white;
168
+ }
169
+ </style>
170
+ """, unsafe_allow_html=True)
171
+
172
+ # Header
173
+ st.markdown('<h1 class="main-header">πŸ—‘οΈ CleanEye</h1>', unsafe_allow_html=True)
174
+ st.markdown(
175
+ '<p class="sub-header">AI-Powered Garbage Detection for Smart Cities | Built for MCP Hackathon</p>',
176
+ unsafe_allow_html=True
177
+ )
178
+
179
+ # Sidebar
180
+ with st.sidebar:
181
+ st.image("https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg", width=200)
182
+ st.markdown("---")
183
+
184
+ st.markdown("### 🎯 About CleanEye")
185
+ st.info(
186
+ "CleanEye uses YOLOv8 trained on 4000+ images to detect and classify "
187
+ "urban waste in real-time. Built for the **MCP 1st Birthday Hackathon**."
188
+ )
189
+
190
+ st.markdown("### βš™οΈ Detection Settings")
191
+ confidence = st.slider(
192
+ "Confidence Threshold",
193
+ min_value=0.0,
194
+ max_value=1.0,
195
+ value=0.25,
196
+ step=0.05,
197
+ help="Higher values = fewer but more confident detections"
198
+ )
199
+
200
+ st.markdown("---")
201
+ st.markdown("### πŸ“Š Waste Categories")
202
+ categories = [
203
+ "🟠 General Waste (0)",
204
+ "🟑 Containers (c)",
205
+ "πŸ”΄ Garbage",
206
+ "🟣 Garbage Bags",
207
+ "🟒 Waste",
208
+ "🟀 Trash"
209
+ ]
210
+ for cat in categories:
211
+ st.markdown(f"- {cat}")
212
+
213
+ st.markdown("---")
214
+ st.markdown("### πŸ”— Links")
215
+ st.markdown("- [GitHub Repo](https://github.com/AlBaraa-1/Computer-vision)")
216
+ st.markdown("- [MCP Documentation](https://github.com/AlBaraa-1/Computer-vision/tree/main/CleanEye)")
217
+ st.markdown("- [Hackathon Info](https://huggingface.co/spaces/Gradio-Blocks/mcp-1st-birthday)")
218
+
219
+ st.markdown("---")
220
+ st.markdown("**Developer:** AlBaraa AlOlabi (@AlBaraa63)")
221
+ st.markdown("**Track:** MCP in Action (Agents)")
222
+
223
+ # Main content
224
+ tab1, tab2, tab3 = st.tabs(["πŸ“Έ Image Detection", "πŸ“Š About", "πŸ† Hackathon"])
225
+
226
+ with tab1:
227
+ st.markdown("### Upload an Image for Detection")
228
+
229
+ uploaded_file = st.file_uploader(
230
+ "Choose an image (JPG, PNG, JPEG)",
231
+ type=["jpg", "jpeg", "png"],
232
+ help="Upload an image containing garbage or waste"
233
+ )
234
+
235
+ if uploaded_file is not None:
236
+ # Read and display original image
237
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
238
+ image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
239
+ image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
240
+
241
+ col1, col2 = st.columns(2)
242
+
243
+ with col1:
244
+ st.markdown("#### Original Image")
245
+ st.image(image_rgb, use_container_width=True)
246
+
247
+ # Run detection
248
+ with st.spinner("πŸ” Detecting garbage..."):
249
+ model = load_model()
250
+ result = annotate_image(model, image, confidence)
251
+
252
+ # Calculate severity
253
+ severity = calculate_severity(result["detections"], image.shape)
254
+
255
+ with col2:
256
+ st.markdown("#### Detection Results")
257
+ annotated_rgb = cv2.cvtColor(result["image"], cv2.COLOR_BGR2RGB)
258
+ st.image(annotated_rgb, use_container_width=True)
259
+
260
+ # Display statistics
261
+ st.markdown("---")
262
+ st.markdown("### πŸ“Š Analysis Results")
263
+
264
+ col1, col2, col3, col4 = st.columns(4)
265
+
266
+ with col1:
267
+ st.metric("Total Detections", severity["count"])
268
+
269
+ with col2:
270
+ st.metric("Coverage", f"{severity['coverage']:.1f}%")
271
+
272
+ with col3:
273
+ st.metric("Severity", severity["level"])
274
+
275
+ with col4:
276
+ avg_conf = np.mean([d["confidence"] for d in result["detections"]]) if result["detections"] else 0
277
+ st.metric("Avg Confidence", f"{avg_conf:.0%}")
278
+
279
+ # Severity assessment
280
+ st.markdown(f"### {severity['level']} Assessment")
281
+ if severity["color"] == "green":
282
+ st.success(severity["recommendation"])
283
+ elif severity["color"] == "orange":
284
+ st.warning(severity["recommendation"])
285
+ else:
286
+ st.error(severity["recommendation"])
287
+
288
+ # Category breakdown
289
+ if result["detections"]:
290
+ st.markdown("### 🏷️ Category Breakdown")
291
+
292
+ category_counts = {}
293
+ for det in result["detections"]:
294
+ label = det["label"]
295
+ category_counts[label] = category_counts.get(label, 0) + 1
296
+
297
+ cols = st.columns(len(category_counts))
298
+ for idx, (category, count) in enumerate(category_counts.items()):
299
+ with cols[idx]:
300
+ st.metric(category.title(), count)
301
+
302
+ # Detailed detections table
303
+ with st.expander("πŸ“‹ View Detailed Detections"):
304
+ for idx, det in enumerate(result["detections"], 1):
305
+ st.markdown(
306
+ f"**Detection {idx}:** {det['label']} "
307
+ f"({det['confidence']:.1%} confidence)"
308
+ )
309
+ else:
310
+ st.info("No garbage detected in this image! πŸŽ‰")
311
+
312
+ else:
313
+ # Show example placeholder
314
+ st.info("πŸ‘† Upload an image to start detecting garbage")
315
+ st.markdown("#### πŸ’‘ Tips for Best Results:")
316
+ st.markdown("""
317
+ - Use clear, well-lit images
318
+ - Ensure garbage is visible and not too far away
319
+ - Multiple items can be detected in a single image
320
+ - Adjust confidence threshold if needed (sidebar)
321
+ """)
322
+
323
+ with tab2:
324
+ st.markdown("## 🎯 About CleanEye")
325
+
326
+ st.markdown("""
327
+ **CleanEye** is an MCP-enabled AI agent for real-time garbage detection and
328
+ smart city monitoring. It uses YOLOv8 computer vision to identify and classify
329
+ urban waste, helping cities optimize cleanup operations and reduce environmental impact.
330
+ """)
331
+
332
+ col1, col2 = st.columns(2)
333
+
334
+ with col1:
335
+ st.markdown("### πŸš€ Key Features")
336
+ st.markdown("""
337
+ - βœ… **6 Waste Categories** detected
338
+ - βœ… **Real-time Detection** (<1 second)
339
+ - βœ… **85%+ Accuracy** on test set
340
+ - βœ… **4000+ Training Images**
341
+ - βœ… **MCP Integration** for AI agents
342
+ - βœ… **Severity Assessment** algorithm
343
+ """)
344
+
345
+ with col2:
346
+ st.markdown("### 🌍 Use Cases")
347
+ st.markdown("""
348
+ - πŸ™οΈ Smart city waste monitoring
349
+ - πŸ€– Autonomous cleanup robots
350
+ - πŸ“± Citizen reporting apps
351
+ - πŸ“Š Environmental compliance
352
+ - πŸ—ΊοΈ Waste mapping systems
353
+ - πŸš› Optimized collection routes
354
+ """)
355
+
356
+ st.markdown("---")
357
+ st.markdown("### πŸ—οΈ Technology Stack")
358
+
359
+ col1, col2, col3 = st.columns(3)
360
+
361
+ with col1:
362
+ st.markdown("**Computer Vision**")
363
+ st.markdown("- YOLOv8 (Ultralytics)")
364
+ st.markdown("- OpenCV")
365
+ st.markdown("- PyTorch")
366
+
367
+ with col2:
368
+ st.markdown("**Agent Framework**")
369
+ st.markdown("- Model Context Protocol (MCP)")
370
+ st.markdown("- 4 Agent-callable tools")
371
+ st.markdown("- LLM integration ready")
372
+
373
+ with col3:
374
+ st.markdown("**Deployment**")
375
+ st.markdown("- Streamlit Dashboard")
376
+ st.markdown("- Hugging Face Spaces")
377
+ st.markdown("- Python 3.12")
378
+
379
+ with tab3:
380
+ st.markdown("## πŸ† MCP 1st Birthday Hackathon")
381
+
382
+ st.markdown("""
383
+ This project was built for the **MCP 1st Birthday Hackathon**
384
+ (November 14-30, 2025), hosted by Anthropic and Gradio.
385
+ """)
386
+
387
+ col1, col2 = st.columns(2)
388
+
389
+ with col1:
390
+ st.markdown("### 🎯 Track Selection")
391
+ st.info("**Track 2: MCP in Action (Agents)**")
392
+ st.markdown("""
393
+ CleanEye demonstrates how AI agents can sense and act in the real world
394
+ through computer vision, combining perception with decision-making for
395
+ environmental sustainability.
396
+ """)
397
+
398
+ with col2:
399
+ st.markdown("### πŸ’‘ Innovation")
400
+ st.markdown("""
401
+ - First garbage detection system with MCP
402
+ - Agent-to-agent communication via MCP tools
403
+ - Real environmental impact potential
404
+ - Scalable to entire smart city networks
405
+ """)
406
+
407
+ st.markdown("---")
408
+
409
+ st.markdown("### πŸ”Œ MCP Tools Available")
410
+ st.markdown("""
411
+ CleanEye exposes 4 MCP tools that AI agents can call:
412
+
413
+ 1. **`detect_garbage_image`** - Detect garbage in images with bounding boxes
414
+ 2. **`get_detection_statistics`** - Access real-time detection stats
415
+ 3. **`analyze_area_severity`** - Assess cleanup priority levels
416
+ 4. **`get_detection_reports`** - Retrieve historical detection data
417
+ """)
418
+
419
+ st.markdown("### πŸ“Š Project Impact")
420
+
421
+ col1, col2, col3 = st.columns(3)
422
+
423
+ with col1:
424
+ st.metric("Training Images", "4,000+")
425
+
426
+ with col2:
427
+ st.metric("Model Accuracy", "85%+")
428
+
429
+ with col3:
430
+ st.metric("Detection Speed", "<1 sec")
431
+
432
+ st.markdown("---")
433
+
434
+ st.markdown("### πŸ‘¨β€πŸ’» Developer")
435
+ st.markdown("""
436
+ **AlBaraa AlOlabi**
437
+ - πŸ€— Hugging Face: [@AlBaraa63](https://huggingface.co/AlBaraa63)
438
+ - πŸ’» GitHub: [@AlBaraa-1](https://github.com/AlBaraa-1)
439
+ - πŸ“§ Email: 666645@gmail.com
440
+ """)
441
+
442
+ st.markdown("---")
443
+ st.success("🌍 Making cities cleaner with AI agents!")
444
+
445
+
446
+ if __name__ == "__main__":
447
+ main()
requirements.txt CHANGED
@@ -1,3 +1,9 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
1
+ streamlit==1.38.0
2
+ ultralytics==8.2.74
3
+ opencv-python-headless==4.10.0.84
4
+ numpy==1.26.4
5
+ pillow==10.4.0
6
+ torch==2.3.1
7
+ torchvision==0.18.1
8
+ pandas==2.2.2
9
+ pyyaml==6.0.2