Skip to content

Commit ccc823c

Browse files
committed
feat: add URL-auth eval export endpoint for WSI training pipeline
1 parent d479e55 commit ccc823c

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

‎admin_blueprint.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,3 +3965,58 @@ def api_eval_stats():
39653965
"ready": total >= 180,
39663966
"counts": counts,
39673967
})
3968+
3969+
@admin_bp.route('/api/eval-export-wsi/<secret>')
3970+
def api_eval_export_wsi(secret):
3971+
"""Standalone eval export with URL-based auth for training pipeline."""
3972+
import os as _os
3973+
expected = _os.getenv("ADMIN_API_KEY", "")
3974+
if not expected or secret != expected:
3975+
return jsonify({"error": "Unauthorized", "debug_key_set": bool(expected)}), 401
3976+
3977+
import io, zipfile
3978+
from flask import send_file
3979+
3980+
eval_dir = _os.getenv("EVAL_LOG_DIR", "data/eval_log")
3981+
subdirs = ["pr_reviews_public", "pr_reviews_internal", "bounty_evaluations",
3982+
"security_audits", "swarmsolve_audits", "task_verifications"]
3983+
3984+
fmt = request.args.get("format", "zip")
3985+
3986+
if fmt == "json":
3987+
import json as _json
3988+
all_evals = []
3989+
for subdir in subdirs:
3990+
path = _os.path.join(eval_dir, subdir)
3991+
if not _os.path.isdir(path):
3992+
continue
3993+
for fname in sorted(_os.listdir(path)):
3994+
if not fname.endswith(".json"):
3995+
continue
3996+
try:
3997+
with open(_os.path.join(path, fname)) as f:
3998+
record = _json.load(f)
3999+
record["_eval_type"] = subdir
4000+
all_evals.append(record)
4001+
except Exception:
4002+
continue
4003+
return jsonify({"total": len(all_evals), "evaluations": all_evals})
4004+
4005+
# Default: zip
4006+
buf = io.BytesIO()
4007+
file_count = 0
4008+
with zipfile.ZipFile(buf, "w", zipfile.ZIP_DEFLATED) as zf:
4009+
for subdir in subdirs:
4010+
path = _os.path.join(eval_dir, subdir)
4011+
if not _os.path.isdir(path):
4012+
continue
4013+
for fname in sorted(_os.listdir(path)):
4014+
if not fname.endswith(".json"):
4015+
continue
4016+
zf.write(_os.path.join(path, fname), _os.path.join(subdir, fname))
4017+
file_count += 1
4018+
if file_count == 0:
4019+
return jsonify({"error": "No eval data found", "eval_dir": eval_dir}), 404
4020+
buf.seek(0)
4021+
return send_file(buf, mimetype="application/zip", as_attachment=True, download_name="wsi_training_data.zip")
4022+

0 commit comments

Comments
 (0)