Phase 3: near-duplicate (dHash) rejection on contributed photos
Browse files- game/ui.py +11 -8
game/ui.py
CHANGED
|
@@ -191,16 +191,18 @@ def _stump_reject_html() -> str:
|
|
| 191 |
)
|
| 192 |
|
| 193 |
|
| 194 |
-
def _stump_result_html(label: str, res,
|
| 195 |
mtier = "UNKNOWN" if res.abstained else res.safety
|
| 196 |
c = TIER_COLOR.get(mtier, "#57544c")
|
| 197 |
mcall = "refused to commit" if res.abstained else f"{_pretty(res.species)} · {mtier}"
|
| 198 |
head = "🏆 You stumped the machine!" if res.abstained else "The machine made its call."
|
| 199 |
-
store_line =
|
| 200 |
-
"<div class='gm-ok'>✓ Added to the open dataset — thank you. This is exactly
|
| 201 |
-
|
| 202 |
-
"<div class='gm-warn'>
|
| 203 |
-
|
|
|
|
|
|
|
| 204 |
return (
|
| 205 |
f"<div class='gm-reveal'>"
|
| 206 |
f"<div class='gm-truth-h'>YOUR FIND</div>"
|
|
@@ -261,8 +263,9 @@ def build_stump_tab(pipe) -> None:
|
|
| 261 |
return _stump_reject_html(), gr.update()
|
| 262 |
machine = {"species": res.species, "confidence": res.confidence,
|
| 263 |
"abstained": res.abstained, "safety": res.safety, "domain": res.domain}
|
| 264 |
-
|
| 265 |
-
|
|
|
|
| 266 |
|
| 267 |
submit.click(_submit, [up, guess, consent], [sresult, contrib])
|
| 268 |
crefresh.click(lambda: _contrib_df(), None, [contrib])
|
|
|
|
| 191 |
)
|
| 192 |
|
| 193 |
|
| 194 |
+
def _stump_result_html(label: str, res, status: str) -> str:
|
| 195 |
mtier = "UNKNOWN" if res.abstained else res.safety
|
| 196 |
c = TIER_COLOR.get(mtier, "#57544c")
|
| 197 |
mcall = "refused to commit" if res.abstained else f"{_pretty(res.species)} · {mtier}"
|
| 198 |
head = "🏆 You stumped the machine!" if res.abstained else "The machine made its call."
|
| 199 |
+
store_line = {
|
| 200 |
+
"stored": "<div class='gm-ok'>✓ Added to the open dataset — thank you. This is exactly "
|
| 201 |
+
"the data that makes the next model better.</div>",
|
| 202 |
+
"duplicate": "<div class='gm-warn'>Already in the dataset — this photo (or a near-match) "
|
| 203 |
+
"was logged before, so it wasn't added again.</div>",
|
| 204 |
+
"disabled": "<div class='gm-warn'>Couldn't persist (dataset token not set on the Space).</div>",
|
| 205 |
+
}.get(status, "")
|
| 206 |
return (
|
| 207 |
f"<div class='gm-reveal'>"
|
| 208 |
f"<div class='gm-truth-h'>YOUR FIND</div>"
|
|
|
|
| 263 |
return _stump_reject_html(), gr.update()
|
| 264 |
machine = {"species": res.species, "confidence": res.confidence,
|
| 265 |
"abstained": res.abstained, "safety": res.safety, "domain": res.domain}
|
| 266 |
+
status = datastore.append_sighting(image, user_label.strip(), machine, profile.username)
|
| 267 |
+
board = _contrib_df() if status == "stored" else gr.update()
|
| 268 |
+
return _stump_result_html(user_label.strip(), res, status), board
|
| 269 |
|
| 270 |
submit.click(_submit, [up, guess, consent], [sresult, contrib])
|
| 271 |
crefresh.click(lambda: _contrib_df(), None, [contrib])
|