Spaces:
Running
Running
sara.mesquita commited on
Commit ·
ee32f51
1
Parent(s): 77c7fef
adds logs for caring is sharing badge
Browse files
app.py
CHANGED
|
@@ -21,6 +21,7 @@ from core.ai import AnimalAI
|
|
| 21 |
from core.database import Database, DATA_DIR, PHOTOS_DIR
|
| 22 |
from core.matcher import AnimalMatcher
|
| 23 |
from core.seed import seed_if_empty
|
|
|
|
| 24 |
|
| 25 |
logging.basicConfig(level=logging.INFO)
|
| 26 |
db = Database()
|
|
@@ -155,6 +156,13 @@ def analyze_image(image_path: FileData) -> dict:
|
|
| 155 |
}
|
| 156 |
_cleanup_sessions()
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
return {
|
| 159 |
"session_id": session_id,
|
| 160 |
"description": description,
|
|
@@ -232,7 +240,7 @@ def confirm_sighting(
|
|
| 232 |
breed if breed and breed.lower() not in ("srd", "unknown", "") else "",
|
| 233 |
])).strip() or ("Cão" if species == "dog" else "Gato")
|
| 234 |
|
| 235 |
-
|
| 236 |
"animal_id": animal_id,
|
| 237 |
"is_new": is_new,
|
| 238 |
"count": count,
|
|
@@ -243,6 +251,19 @@ def confirm_sighting(
|
|
| 243 |
"time": datetime.datetime.now().strftime("%H:%M"),
|
| 244 |
}
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
def _cleanup_sessions():
|
| 248 |
cutoff = time.time() - 1800 # 30 min
|
|
|
|
| 21 |
from core.database import Database, DATA_DIR, PHOTOS_DIR
|
| 22 |
from core.matcher import AnimalMatcher
|
| 23 |
from core.seed import seed_if_empty
|
| 24 |
+
from core.tracer import log_trace
|
| 25 |
|
| 26 |
logging.basicConfig(level=logging.INFO)
|
| 27 |
db = Database()
|
|
|
|
| 156 |
}
|
| 157 |
_cleanup_sessions()
|
| 158 |
|
| 159 |
+
log_trace({
|
| 160 |
+
"event": "analyze",
|
| 161 |
+
"session_id": session_id,
|
| 162 |
+
"description": {k: v for k, v in description.items() if k not in ("_ai_success",)},
|
| 163 |
+
"top_matches": [{"id": m["id"], "score_pct": m["score_pct"]} for m in similar],
|
| 164 |
+
})
|
| 165 |
+
|
| 166 |
return {
|
| 167 |
"session_id": session_id,
|
| 168 |
"description": description,
|
|
|
|
| 240 |
breed if breed and breed.lower() not in ("srd", "unknown", "") else "",
|
| 241 |
])).strip() or ("Cão" if species == "dog" else "Gato")
|
| 242 |
|
| 243 |
+
result = {
|
| 244 |
"animal_id": animal_id,
|
| 245 |
"is_new": is_new,
|
| 246 |
"count": count,
|
|
|
|
| 251 |
"time": datetime.datetime.now().strftime("%H:%M"),
|
| 252 |
}
|
| 253 |
|
| 254 |
+
log_trace({
|
| 255 |
+
"event": "confirm",
|
| 256 |
+
"session_id": session_id,
|
| 257 |
+
"animal_id": animal_id,
|
| 258 |
+
"is_new": is_new,
|
| 259 |
+
"species": species,
|
| 260 |
+
"sighting_count": count,
|
| 261 |
+
"gps": {"lat": lat, "lng": lng},
|
| 262 |
+
"description": desc_obj,
|
| 263 |
+
})
|
| 264 |
+
|
| 265 |
+
return result
|
| 266 |
+
|
| 267 |
|
| 268 |
def _cleanup_sessions():
|
| 269 |
cutoff = time.time() - 1800 # 30 min
|