DIVYANSHI SINGH commited on
Commit Β·
e22aa39
1
Parent(s): 3c16f49
feat: implement dynamic model-specific samples and resolve session stability error
Browse files- apds/dashboard.py +28 -11
- apds/path_utils.py +9 -2
- assets/samples/images/cracks/cracking-2-_jpg.rf.7ca438dfc3d0379a740e37426ae8b60d.jpg +3 -0
- assets/samples/images/cracks/cracking-27-_jpg.rf.0f7a0646abc4786b505562127d7be737.jpg +3 -0
- assets/samples/images/cracks/cracking-32-_jpg.rf.38387a609dd55cf2f0c6bedf5a79e684.jpg +3 -0
apds/dashboard.py
CHANGED
|
@@ -14,6 +14,8 @@ from .detector import PotholeDetector
|
|
| 14 |
from . import utils
|
| 15 |
from datetime import datetime
|
| 16 |
import torch
|
|
|
|
|
|
|
| 17 |
from dotenv import load_dotenv
|
| 18 |
|
| 19 |
import cv2
|
|
@@ -331,22 +333,33 @@ def tab_image(model, variant, conf, label, use_sahi: bool = False):
|
|
| 331 |
else:
|
| 332 |
st.session_state.detected_gps = None
|
| 333 |
else:
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
name = col_sel.selectbox("Pick a field sample", list(samples.keys()))
|
| 344 |
if name and samples[name]:
|
| 345 |
-
s_path = pu.get_sample_path(samples[name])
|
| 346 |
if s_path.exists():
|
| 347 |
img = Image.open(s_path).convert("RGB")
|
|
|
|
| 348 |
else:
|
| 349 |
-
st.error(f"
|
| 350 |
|
| 351 |
if img is None: return
|
| 352 |
|
|
@@ -677,6 +690,10 @@ def tab_evaluation(variant: str):
|
|
| 677 |
|
| 678 |
|
| 679 |
def render():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
st.markdown("<h1 style='text-align:center;'>ποΈ Automated Pavement Distress System (APDS)</h1>", unsafe_allow_html=True)
|
| 681 |
st.divider()
|
| 682 |
|
|
|
|
| 14 |
from . import utils
|
| 15 |
from datetime import datetime
|
| 16 |
import torch
|
| 17 |
+
import os
|
| 18 |
+
import uuid
|
| 19 |
from dotenv import load_dotenv
|
| 20 |
|
| 21 |
import cv2
|
|
|
|
| 333 |
else:
|
| 334 |
st.session_state.detected_gps = None
|
| 335 |
else:
|
| 336 |
+
# ββ Dynamic Sample Logic ββ
|
| 337 |
+
is_crack = "crack" in label.lower()
|
| 338 |
+
if is_crack:
|
| 339 |
+
samples = {
|
| 340 |
+
"Select Crack Sample": None,
|
| 341 |
+
"Crack Sample 1: Surface Fatigue": "cracking-2-_jpg.rf.7ca438dfc3d0379a740e37426ae8b60d.jpg",
|
| 342 |
+
"Crack Sample 2: Transverse stress": "cracking-27-_jpg.rf.0f7a0646abc4786b505562127d7be737.jpg",
|
| 343 |
+
"Crack Sample 3: Alligator cracking": "cracking-32-_jpg.rf.38387a609dd55cf2f0c6bedf5a79e684.jpg"
|
| 344 |
+
}
|
| 345 |
+
else:
|
| 346 |
+
samples = {
|
| 347 |
+
"Select Pothole Sample": None,
|
| 348 |
+
"Sample 1: Multiple Potholes": "train_0001_jpg.rf.042f2f916fa4f5561dac320039da31b5.jpg",
|
| 349 |
+
"Sample 2: Complex Road View": "train_0002_jpg.rf.0639c6d4a821da6d40ec8c499710b0f4.jpg",
|
| 350 |
+
"Sample 3: Shadowy Conditions": "test_0004_jpg.rf.ca7c5c7984d0c49b97d713a94471d3bb.jpg",
|
| 351 |
+
"Sample 4: Urban Arterial Stress": "test_0162_jpg.rf.2bd99b9e0ae585e50ae1ef3978672473.jpg",
|
| 352 |
+
"Sample 5: High-Traffic Fatigue": "test_0187_jpg.rf.696b03eb513485044a267f5fa8cb74d1.jpg"
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
name = col_sel.selectbox("Pick a field sample", list(samples.keys()))
|
| 356 |
if name and samples[name]:
|
| 357 |
+
s_path = pu.get_sample_path(samples[name], is_crack=is_crack)
|
| 358 |
if s_path.exists():
|
| 359 |
img = Image.open(s_path).convert("RGB")
|
| 360 |
+
st.info(f"π‘ Playing demo with professional {label.lower()} sample.")
|
| 361 |
else:
|
| 362 |
+
st.error(f"Demo file missed in cloud: {samples[name]}")
|
| 363 |
|
| 364 |
if img is None: return
|
| 365 |
|
|
|
|
| 690 |
|
| 691 |
|
| 692 |
def render():
|
| 693 |
+
if "session_id" not in st.session_state:
|
| 694 |
+
st.session_state.session_id = str(uuid.uuid4())
|
| 695 |
+
st.session_state.initialized = True
|
| 696 |
+
|
| 697 |
st.markdown("<h1 style='text-align:center;'>ποΈ Automated Pavement Distress System (APDS)</h1>", unsafe_allow_html=True)
|
| 698 |
st.divider()
|
| 699 |
|
apds/path_utils.py
CHANGED
|
@@ -60,9 +60,14 @@ def get_training_artifact(model_path: Path, filename: str) -> Path:
|
|
| 60 |
# Fallback to exact filename
|
| 61 |
return base_dir / filename
|
| 62 |
|
| 63 |
-
def get_sample_path(filename: str, is_video: bool = False) -> Path:
|
| 64 |
"""Find a sample file, prioritizing cloud-accessible 'assets/' folder."""
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Priority 1: Cloud Assets (included in Git)
|
| 68 |
p = ROOT / "assets" / "samples" / sub / filename
|
|
@@ -75,6 +80,8 @@ def get_sample_path(filename: str, is_video: bool = False) -> Path:
|
|
| 75 |
p = ROOT / "data" / "combined" / "train" / "images" / filename
|
| 76 |
if not p.exists():
|
| 77 |
p = ROOT / "data" / "combined" / "test" / "images" / filename
|
|
|
|
|
|
|
| 78 |
|
| 79 |
return p
|
| 80 |
|
|
|
|
| 60 |
# Fallback to exact filename
|
| 61 |
return base_dir / filename
|
| 62 |
|
| 63 |
+
def get_sample_path(filename: str, is_video: bool = False, is_crack: bool = False) -> Path:
|
| 64 |
"""Find a sample file, prioritizing cloud-accessible 'assets/' folder."""
|
| 65 |
+
if is_video:
|
| 66 |
+
sub = "videos"
|
| 67 |
+
elif is_crack:
|
| 68 |
+
sub = "images/cracks"
|
| 69 |
+
else:
|
| 70 |
+
sub = "images"
|
| 71 |
|
| 72 |
# Priority 1: Cloud Assets (included in Git)
|
| 73 |
p = ROOT / "assets" / "samples" / sub / filename
|
|
|
|
| 80 |
p = ROOT / "data" / "combined" / "train" / "images" / filename
|
| 81 |
if not p.exists():
|
| 82 |
p = ROOT / "data" / "combined" / "test" / "images" / filename
|
| 83 |
+
if not p.exists() and is_crack:
|
| 84 |
+
p = ROOT / "data" / "bc_projekt" / "test" / "images" / filename
|
| 85 |
|
| 86 |
return p
|
| 87 |
|
assets/samples/images/cracks/cracking-2-_jpg.rf.7ca438dfc3d0379a740e37426ae8b60d.jpg
ADDED
|
Git LFS Details
|
assets/samples/images/cracks/cracking-27-_jpg.rf.0f7a0646abc4786b505562127d7be737.jpg
ADDED
|
Git LFS Details
|
assets/samples/images/cracks/cracking-32-_jpg.rf.38387a609dd55cf2f0c6bedf5a79e684.jpg
ADDED
|
Git LFS Details
|