Spaces:
Sleeping
Sleeping
File size: 18,640 Bytes
3d0817d 9c546da 3d0817d 9c546da 3d0817d 60e56c1 3d0817d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
import streamlit as st
import os
"""
# Welcome to Streamlit!
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).
In the meantime, below is an example of what you can do with just a few lines of code:
"""
# โ
MUST be the very first Streamlit call
st.set_page_config(
page_title="SmartVision",
layout="wide",
page_icon="๐๏ธ"
)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# HERO WITH IMAGE
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown(
"""
<div style="
background: linear-gradient(135deg, #0f172a, #111827);
border-radius: 18px;
padding: 30px 30px 40px 30px;
margin-bottom: 28px;
text-align: center;
">
""",
unsafe_allow_html=True,
)
# โ
FIX 1: Use forward slash (works on Linux/Mac/Windows)
# image_path = "models/smartvision.png"
import os
APP_ROOT = "/app"
image_path = os.path.join(APP_ROOT, "models", "smartvision.png")
# โ
FIX 2: Check if file exists before loading to give a clear error
if os.path.exists(image_path):
st.image(image_path, use_container_width=True)
else:
st.warning(f"โ ๏ธ Image not found at `{image_path}`. Please ensure the file is committed to your repository.")
st.markdown(
"""
<div style="margin-top:20px;">
<p style="font-size:16px; color:#9ca3af; margin:0;">
Unified Image Classification & Object Detection Platform
</p>
<p style="font-size:13px; color:#6b7280; margin-top:10px;">
25-Class COCO ยท YOLOv8 ยท VGG16 ยท ResNet50 ยท MobileNetV2 ยท EfficientNetB0
</p>
</div>
</div>
""",
unsafe_allow_html=True,
)
st.info("๐ Use the **sidebar** to navigate between pages.")
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SECTION 1 โ TOP STATS
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("### ๐ Platform Overview")
c1, c2, c3, c4, c5 = st.columns(5)
stats = [
("๐ฏ Classes", "25", "#2ecc71"),
("๐ง CNN Models", "4", "#3498db"),
("๐ Detection", "YOLOv8s", "#f39c12"),
("๐ฆ Dataset", "COCO", "#9b59b6"),
("โ๏ธ Deployment", "HF Spaces", "#1abc9c"),
]
for col, (label, val, color) in zip([c1, c2, c3, c4, c5], stats):
with col:
st.markdown(
f"""<div style="
border:2px solid {color}55; border-radius:12px;
padding:16px 10px; text-align:center; background:{color}0d;
">
<p style="font-size:11px;color:#888;margin:0;font-weight:600;
letter-spacing:1px;text-transform:uppercase;">{label}</p>
<p style="font-size:20px;font-weight:800;color:{color};margin:6px 0 0;">{val}</p>
</div>""",
unsafe_allow_html=True,
)
st.divider()
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SECTION 2 โ KEY FEATURES
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("### ๐ Key Features")
feat_col1, feat_col2 = st.columns(2)
features_left = [
("๐ผ๏ธ", "Single-object image classification", "Upload any image โ all 4 CNNs classify it simultaneously with Top-5 predictions."),
("๐ฆ", "Multi-object detection with bounding boxes","YOLOv8 detects and localises multiple objects in a single frame."),
("๐จ", "Color-coded per-class visualisation", "Each of 25 classes has a unique bounding box color for instant recognition."),
]
features_right = [
("๐", "Interactive performance dashboard", "Live charts, confusion matrices, training curves, and per-class mAP breakdown."),
("๐ท", "Live webcam detection", "Real-time YOLOv8 inference on webcam feed with FPS overlay (local only)."),
]
for col, feats in zip([feat_col1, feat_col2], [features_left, features_right]):
with col:
for icon, title, desc in feats:
st.markdown(
f"""<div style="
display:flex; gap:12px; padding:12px 14px;
border:1.5px solid #dee2e6; border-radius:10px;
margin-bottom:10px; background:#fafbfc;
">
<span style="font-size:22px;flex-shrink:0;">{icon}</span>
<div>
<p style="font-size:13px;font-weight:700;margin:0 0 2px;">{title}</p>
<p style="font-size:12px;color:#666;margin:0;">{desc}</p>
</div>
</div>""",
unsafe_allow_html=True,
)
st.divider()
# =====================================================
# QUICK NAVIGATION BUTTONS
# =====================================================
st.header("๐ Explore Features")
col1, col2 = st.columns(2)
with col1:
if st.button("๐ผ๏ธ Image Classification", use_container_width=True):
st.switch_page("pages/image_classification.py")
if st.button("๐ CNN Performance", use_container_width=True):
st.switch_page("pages/model_performance.py")
with col2:
if st.button("๐ Object Detection", use_container_width=True):
st.switch_page("pages/yolo_object_detection.py")
if st.button("๐ YOLO Performance", use_container_width=True):
st.switch_page("pages/yolo_performance.py")
st.divider()
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SECTION 3 โ MODELS USED
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("### ๐ค Models Used")
# โโ YOLOv8 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("#### ๐ Object Detection")
yolo_col, yolo_info = st.columns([1, 3])
with yolo_col:
st.markdown(
"""<div style="
background:linear-gradient(135deg,#f39c1222,#f39c1211);
border:2px solid #f39c1266; border-radius:14px;
padding:20px; text-align:center;
">
<p style="font-size:36px;margin:0;">โก</p>
<p style="font-size:16px;font-weight:800;color:#f39c12;margin:8px 0 2px;">YOLOv8s</p>
<p style="font-size:11px;color:#888;margin:0;">Ultralytics</p>
</div>""",
unsafe_allow_html=True,
)
with yolo_info:
chips = [
("ARCHITECTURE", "YOLOv8 Small (YOLOv8s)"),
("PRETRAINED ON", "COCO (80 classes)"),
("FINE-TUNED ON", "25-Class COCO Subset"),
("EPOCHS", "50"),
("IMAGE SIZE", "640 ร 640"),
("mAP@0.5", "0.893"),
("PRECISION", "95.1%"),
("RECALL", "87.7%"),
("INFERENCE", "~6.7 ms ยท ~120 FPS"),
]
chips_html = "".join(
f'<span style="display:inline-block;background:#f8f9fa;border:1px solid #dee2e6;'
f'border-radius:8px;padding:5px 10px;font-size:12px;margin:3px 4px 3px 0;">'
f'<span style="color:#888;font-size:10px;display:block;font-weight:600;'
f'letter-spacing:.5px;text-transform:uppercase;">{k}</span>'
f'<span style="font-weight:700;color:#f39c12;">{v}</span></span>'
for k, v in chips
)
st.markdown(
f"""<div style="border:1.5px solid #f39c1233;border-radius:12px;
padding:14px 16px;background:#f39c1208;">
<div style="margin-bottom:10px;">{chips_html}</div>
<p style="font-size:12px;color:#666;margin:0;line-height:1.6;">
YOLOv8s is Ultralytics' small variant โ optimised for the best balance between
accuracy and inference speed. Fine-tuned with mosaic augmentation,
auto-optimizer (AdamW), and AMP mixed precision.
</p>
</div>""",
unsafe_allow_html=True,
)
st.markdown("<br>", unsafe_allow_html=True)
# โโ CNN Models โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("#### ๐ง Image Classification โ CNN Models")
CNN_MODELS = [
{"name": "EfficientNetB0", "icon": "๐จ", "color": "#f39c12", "highlight": "Best Accuracy"},
{"name": "ResNet50", "icon": "๐ฅ", "color": "#e74c3c", "highlight": "Best All-Rounder"},
{"name": "MobileNetV2", "icon": "๐ฉ", "color": "#2ecc71", "highlight": "Fastest Inference"},
{"name": "VGG16", "icon": "๐ฆ", "color": "#3498db", "highlight": "Reliable Baseline"},
]
for model in CNN_MODELS:
st.markdown(
f"""
<div style="
padding:10px 14px;
margin-bottom:8px;
border-radius:10px;
background:#f8f9fa;
border-left:5px solid {model['color']};
">
<span style="font-size:18px;">{model['icon']}</span>
<span style="font-weight:700;font-size:15px;color:#000000;">
{model['name']}
</span>
<span style="font-size:11px;margin-left:8px;color:{model['color']};font-weight:600;">
{model['highlight']}
</span>
</div>
""",
unsafe_allow_html=True
)
st.divider()
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SECTION 4 โ DATASET + CLASSES
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("### ๐ฆ Dataset")
d1, d2 = st.columns([1, 2])
with d1:
dataset_rows = [
("Total Images", "2,500"),
("Images / Class", "100"),
("Train Split", "70% ยท 1,750 images"),
("Val Split", "15% ยท 375 images"),
("Test Split", "15% ยท 375 images"),
("Image Size", "224 ร 224 px"),
("Annotation", "COCO Bounding Boxes"),
("Source", "Hugging Face (streaming)"),
]
rows_html = "".join(
f'<div style="display:flex;justify-content:space-between;align-items:center;'
f'padding:8px 14px;border-bottom:1px solid #f0f0f0;font-size:12px;">'
f'<span style="color:#666;font-weight:500;">{k}</span>'
f'<span style="font-weight:700;color:#2c3e50;">{v}</span></div>'
for k, v in dataset_rows
)
st.markdown(
f'<div style="border:1.5px solid #dee2e6;border-radius:12px;overflow:hidden;">'
f'<div style="background:#2c3e50;padding:10px 14px;">'
f'<p style="color:#fff;font-weight:700;font-size:14px;margin:0;">COCO-25 Subset</p></div>'
f'{rows_html}</div>',
unsafe_allow_html=True,
)
with d2:
st.markdown("**25 Supported Classes:**")
CLASS_NAMES = [
'person','bicycle','car','motorcycle','airplane','bus','train','truck',
'traffic light','stop sign','bench','bird','cat','dog','horse','cow',
'elephant','bottle','cup','bowl','pizza','cake','chair','couch','potted plant',
]
ICONS = {
'person':'๐ง','bicycle':'๐ฒ','car':'๐','motorcycle':'๐๏ธ','airplane':'โ๏ธ',
'bus':'๐','train':'๐','truck':'๐','traffic light':'๐ฆ','stop sign':'๐',
'bench':'๐ช','bird':'๐ฆ','cat':'๐ฑ','dog':'๐ถ','horse':'๐ด','cow':'๐ฎ',
'elephant':'๐','bottle':'๐ถ','cup':'โ','bowl':'๐ฅฃ','pizza':'๐',
'cake':'๐','chair':'๐ช','couch':'๐๏ธ','potted plant':'๐ชด',
}
badges = " ".join(
f'<span style="display:inline-block;background:#f0f4ff;border:1px solid #c8d8f8;'
f'border-radius:20px;padding:6px 14px;font-size:16px;margin:6px 4px;'
f'color:#000000;font-weight:600;">'
f'{ICONS.get(c,"โข")} {c}</span>'
for c in CLASS_NAMES
)
st.markdown(f'<div style="line-height:2.6;">{badges}</div>', unsafe_allow_html=True)
st.divider()
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SECTION 5 โ BUSINESS APPLICATIONS
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("### ๐ Business Applications")
APPS = [
("๐๏ธ", "Smart Cities & Traffic Management",
"Automated vehicle detection ยท Pedestrian safety monitoring ยท Parking detection ยท Traffic violation detection"),
("๐", "Retail & E-Commerce",
"Product recognition ยท Scan-free checkout ยท Customer behaviour analytics ยท Visual search"),
("๐", "Security & Surveillance",
"Intrusion detection ยท Unattended object alerts ยท Perimeter monitoring ยท Crowd density analysis"),
("๐ฆ", "Wildlife Conservation",
"Species identification ยท Habitat monitoring ยท Poaching prevention ยท Population studies"),
("๐ฅ", "Healthcare",
"PPE compliance verification ยท Equipment tracking ยท Patient fall detection ยท Hygiene monitoring"),
("๐ ", "Smart Home & IoT",
"Home automation ยท Security alerts ยท Pet activity tracking ยท Energy usage detection"),
("๐พ", "Agriculture",
"Livestock monitoring ยท Pest detection ยท Equipment tracking ยท Harvest readiness detection"),
("๐ฆ", "Logistics & Warehousing",
"Package sorting ยท Inventory tracking ยท Quality control ยท Loading bay monitoring"),
]
for icon, title, description in APPS:
st.markdown(
f"""
<div style="border:1.5px solid #dee2e6;border-radius:12px;padding:14px 16px;
margin-bottom:12px;background:#fafbfc;">
<span style="font-size:20px;">{icon}</span>
<span style="font-size:15px;font-weight:700;color:#000;">{title}: </span>
<span style="font-size:13px;color:#555;">{description}</span>
</div>
""",
unsafe_allow_html=True,
)
st.divider()
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# SECTION 6 โ TECH STACK + RESULTS
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("### ๐ ๏ธ Tech Stack & Project Info")
tech_col, dev_col = st.columns([1, 1])
with tech_col:
TECH = [
("๐", "Python 3.10", "Core programming language"),
("๐ค", "TensorFlow / Keras", "CNN training & inference"),
("โก", "Ultralytics YOLOv8", "Object detection & fine-tuning"),
("๐๏ธ", "OpenCV", "Image processing & annotation"),
("๐", "Streamlit", "Interactive web app framework"),
("๐ค", "Hugging Face Spaces", "Cloud deployment platform"),
("๐", "Matplotlib / Seaborn", "Visualisations"),
("๐ข", "NumPy / Pandas", "Data processing"),
("๐งช", "Scikit-learn", "Evaluation metrics"),
]
rows_html = "".join(
f'<div style="display:flex;align-items:center;gap:10px;padding:10px 14px;'
f'border-bottom:1px solid rgba(255,255,255,0.05);">'
f'<span style="font-size:18px;width:26px;text-align:center;">{icon}</span>'
f'<span style="font-size:13px;font-weight:600;min-width:170px;color:#e5e7eb;">{name}</span>'
f'<span style="font-size:12px;color:#9ca3af;">{desc}</span></div>'
for icon, name, desc in TECH
)
st.markdown(
f'''<div style="border:1px solid rgba(255,255,255,0.08);border-radius:14px;
overflow:hidden;background:linear-gradient(145deg,#0f172a,#111827);
box-shadow:0 8px 24px rgba(0,0,0,0.4);">
<div style="background:linear-gradient(90deg,#2563eb,#1d4ed8);padding:12px 16px;">
<p style="color:#fff;font-weight:700;font-size:14px;margin:0;">๐ ๏ธ Tech Stack</p>
</div>
{rows_html}
</div>''',
unsafe_allow_html=True,
)
with dev_col:
st.markdown("""
<div style="border:1px solid rgba(255,255,255,0.08);border-radius:14px;padding:18px 20px;
background:linear-gradient(145deg,#0f172a,#111827);box-shadow:0 8px 24px rgba(0,0,0,0.4);
color:#e5e7eb;line-height:1.9;font-size:14px;">
<p style="font-weight:700;font-size:16px;margin-bottom:12px;">๐ Model Scope & Results</p>
Image Classification (Transfer Learning)<br>
Object Detection (YOLOv8 Fine-tuning)<br>
Evaluation โ Accuracy ยท mAP@0.5 ยท Precision ยท Recall ยท F1<br><br>
<span style="color:#22c55e;font-weight:600;">CNN Result โ 92% (EfficientNetB0) โ
</span><br>
<span style="color:#22c55e;font-weight:600;">YOLO Result โ mAP@0.5 = 0.893 โ
</span>
</div>
""", unsafe_allow_html=True) |