Spaces:
Running
Running
adds error treat
Browse files- app.py +73 -1
- index.html +1 -1
app.py
CHANGED
|
@@ -322,4 +322,76 @@ def submit_help_proof(
|
|
| 322 |
match = matcher.find_match(embedding, candidates)
|
| 323 |
if match:
|
| 324 |
matched_id, score = match
|
| 325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
match = matcher.find_match(embedding, candidates)
|
| 323 |
if match:
|
| 324 |
matched_id, score = match
|
| 325 |
+
ai_verified = (matched_id == animal_id)
|
| 326 |
+
match_score = round(score * 100)
|
| 327 |
+
|
| 328 |
+
# Detecta melhora de condiΓ§Γ£o
|
| 329 |
+
animal_data = db.get_animal(animal_id)
|
| 330 |
+
if animal_data:
|
| 331 |
+
prev_desc = _json.loads(animal_data.get("description") or "{}")
|
| 332 |
+
prev_condition = prev_desc.get("condition", "")
|
| 333 |
+
new_condition = description.get("condition", "")
|
| 334 |
+
condition_rank = {"injured": 0, "thin": 1, "healthy": 2}
|
| 335 |
+
if (condition_rank.get(new_condition, -1) >
|
| 336 |
+
condition_rank.get(prev_condition, -1)):
|
| 337 |
+
condition_update = new_condition
|
| 338 |
+
|
| 339 |
+
photo_path = db.save_photo(img, animal_id=animal_id)
|
| 340 |
+
|
| 341 |
+
db.add_sighting(
|
| 342 |
+
animal_id,
|
| 343 |
+
photo_path,
|
| 344 |
+
None, None,
|
| 345 |
+
notes,
|
| 346 |
+
is_help_event=True,
|
| 347 |
+
help_type=help_type,
|
| 348 |
+
)
|
| 349 |
+
db.update_animal(animal_id)
|
| 350 |
+
|
| 351 |
+
log_trace({
|
| 352 |
+
"event": "help_proof",
|
| 353 |
+
"animal_id": animal_id,
|
| 354 |
+
"help_type": help_type,
|
| 355 |
+
"has_photo": photo_path is not None,
|
| 356 |
+
"ai_verified": ai_verified,
|
| 357 |
+
"match_score": match_score,
|
| 358 |
+
"condition_update": condition_update,
|
| 359 |
+
})
|
| 360 |
+
|
| 361 |
+
return {
|
| 362 |
+
"ok": True,
|
| 363 |
+
"animal_id": animal_id,
|
| 364 |
+
"help_type": help_type,
|
| 365 |
+
"ai_verified": ai_verified,
|
| 366 |
+
"match_score": match_score,
|
| 367 |
+
"condition_update": condition_update,
|
| 368 |
+
"photo_url": _photo_url(photo_path) if photo_path else "",
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
# βββ Admin ββββββββββββββββββββββββββββββββββββββββββββ
|
| 373 |
+
|
| 374 |
+
@app.get("/admin/push-traces")
|
| 375 |
+
async def push_traces():
|
| 376 |
+
"""Publica data/traces.jsonl como dataset no HF Hub.
|
| 377 |
+
Acesse esta URL no browser para disparar o upload.
|
| 378 |
+
Requer HF_TOKEN e HF_DATASET_ID nos Secrets do Space.
|
| 379 |
+
"""
|
| 380 |
+
from core.tracer import push_to_hub, TRACES_PATH
|
| 381 |
+
if not TRACES_PATH.exists():
|
| 382 |
+
return JSONResponse(content={"ok": False, "error": "Nenhum trace encontrado ainda."})
|
| 383 |
+
lines = TRACES_PATH.read_text().strip().splitlines()
|
| 384 |
+
push_to_hub()
|
| 385 |
+
return JSONResponse(content={"ok": True, "traces_published": len(lines)})
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
# βββ Launch ββββββββββββββββββββββββββββββββββββββββββββ
|
| 389 |
+
|
| 390 |
+
if __name__ == "__main__":
|
| 391 |
+
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
| 392 |
+
PHOTOS_DIR.mkdir(parents=True, exist_ok=True)
|
| 393 |
+
app.launch(
|
| 394 |
+
server_name="0.0.0.0",
|
| 395 |
+
server_port=int(os.environ.get("PORT", 7860)),
|
| 396 |
+
show_error=True,
|
| 397 |
+
)
|
index.html
CHANGED
|
@@ -1282,4 +1282,4 @@
|
|
| 1282 |
</script>
|
| 1283 |
<script src="/static/help-proof.js"></script>
|
| 1284 |
</body>
|
| 1285 |
-
<
|
|
|
|
| 1282 |
</script>
|
| 1283 |
<script src="/static/help-proof.js"></script>
|
| 1284 |
</body>
|
| 1285 |
+
</html>
|