"""Glue between the page and aitrace. Runs inside the browser (Pyodide); aitrace's own code is loaded from GitHub.""" import html import json import os from aitrace.core import ALWAYS, INFO, MODERATE, STRONG, WEAK, inspect ORDER = {STRONG: 0, MODERATE: 1, WEAK: 2, INFO: 3} TONE = {"DECLARED AI-GENERATED": "red", "DECLARED SYNTHETIC": "red", "AI PRODUCT NAMED": "amber", "CAMERA ORIGIN CLAIMED, WITH CONTENT CREDENTIALS": "green", "CONTENT CREDENTIALS PRESENT": "green", "CAMERA METADATA PRESENT": "blue", "EDITING OR ENCODING SOFTWARE NAMED": "blue"} def check(path, name): rep = inspect(path) e = html.escape dims = f", {rep.width}×{rep.height}" if rep.width and rep.height else "" out = [f'
{e(rep.verdict)}
', f'

{e(rep.summary)}

{e(name)} · {e(rep.format)}{dims} · {rep.size_bytes:,} bytes

'] if rep.findings: out.append('

What was found

") out.append(f'

{e(ALWAYS)}

') meta = json.dumps(rep.metadata, indent=1, ensure_ascii=False, default=str) if rep.metadata else "No metadata was read from this file." return json.dumps({"html": "\n".join(out), "meta": meta})