Spaces:
Sleeping

MichaWehrli commited on
Commit
ce3441e
·
verified ·
1 Parent(s): fab61ba

Sync from GitHub c0f5c21

Browse files
Files changed (3) hide show
  1. CHANGELOG.md +8 -0
  2. README.md +3 -0
  3. gradio_app.py +63 -4
CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
  # CollemBot — changelog
2
 
 
 
 
 
 
 
 
 
3
  ## v0.2.2 (2026-10-28) — desktop version
4
  Changes AI-assisted (Claude Opus 5.5); maintainer review pending.
5
 
 
1
  # CollemBot — changelog
2
 
3
+ ## v0.2.3 (2026-10-28) — anonymous usage log
4
+ Changes AI-assisted (Claude Opus 5.5); maintainer review pending.
5
+
6
+ - One log line per analysis (Compare groups, Hand correction, Calibrate threshold), shown in the Space's Logs tab (desktop: in its own window), e.g. `[CollemBot usage] 2026-10-28 10:41 UTC | compare | browser | 3 image(s) | 42 s | ok`.
7
+ - Logged: UTC time (minute), tab, client type (`browser`, `script` = API client, `other`), number of images, run time, ok/error. Not logged: IP address, user-agent text, file names, image content, session or user IDs. Client type is derived from request headers; only the one word is kept.
8
+ - Purpose: to see whether the Space is used by people in the browser or by scripts, and how much (GPU cost).
9
+ - Analysis code, results, CSV and ZIP unchanged; API endpoint names unchanged.
10
+
11
  ## v0.2.2 (2026-10-28) — desktop version
12
  Changes AI-assisted (Claude Opus 5.5); maintainer review pending.
13
 
README.md CHANGED
@@ -11,6 +11,7 @@ pinned: false
11
  # 🪲 COLLEMBOT — AI-based Collembola Counting for OECD 232
12
 
13
  **⚠️ Beta — validate counts before use in publications.**
 
14
  Version 0.2.2 (2026-10-28): desktop version (same app, runs on your own computer); counts unchanged from 0.2.0.
15
  Version 0.2.1 (2026-10-28): title page with a usage notice.
16
  Version 0.2.0 (2026-10-20): overlapping detections are now merged exactly as in the published pipeline (base repository `scripts/run_inference.py`). Counts differ from 0.1.x — see CHANGELOG.md.
@@ -21,6 +22,8 @@ COLLEMBOT is a free, open-source tool for automated counting and body-size measu
21
 
