4.9 KiB
Model Grouping by Stem with Format Selection
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Combine model files with the same stem (e.g., best.pt, best.onnx, best.engine) into a single selectable model entry with a format dropdown (.pt / .onnx / .engine), reducing UI clutter while preserving format choice.
Current State: 17 model files displayed as 17 separate checkboxes (e.g., best.pt, best.onnx, best.engine as three separate entries). Each has its own filter dropdown.
Desired State: 6 model entries (one per stem: best, model_karung_truk, truck-detector, v4-best, yolo11n-bbox-100ep-sack+box-20260909-best, karung-dimuat-detection-di-feedmill-yolo26n-seg-200e). Each entry has:
- One checkbox to enable the model
- A format dropdown showing available formats (e.g.,
.pt,.onnx,.engine) - One filter dropdown (shared across formats, since classes are the same per stem)
Architecture:
- Modify
scan_models()to return grouped models (one per stem) with format options - Update
ModelConfigdataclass to includeformats: list[str]andformat_paths: dict[str, str] - Update
/route to pass grouped models - Update upload endpoint to handle the new format
- Rewrite template to render grouped cards with format dropdown
- Update JavaScript to handle grouped model selection
Tech Stack: Python, Flask, vanilla JS
Global Constraints
- Python >= 3.10
- No new Python dependencies
- Keep backward compatibility where reasonable
- Flat Design CSS with teal primary, orange accent
- Accessible: semantic HTML, ARIA, keyboard navigation
- Responsive: mobile-first
Task 1: Update Model Registry — Group by Stem
Files:
- Modify:
src/model_registry.py
Requirements:
-
New dataclass
ModelGroup:stem: str— the model stem (e.g., "best")formats: list[str]— available formats (e.g., [".pt", ".onnx", ".engine"])format_paths: dict[str, str]— format -> full path mappingknown_classes: list[str]— from KNOWN_MODEL_CLASSESdefault_format: str— preferred format order: .engine > .pt > .onnx
-
New function
scan_model_groups(models_dir: str) -> list[ModelGroup]:- Scan all files with MODEL_EXTENSIONS
- Group by stem
- Sort formats by preference (.engine first)
- Return list of ModelGroup
-
Keep
scan_models()for backward compatibility (API endpoint, tests)
Interfaces:
- Produces:
ModelGroupwith fields above - Consumes:
KNOWN_MODEL_CLASSES,MODEL_EXTENSIONS
Tests: Add tests for grouping logic
Task 2: Update Flask Routes — Use Grouped Models
Files:
- Modify:
app.py
Requirements:
index()route: callscan_model_groups()instead ofscan_models(), passmodel_groupsto templateupload()route:- Accept
model_stemandmodel_formatfrom form (e.g.,model_stem=best,model_format=.engine) - Look up group by stem, then get path from
format_paths[format] - Build
model_configswith single selected format per group - Keep class filter logic (per stem, not per file)
- Accept
api_models()endpoint: return grouped format (include formats + paths)
Backward Compatibility:
- If
models(filenames) still sent, support legacy path - But prefer new
model_stem+model_formatapproach
Task 3: Update Template — Grouped Model Cards
Files:
- Modify:
templates/index.html
Requirements:
- Iterate over
model_groupsinstead ofmodels - Each card:
- Checkbox with
value="{{ group.stem }}"anddata-format="{{ group.default_format }}" - Format dropdown (
<select name="format_{{ group.stem }}">) with options for each format ingroup.formats - Filter dropdown (same as before, but
name="filter_{{ group.stem }}") - Badges from
group.known_classes
- Checkbox with
- Update "Select All" / "Deselect All" to work with grouped checkboxes
- Update submit hint logic: enable submit when video + at least one group selected
Task 4: Update JavaScript — Handle Grouped Models
Files:
- Modify:
static/app.js
Requirements:
initModelCards(): work with grouped cards (same logic, different selectors)updateSubmitState(): check grouped checkboxesinitFormSubmit(): on submit, collectmodel_stem+format_{{stem}}values- Format dropdown change: update hidden input or data attribute so form submits correct format
Task 5: Verification & Testing
Files: None (verification only)
Requirements:
- Run existing tests:
python -m pytest tests/ -v - Verify Flask app starts
- Test UI manually:
- Open
/-> see 6 model entries (not 17) - Each entry has format dropdown with correct options
- Select multiple models with different formats
- Submit -> job processes with selected formats
- Open
- Verify
/api/modelsreturns grouped format