feat: update Flask routes to use grouped models
This commit is contained in:
1 parent
22c78429cf
commit
dbd79ed442
2 files changed
+83
-18
No files matched your search
@@ -13,7 +13,7 @@ from flask import (
|
|||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
from src.job import JobQueue
|
from src.job import JobQueue
|
||||||
from src.model_registry import scan_models
|
from src.model_registry import scan_models, scan_model_groups
|
||||||
from src.preview import extract_thumbnail, extract_sample_frames
|
from src.preview import extract_thumbnail, extract_sample_frames
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@@ -40,8 +40,8 @@ def basename_filter(path):
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
models = scan_models(MODELS_DIR)
|
model_groups = scan_model_groups(MODELS_DIR)
|
||||||
return render_template("index.html", models=models, models_dir=MODELS_DIR)
|
return render_template("index.html", model_groups=model_groups, models_dir=MODELS_DIR)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/upload", methods=["POST"])
|
@app.route("/upload", methods=["POST"])
|
||||||
@@ -54,12 +54,46 @@ def upload():
|
|||||||
if not safe_name or not safe_name.lower().endswith((".mp4", ".avi", ".mkv", ".mov", ".webm")):
|
if not safe_name or not safe_name.lower().endswith((".mp4", ".avi", ".mkv", ".mov", ".webm")):
|
||||||
return "Invalid video file type", 400
|
return "Invalid video file type", 400
|
||||||
|
|
||||||
|
# New grouped format: model_stems + format_{stem}
|
||||||
|
selected_stems = request.form.getlist("model_stems")
|
||||||
|
# Legacy format: models (filenames)
|
||||||
selected_models = request.form.getlist("models")
|
selected_models = request.form.getlist("models")
|
||||||
models = scan_models(MODELS_DIR)
|
|
||||||
by_name = {m.filename: m for m in models}
|
|
||||||
|
|
||||||
model_configs = []
|
model_configs = []
|
||||||
class_filters = {}
|
class_filters = {}
|
||||||
|
|
||||||
|
if selected_stems:
|
||||||
|
# Grouped model selection
|
||||||
|
groups = scan_model_groups(MODELS_DIR)
|
||||||
|
groups_by_stem = {g.stem: g for g in groups}
|
||||||
|
|
||||||
|
for stem in selected_stems:
|
||||||
|
if stem not in groups_by_stem:
|
||||||
|
continue
|
||||||
|
group = groups_by_stem[stem]
|
||||||
|
fmt = request.form.get(f"format_{stem}", group.default_format)
|
||||||
|
if fmt not in group.format_paths:
|
||||||
|
continue
|
||||||
|
# Create a ModelConfig for the selected format
|
||||||
|
from src.model_registry import ModelConfig
|
||||||
|
model_configs.append(ModelConfig(
|
||||||
|
filename=os.path.basename(group.format_paths[fmt]),
|
||||||
|
path=group.format_paths[fmt],
|
||||||
|
stem=stem,
|
||||||
|
known_classes=list(group.known_classes),
|
||||||
|
))
|
||||||
|
filter_val = request.form.get(f"filter_{stem}", "")
|
||||||
|
if not filter_val or filter_val in ("default",):
|
||||||
|
pass # model defaults
|
||||||
|
elif filter_val == "all":
|
||||||
|
class_filters[stem] = None
|
||||||
|
else:
|
||||||
|
class_filters[stem] = filter_val.split(",")
|
||||||
|
elif selected_models:
|
||||||
|
# Legacy flat model selection
|
||||||
|
models = scan_models(MODELS_DIR)
|
||||||
|
by_name = {m.filename: m for m in models}
|
||||||
|
|
||||||
for name in selected_models:
|
for name in selected_models:
|
||||||
if name in by_name:
|
if name in by_name:
|
||||||
model_configs.append(by_name[name])
|
model_configs.append(by_name[name])
|
||||||
@@ -122,14 +156,16 @@ def download(job_id, filename):
|
|||||||
|
|
||||||
@app.route("/api/models")
|
@app.route("/api/models")
|
||||||
def api_models():
|
def api_models():
|
||||||
models = scan_models(MODELS_DIR)
|
groups = scan_model_groups(MODELS_DIR)
|
||||||
return jsonify([
|
return jsonify([
|
||||||
{
|
{
|
||||||
"filename": m.filename,
|
"stem": g.stem,
|
||||||
"stem": m.stem,
|
"formats": g.formats,
|
||||||
"known_classes": m.known_classes,
|
"format_paths": g.format_paths,
|
||||||
|
"known_classes": g.known_classes,
|
||||||
|
"default_format": g.default_format,
|
||||||
}
|
}
|
||||||
for m in models
|
for g in groups
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+37
-8
@@ -164,6 +164,27 @@
|
|||||||
background: var(--color-neutral-50);
|
background: var(--color-neutral-50);
|
||||||
color: var(--color-neutral-700);
|
color: var(--color-neutral-700);
|
||||||
}
|
}
|
||||||
|
.model-card-format {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
margin-bottom: var(--space-3);
|
||||||
|
}
|
||||||
|
.model-card-format label {
|
||||||
|
font-size: var(--text-xs);
|
||||||
|
font-weight: var(--font-medium);
|
||||||
|
color: var(--color-neutral-500);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.model-card-format select {
|
||||||
|
flex: 1;
|
||||||
|
padding: var(--space-1) var(--space-2);
|
||||||
|
font-size: var(--text-xs);
|
||||||
|
border: 1px solid var(--color-neutral-300);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: var(--color-neutral-50);
|
||||||
|
color: var(--color-neutral-700);
|
||||||
|
}
|
||||||
|
|
||||||
/* Submit area */
|
/* Submit area */
|
||||||
.submit-area {
|
.submit-area {
|
||||||
@@ -220,7 +241,7 @@
|
|||||||
<div class="model-section">
|
<div class="model-section">
|
||||||
<div class="model-section-header">
|
<div class="model-section-header">
|
||||||
<h3>Select Models</h3>
|
<h3>Select Models</h3>
|
||||||
{% if models %}
|
{% if model_groups %}
|
||||||
<div class="model-toggle-btns">
|
<div class="model-toggle-btns">
|
||||||
<button type="button" class="btn btn-ghost btn-sm" id="select-all-btn">Select All</button>
|
<button type="button" class="btn btn-ghost btn-sm" id="select-all-btn">Select All</button>
|
||||||
<button type="button" class="btn btn-ghost btn-sm" id="deselect-all-btn">Deselect All</button>
|
<button type="button" class="btn btn-ghost btn-sm" id="deselect-all-btn">Deselect All</button>
|
||||||
@@ -228,26 +249,34 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if models %}
|
{% if model_groups %}
|
||||||
<div class="model-grid" id="model-grid" role="group" aria-label="Available detection models">
|
<div class="model-grid" id="model-grid" role="group" aria-label="Available detection models">
|
||||||
{% for model in models %}
|
{% for group in model_groups %}
|
||||||
<label class="model-card" id="card-{{ loop.index }}">
|
<label class="model-card" id="card-{{ loop.index }}">
|
||||||
<div class="model-card-header">
|
<div class="model-card-header">
|
||||||
<input type="checkbox" name="models" value="{{ model.filename }}" class="model-card-check" id="m-{{ loop.index }}">
|
<input type="checkbox" name="model_stems" value="{{ group.stem }}" class="model-card-check" id="m-{{ loop.index }}">
|
||||||
<span class="model-card-name">{{ model.filename }}</span>
|
<span class="model-card-name">{{ group.stem }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="model-card-badges">
|
<div class="model-card-badges">
|
||||||
{% if model.known_classes %}
|
{% if group.known_classes %}
|
||||||
{% for cls in model.known_classes %}
|
{% for cls in group.known_classes %}
|
||||||
<span class="badge badge-info">{{ cls }}</span>
|
<span class="badge badge-info">{{ cls }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="badge badge-neutral">no class info</span>
|
<span class="badge badge-neutral">no class info</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="model-card-format">
|
||||||
|
<label for="format-{{ loop.index }}">Format:</label>
|
||||||
|
<select name="format_{{ group.stem }}" id="format-{{ loop.index }}">
|
||||||
|
{% for fmt in group.formats %}
|
||||||
|
<option value="{{ fmt }}"{% if fmt == group.default_format %} selected{% endif %}>{{ fmt }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="model-card-filter">
|
<div class="model-card-filter">
|
||||||
<label for="filter-{{ loop.index }}">Filter:</label>
|
<label for="filter-{{ loop.index }}">Filter:</label>
|
||||||
<select name="filter_{{ model.filename }}" id="filter-{{ loop.index }}">
|
<select name="filter_{{ group.stem }}" id="filter-{{ loop.index }}">
|
||||||
<option value="default">Use model defaults</option>
|
<option value="default">Use model defaults</option>
|
||||||
<option value="sack">sack only</option>
|
<option value="sack">sack only</option>
|
||||||
<option value="box">box only</option>
|
<option value="box">box only</option>
|
||||||
|
|||||||
Reference in new issue
Block a user