22
  Published in *Environmental Toxicology and Chemistry* (2026) · DOI: [10.1093/etojnl/vgag068](https://doi.org/10.1093/etojnl/vgag068)
23
 
 
 
24
  ---
25
 
26
  ## Tabs
 
11
  # 🪲 COLLEMBOT — AI-based Collembola Counting for OECD 232
12
 
13
  **⚠️ Beta — validate counts before use in publications.**
14
+ Version 0.2.3 (2026-10-28): anonymous usage log (see Privacy).
15
  Version 0.2.2 (2026-10-28): desktop version (same app, runs on your own computer); counts unchanged from 0.2.0.
16
  Version 0.2.1 (2026-10-28): title page with a usage notice.
17
  Version 0.2.0 (2026-10-20): overlapping detections are now merged exactly as in the published pipeline (base repository `scripts/run_inference.py`). Counts differ from 0.1.x — see CHANGELOG.md.
 
22
 
23
  Published in *Environmental Toxicology and Chemistry* (2026) · DOI: [10.1093/etojnl/vgag068](https://doi.org/10.1093/etojnl/vgag068)
24
 
25
+ **Privacy and usage log:** for functional analysis purposes only (to understand how CollemBot is used and what it costs to run), the app logs very basic data for each analysis: the time (to the minute), the tab, whether the analysis was started in a browser or by a script, the number of images, the run time and whether it finished. **No personal data is logged**: no IP addresses, no browser or device details, no file names, no image content, and no user or session IDs, so log entries cannot be traced back to a person. The desktop version prints the same line only to its own window on your computer.
26
+
27
  ---
28
 
29
  ## Tabs
gradio_app.py CHANGED
@@ -1922,7 +1922,7 @@ def _make_batch_thumbnail(
1922
  # AI-assisted (Claude Opus 5.5, 2026-10-20); reviewed by: <pending>.
1923
  # Nothing in this block changes detection, fusion or counting.
1924
 
1925
- APP_VERSION = "0.2.2"
1926
 
1927
  # v0.2.1: title page shown before the app (interface text only).
1928
  USAGE_NOTICE_MD = """
@@ -1988,6 +1988,61 @@ def _title_page_default() -> bool:
1988
  value = os.environ.get("COLLEMBOT_TITLE_PAGE", "1").strip().lower()
1989
  return value not in ("0", "false", "no", "off")
1990
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1991
  SCALE_HELP = (
1992
  "Measure once per camera setup in ImageJ/Fiji: draw a straight line between "
1993
  "two ruler marks a known distance apart, Analyze > Measure, then "
@@ -2639,7 +2694,8 @@ def launch_app(
2639
  )
2640
 
2641
  btn2.click(
2642
- fn=_compare,
 
2643
  inputs=[multi_files, labels_inp, px_per_mm_c, conf_slider2],
2644
  outputs=[out_plot, out_csv2, out_table, out_gallery, out_zip],
2645
  )
@@ -2762,7 +2818,8 @@ def launch_app(
2762
  return state, canvas, df, tally
2763
 
2764
  btn_corr_run.click(
2765
- fn=_corr_run,
 
2766
  inputs=[corr_inp, conf_slider3],
2767
  outputs=[corr_state, corr_canvas, corr_df, corr_tally],
2768
  )
@@ -3112,7 +3169,9 @@ def launch_app(
3112
  return buf.name, result_md, best_th, gr.update(interactive=True)
3113
 
3114
  btn_calibrate.click(
3115
- fn=_run_calibration,
 
 
3116
  inputs=[
3117
  cal_inps[0], cal_counts[0], cal_scales[0],
3118
  cal_inps[1], cal_counts[1], cal_scales[1],
 
1922
  # AI-assisted (Claude Opus 5.5, 2026-10-20); reviewed by: <pending>.
1923
  # Nothing in this block changes detection, fusion or counting.
1924
 
1925
+ APP_VERSION = "0.2.3"
1926
 
1927
  # v0.2.1: title page shown before the app (interface text only).
1928
  USAGE_NOTICE_MD = """
 
1988
  value = os.environ.get("COLLEMBOT_TITLE_PAGE", "1").strip().lower()
1989
  return value not in ("0", "false", "no", "off")
1990
 
1991
+
1992
+ # v0.2.3: anonymous usage log, one line per analysis (Space "Logs" tab / desktop console).
1993
+ # Logged: UTC time (minute), tab, client type, number of images, run time, ok/error.
1994
+ # Not logged: IP address, user-agent text, file names, image content, session or user IDs.
1995
+ _SCRIPT_AGENTS = ("gradio_client", "python", "httpx", "requests", "curl", "wget", "node")
1996
+
1997
+
1998
+ def _client_type(request) -> str:
1999
+ """'browser', 'script' (API client) or 'other'. Only this word is kept."""
2000
+ try:
2001
+ headers = {str(k).lower(): str(v) for k, v in dict(request.headers).items()}
2002
+ except Exception:
2003
+ return "other"
2004
+ agent = headers.get("user-agent", "").lower()
2005
+ if headers.get("x-gradio-user", "").lower() == "api" or any(s in agent for s in _SCRIPT_AGENTS):
2006
+ return "script"
2007
+ if agent.startswith("mozilla/"):
2008
+ return "browser"
2009
+ return "other"
2010
+
2011
+
2012
+ def _usage_logged(fn, tab: str, count_images):
2013
+ """Wrap an analysis function: same inputs and outputs, plus one anonymous log line.
2014
+ Gradio passes the request because the wrapper declares a gr.Request parameter."""
2015
+ import functools
2016
+ import inspect
2017
+ import time
2018
+
2019
+ sig = inspect.signature(fn)
2020
+ params = list(sig.parameters.values()) + [inspect.Parameter(
2021
+ "request", inspect.Parameter.POSITIONAL_OR_KEYWORD, default=None, annotation=gr.Request)]
2022
+ new_sig = sig.replace(parameters=params)
2023
+
2024
+ @functools.wraps(fn)
2025
+ def wrapper(*args, **kwargs):
2026
+ bound = new_sig.bind(*args, **kwargs)
2027
+ request = bound.arguments.pop("request", None)
2028
+ try:
2029
+ n_images = int(count_images(bound.arguments))
2030
+ except Exception:
2031
+ n_images = -1
2032
+ start, status = time.monotonic(), "error"
2033
+ try:
2034
+ result = fn(**bound.arguments)
2035
+ status = "ok"
2036
+ return result
2037
+ finally:
2038
+ stamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
2039
+ print(f"[CollemBot usage] {stamp} | {tab} | {_client_type(request)} | "
2040
+ f"{n_images} image(s) | {time.monotonic() - start:.0f} s | {status}", flush=True)
2041
+
2042
+ wrapper.__signature__ = new_sig
2043
+ wrapper.__annotations__ = {**getattr(fn, "__annotations__", {}), "request": gr.Request}
2044
+ return wrapper
2045
+
2046
  SCALE_HELP = (
2047
  "Measure once per camera setup in ImageJ/Fiji: draw a straight line between "
2048
  "two ruler marks a known distance apart, Analyze > Measure, then "
 
2694
  )
2695
 
2696
  btn2.click(
2697
+ fn=_usage_logged(_compare, "compare",
2698
+ lambda a: len(a.get("files") or [])),
2699
  inputs=[multi_files, labels_inp, px_per_mm_c, conf_slider2],
2700
  outputs=[out_plot, out_csv2, out_table, out_gallery, out_zip],
2701
  )
 
2818
  return state, canvas, df, tally
2819
 
2820
  btn_corr_run.click(
2821
+ fn=_usage_logged(_corr_run, "hand-correction",
2822
+ lambda a: int(a.get("pil_img") is not None)),
2823
  inputs=[corr_inp, conf_slider3],
2824
  outputs=[corr_state, corr_canvas, corr_df, corr_tally],
2825
  )
 
3169
  return buf.name, result_md, best_th, gr.update(interactive=True)
3170
 
3171
  btn_calibrate.click(
3172
+ fn=_usage_logged(_run_calibration, "calibration",
3173
+ lambda a: sum(a.get(k) is not None
3174
+ for k in ("img1", "img2", "img3"))),
3175
  inputs=[
3176
  cal_inps[0], cal_counts[0], cal_scales[0],
3177
  cal_inps[1], cal_counts[1], cal_scales[1],