report: less repetition, cleaner shots, correct speakers

- docs/memory passes get the facts already reported, so topics stop repeating them
- regroup pass merges consecutive topics on the same subject
- shots: settle 1.5s after a scene change, yuvj444p, no duplicate screen per topic,
  click-to-zoom in report.html, OCR identifier misreads fixed by majority vote
- speakers: split diarized paragraphs where Teams captions change speaker
- talk time from those paragraphs, counting only detected speech
This commit is contained in:
Stefano Zini
2026-11-10 14:23:59 +01:00
parent b80207a186
commit 3f020cd246
5 changed files with 408 additions and 79 deletions
+90 -7
View File
@@ -38,6 +38,9 @@ CONTENT_KINDS = {
}
# Crop frames to the model-reported shared-content box (see _view).
CROP_BOX = True
# Seconds after a scene change before grabbing the frame: slide/tab swipe animations and Teams' share re-sharpening are over by then.
# A candidate followed by another change within SETTLE s is mid-transition and skipped.
SETTLE = 1.5
# Allowed values for 'kind'; also the grammar enum in SCHEMA.
KINDS = [
"slide",
@@ -108,11 +111,11 @@ PROMPT = (
+ "|".join(KINDS)
+ '","title":str|null,"app":str|null,"summary":str,"text":str,'
'"entities":{"systems":[str],"tickets":[str],"urls":[str],"numbers":[str],"terms":[str]},"people":[str],"presenter":str|null,"meeting_title":str|null,"content_box":[x1,y1,x2,y2]|null}\n'
"Look ONLY at the shared screen content: ignore the browser bookmarks bar, OS taskbar, Teams toolbar, video tiles and captions, except for people/presenter/meeting_title.\n"
"Look ONLY at the shared screen content: ignore the browser bookmarks bar, OS taskbar, Teams toolbar, video tiles, captions and notification pop-ups/toasts (chat messages, meeting reminders), except for people/presenter/meeting_title.\n"
"- kind: type of the shared content; video_tiles ONLY if no screen is shared (just participant videos), chat for a chat panel.\n"
'- title: the visible heading of the shared content: slide title, page/document title, active browser tab title or window title (e.g. "Sprint Review Q3 - Backlog"). null only if no title is readable.\n'
'- title: the heading written inside the shared content: slide title, diagram or document heading, page title (e.g. "Sprint Review Q3 - Backlog"). Use the active browser tab or window title only when the content has no heading. null only if no title is readable.\n'
'- app: application or website shown (e.g. "Confluence", "Grafana", "Excel").\n'
"- summary: in italiano, massimo 40 parole: cosa si vede (nomi concreti: progetti, ambienti, servizi, valori) e perché conta. Inizia direttamente con il contenuto.\n"
"- summary: in italiano, massimo 40 parole: cosa si vede (nomi concreti: progetti, ambienti, servizi, valori). Inizia direttamente con il contenuto; niente frasi finali di commento (es. «utile per…», «serve a…»).\n"
"- text: important visible text copied verbatim (headings, bullets, table rows with values, code lines, errors, form values), max 1500 characters, keep line breaks.\n"
"- entities.systems: every product/tool/service/platform name visible (e.g. GitLab, Grafana, Azure, PostgreSQL); tickets: issue keys like ABC-123; urls; numbers: business figures with their label; terms: technical words useful for a glossary.\n"
'- people: full names (first and last) on video tiles/name tags, never initials. presenter: name in a "Contenuto condiviso da"/"Content shared by" label. meeting_title: the Teams meeting name (Teams window title bar or meeting header, never the title of the shared content); null if not visible.\n'
@@ -280,7 +283,7 @@ def _view(path, content_box):
return path.name
crop_path = path.with_name(f"view_{path.stem}.jpg")
image.crop((int(left), int(top), int(right), int(bottom))).convert("RGB").save(
crop_path, quality=90
crop_path, quality=95, subsampling=0
)
return crop_path.name
@@ -306,6 +309,65 @@ def _times(video, scene, bars=None):
return [float(match) for match in re.findall(r"pts_time:([\d.]+)", result.stderr)]
# Fix rare OCR misreads inside identifiers by majority vote on their parts: 'sap-infra-iac'/'sep-env-dev' lose to 'scp-' seen on more frames.
# ponytail: hyphenated identifiers only (plain words like componente/components are real variants); one letter differs, never a digit or case.
def _fix_spelling(rows, fields=("title", "summary", "text")):
def strings(row):
return [row.get(field) or "" for field in fields] + [
item for items in (row.get("entities") or {}).values() for item in items if isinstance(item, str)
]
def identifiers(text):
return [token for token in re.findall(r"\w+(?:-\w+)+", text) if len(token) >= 6]
# Frames each identifier part ('scp', 'infra', 'iac') appears on.
counts = collections.Counter(
part
for row in rows
for part in {
part
for text in strings(row)
for token in identifiers(text)
for part in token.split("-")
if len(part) >= 3
}
)
fixes = {}
for rare, rare_count in counts.items():
for common, common_count in counts.most_common():
if common_count < max(3, 2 * rare_count):
break
diff = [(a, b) for a, b in zip(rare, common) if a != b]
if (
len(rare) == len(common)
and len(diff) == 1
and diff[0][0].isalpha()
and diff[0][1].isalpha()
and diff[0][0].lower() != diff[0][1].lower()
):
fixes[rare] = common
break
if not fixes:
return
def fix(text):
return re.sub(
r"\w+(?:-\w+)+",
lambda match: "-".join(fixes.get(part, part) for part in match[0].split("-"))
if len(match[0]) >= 6
else match[0],
text,
)
for row in rows:
for field in fields:
if row.get(field):
row[field] = fix(row[field])
for key, items in (row.get("entities") or {}).items():
row["entities"][key] = [fix(item) if isinstance(item, str) else item for item in items]
print("shots: spelling fixes", fixes, flush=True)
# Extract scene-change keyframes, dedupe, read each with the VLM, write shots.json and glossary, derive share/presence events.
def run(name, max_frames=60, scene=0.05):
import imagehash
@@ -338,7 +400,10 @@ def run(name, max_frames=60, scene=0.05):
)[0]
or 0,
)
for timestamp in _times(video, scene, bars):
times = _times(video, scene, bars)
for timestamp, next_change in zip(times, [*times[1:], float("inf")]):
if next_change - timestamp <= SETTLE:
continue # transitional: the next change follows within SETTLE s
frame_path = shots_dir / f"shot_{int(timestamp) // 60:02d}m{int(timestamp) % 60:02d}s.jpg"
if any(kept_frame[1] == frame_path for kept_frame in kept):
continue # same second as a kept frame
@@ -349,14 +414,16 @@ def run(name, max_frames=60, scene=0.05):
"-v",
"error",
"-ss",
str(timestamp),
str(timestamp + SETTLE),
"-i",
str(video),
"-frames:v",
"1",
*(["-vf", bars] if bars else []),
"-q:v",
"3",
"2",
"-pix_fmt",
"yuvj444p",
str(frame_path),
],
check=True,
@@ -408,6 +475,7 @@ def run(name, max_frames=60, scene=0.05):
)[0]
if duration is None:
duration = rows[-1]["t"] + 60 if rows else 0
_fix_spelling(rows)
prev = None
# lead=False when a row repeats the previous kind+title (continuation of the same topic).
for index, row in enumerate(rows):
@@ -482,3 +550,18 @@ def run(name, max_frames=60, scene=0.05):
if last:
events.append((duration, "share_stop", "video", last, ""))
db.add_events(name, events)
if __name__ == "__main__":
# Self-check: a one-letter OCR misread loses to the spelling seen on more frames, unrelated identifiers survive.
shots = [
{"title": "scp-infra-iac", "summary": "", "text": "", "entities": {"systems": ["scp-env-dev"]}},
{"title": "scp-infra-iac", "summary": "pipeline scp-env-dev", "text": "", "entities": {}},
{"title": "scp-infra-iac", "summary": "", "text": "stage1-deploy", "entities": {}},
{"title": "sap-infra-iac", "summary": "", "text": "stage2-deploy", "entities": {"systems": ["sep-env-dev"]}},
]
_fix_spelling(shots)
assert shots[3]["title"] == "scp-infra-iac", shots[3]
assert shots[3]["entities"]["systems"] == ["scp-env-dev"], shots[3]
assert shots[2]["text"] == "stage1-deploy" and shots[3]["text"] == "stage2-deploy" # digits never voted away
print("ok")