Files
teams-whisper/app/review.py
pinokioandClaude Opus 5.5 4ff3e6fe14 Add Pinokio launcher for Teams meeting report pipeline
Pipeline code copied into app/; llama.py now uses launcher-local
llama.cpp (app/bin) and Qwen GGUF (app/models) instead of LM Studio.
install.js fetches ffmpeg, 7zip, llama.cpp CUDA 13, sherpa-onnx
diarization models, bge-m3 and Qwen3.6-35B-A3B, then pre-builds the
uv script environments. start.js serves the GUI on fixed port 18765
(hardcoded in the browser extension). reset.js keeps app/out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 21:29:33 +01:00

118 lines
5.2 KiB
Python

# /// script
# dependencies = []
# ///
"""Quality gate for meeting reports. uv run --script review.py <name> [<name>...]; exit 1 if any fails. No network/LLM."""
import base64, json, re, struct, sys
import db
from report import TICKET, _key, _sim
from shots import CONTENT_KINDS
ENG = {"the", "and", "of", "with", "is", "shows", "showing", "screenshot", "meeting", "displays"}
ITA = {"il", "la", "di", "che", "con", "della", "viene", "mostra", "sono", "per"}
def english(s):
w = re.findall(r"[a-zà-ú]+", str(s).lower())
e, i = sum(x in ENG for x in w), sum(x in ITA for x in w)
return e >= 3 and e > i
def jpeg_w(p):
b = p.read_bytes(); i = 2
while i < len(b):
if b[i] != 0xFF: i += 1; continue
m = b[i + 1]
if m in (0xC0, 0xC1, 0xC2): return struct.unpack(">H", b[i + 7:i + 9])[0]
i += 2 + struct.unpack(">H", b[i + 2:i + 4])[0]
return 0
def review(name):
d = db.out_dir(name)
rep = json.loads((d / "report.json").read_text(encoding="utf-8"))
md = (d / "report.md").read_text(encoding="utf-8")
html = (d / "report.html").read_text(encoding="utf-8")
shots = json.loads((d / "shots.json").read_text(encoding="utf-8")) if (d / "shots.json").exists() else []
docs = json.loads((d / "docs.json").read_text(encoding="utf-8")) if (d / "docs.json").exists() else None
items = (docs or {}).get("items", [])
fails = []
F = lambda code, detail: fails.append(f"FAIL {code} {str(detail)[:200]}")
for m in re.finditer(r"\bSpeaker \d+\b", md): F("R1", md[max(0, m.start() - 40):m.end() + 40].replace("\n", " "))
T, dur = rep["topics"], rep["duration_s"]
if not max(3, dur / 900) <= len(T) <= max(4, dur / 150): F("R2", f"{len(T)} topics for {dur / 60:.0f} min")
for t in T[:-1]:
if t["end_s"] - t["start_s"] < 120: F("R2", f"short topic {t['title']} {t['end_s'] - t['start_s']}s")
for t in T:
for x in t["shown"]:
m = re.search(r"(\d\d):(\d\d)", x)
if not m or not t["start_s"] - 30 <= int(m[1]) * 60 + int(m[2]) <= t["end_s"] + 30: F("R3", f"{t['title']}: {x}")
byfile = {}
for s in shots: byfile[s["file"]] = byfile[s.get("view") or s["file"]] = s
for sec in re.split(r"\n(?=## )", md):
imgs = re.findall(r"!\[[^\]]*\]\(shots/([^)]+)\)", sec)
if len(imgs) > 2: F("R4", f">2 images in {sec[:40]!r}")
used = re.findall(r"!\[[^\]]*\]\(shots/([^)]+)\)", md)
for f in used:
if byfile.get(f, {}).get("kind") not in CONTENT_KINDS: F("R4", f"{f} kind {byfile.get(f, {}).get('kind')}")
if any((s.get("view") or "").startswith("view_") for s in shots):
for f in used:
if not f.startswith("view_"): F("R4", f"uncropped image {f}")
texts = list(rep["tldr"])
for t in T:
texts += [x["text"] if isinstance(x, dict) else x for x in t["summary"]] + [x["text"] for x in t.get("from_docs", [])]
texts += [s.get("summary") or "" for s in t["shots"]]
for x in texts:
if english(x): F("R5", x)
sec = re.search(r"## Partecipanti\n(.*?)(?=\n## )", md, re.S)
people = []
for l in (sec[1].splitlines() if sec else []):
if l.startswith("|"):
c = l.split("|")[1].strip()
if c not in ("Partecipante", "") and not c.startswith("-"): people.append(c)
elif l.strip() and not l.startswith("*"): people += [x.strip() for x in l.split(",")]
for p in people:
if re.fullmatch(r"[A-Z]{1,3}", p) or "..." in p or "…" in p: F("R6", f"initials/truncated {p}")
for i, a in enumerate(people):
for b in people[i + 1:]:
if _sim(a, b) >= 0.82: F("R6", f"{a} ~ {b}")
S = rep["shares"]
for s in S:
if s["end"] - s["start"] < 20: F("R7", f"short share {s}")
for a, b in zip(S, S[1:]):
if a["who"] == b["who"] and b["start"] - a["end"] <= 60: F("R7", f"mergeable {a['who']} {a['end']}->{b['start']}")
rs = re.search(r"\*\*Ticket\*\*\n\n(.*?)(?=\n\n|\Z)", md, re.S)
ok = ({x["key"] for x in items if x["source"] == "jira" and x.get("mentioned")} if docs is not None
else {x["key"] for x in rep["references"]["tickets"]})
for k in re.findall(r"\[([A-Z][A-Z0-9]+-\d+)\]", rs[1] if rs else ""):
if k not in ok: F("R8", f"ticket {k}")
if "Numeri a schermo" in md or "**Email**" in md: F("R8", "numbers/email lists present")
if items:
if "## Documentazione correlata" not in md: F("R9", "missing Documentazione correlata")
urls = {x["url"] for x in items}
for u in re.findall(r"\[📄\]\(([^ )]+)", md):
if u not in urls: F("R9", f"citation url not in docs {u}")
if 'src="shots/' in html: F("R10", "unembedded image")
for b in re.findall(r"data:image/jpeg;base64,([A-Za-z0-9+/=]+)", html):
if len(base64.b64decode(b)) <= 5000: F("R10", "tiny image")
if "## Trascrizione" in md: F("R11", "transcript present")
for f in set(used):
if f.startswith("view_") and jpeg_w(d / "shots" / f) < 600: F("R12", f"{f} narrow {jpeg_w(d / 'shots' / f)}px")
print("\n".join(f"[{name}] {x}" for x in fails))
print(f"{name}: " + ("PASS" if not fails else f"{len(fails)} failures"))
return not fails
if __name__ == "__main__":
sys.stdout.reconfigure(encoding="utf-8")
sys.exit(0 if all([review(n) for n in sys.argv[1:]]) else 1)