Hardware-aware install, per-step LLM profiles, tuned llama.cpp for 4 GB VRAM

Benchmarked on RTX 500 Ada 4 GB (~3.2 GB usable on Windows) + Core Ultra 7 155H.

- install.js: log GPU/VRAM/RAM, abort without NVIDIA >= 4 GB VRAM; always
  install Qwen3.5-4B Q4_K_S, Qwen3.6-35B-A3B only with >= 48 GB RAM.
- llama.py: model registry with vision (shots) and text (report/ask)
  profiles; KV q8, image tokens 1024-1536.
  - 35B: vision encoder on GPU, -ngl 30 (shot 142 -> ~50 s); text: -ub 2048.
  - 4B: vision encoder on GPU, FFN of layers 19-31 in RAM (shot 36 -> 22 s);
    text fully on GPU (~30 tok/s, report 4.5 min).
  - Per-step choice in out/llm.txt: default 4B for shots, biggest for report.
- flow.py: restart llama in text profile after shots (no mmproj for report).
- shots.py: prompt v3 (inline template + defined fields, Italian summary
  rules) and bounded json_schema; stops 4B loops, title 1/38 -> 36/38.
- server.py: shots/report model selects, POST /cancel + stop button, reaper
  thread that honours Prefect "Cancel" and closes runs whose process died.
- diarize.py: cut same-speaker paragraphs every 60 s (one 11-min paragraph
  truncated every report at 28:52); 8 threads; CUDA provider with CPU
  fallback via sherpa-onnx cuda12.cudnn9 wheel (CUDA path not yet verified).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pinokio
2026-11-02 15:20:19 +01:00
co-authored by Claude Opus 5.5
parent 4ff3e6fe14
commit a64d3fb275
10 changed files with 285 additions and 50 deletions
+27 -7
View File
@@ -7,11 +7,31 @@ _open = urllib.request.build_opener(urllib.request.ProxyHandler({})).open # cor
EMPTY = {"kind": "other", "title": None, "app": None, "summary": "", "text": "", "entities": {}, "people": [], "presenter": None, "meeting_title": None, "content_box": None}
CONTENT_KINDS = {"slide", "code", "terminal", "browser", "document", "spreadsheet", "diagram", "dashboard", "ticket"}
CROP_BOX = True
PROMPT = ('/no_think Screenshot from a Microsoft Teams meeting recording. Reply ONLY JSON: {"kind":"slide|code|terminal|browser|document|spreadsheet|diagram|dashboard|ticket|chat|video_tiles|other","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}. '
'summary: written in ITALIAN (never English), max 40 words, what is shown and why it matters. text: the important visible text copied verbatim (headings, bullet points, table rows, code lines, error messages, form values), max 1500 characters, line breaks kept; skip Teams UI chrome. '
'Consider ONLY the shared screen content: ignore browser bookmarks bar, tab titles, OS taskbar, Teams toolbar, video tiles and captions for systems/terms/urls/numbers. '
'systems: product/tool/service names; tickets: issue keys like ABC-123; numbers: business figures with their label; terms: technical words useful as a glossary. 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 only if visible. '
'content_box: bounding box of the shared screen content (the presenter\'s screen, slide or application window, excluding Teams toolbar, video tiles and caption area) in 0-1000 coordinates relative to this image, null if nothing is shared. Use [] or null when absent. Never invent.')
KINDS = ["slide", "code", "terminal", "browser", "document", "spreadsheet", "diagram", "dashboard", "ticket", "chat", "video_tiles", "other"]
_S, _N, _L = {"type": "string", "maxLength": 300}, {"type": ["string", "null"], "maxLength": 200}, {"type": "array", "items": {"type": "string", "maxLength": 120}, "maxItems": 25}
# json_schema -> llama.cpp grammar: valid JSON + valid kind every time (small models broke JSON / looped to max_tokens)
SCHEMA = {"type": "object", "additionalProperties": False,
"required": ["kind", "title", "app", "summary", "text", "entities", "people", "presenter", "meeting_title", "content_box"],
"properties": {"kind": {"enum": KINDS}, "title": _N, "app": _N, "summary": _S, "text": {"type": "string", "maxLength": 1500}, # bounds stop the 4B looping on table rows
"entities": {"type": "object", "additionalProperties": False, "required": ["systems", "tickets", "urls", "numbers", "terms"],
"properties": {k: _L for k in ("systems", "tickets", "urls", "numbers", "terms")}},
"people": _L, "presenter": _N, "meeting_title": _N,
"content_box": {"anyOf": [{"type": "array", "items": {"type": "integer"}, "minItems": 4, "maxItems": 4}, {"type": "null"}]}}}
# v3: v1's inline JSON template (the model never sees the grammar: v2 without it -> kind=video_tiles, title=null) + every field defined
# (v1 left title undefined), summary rules in Italian (v1 'ITALIAN' got echoed). Text before image: image-first measured worse.
PROMPT = ('Screenshot from a Microsoft Teams meeting recording. Reply ONLY JSON: {"kind":"' + '|'.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'
'- 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'
'- 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'
'- 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'
'- content_box: bounding box of the shared screen area (excluding Teams toolbar, video tiles, captions) in 0-1000 coordinates of this image; null if nothing is shared.\n'
'Never invent: use null or [] when absent.')
TICKET = re.compile(r"\b[A-Z][A-Z0-9]{1,9}-\d{1,6}\b")
URL = re.compile(r"""https?://[^\s)\]>"']+""")
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
@@ -19,11 +39,11 @@ EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
def _ask(path, json_mode=True):
img = base64.b64encode(path.read_bytes()).decode()
body = {"model": str(llama.MODEL), "max_tokens": 1200, "temperature": 0.1,
body = {"model": llama.current(True), "max_tokens": 1200, "temperature": 0.1,
"chat_template_kwargs": {"enable_thinking": False},
"messages": [{"role": "user", "content": [{"type": "text", "text": PROMPT},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + img}}]}]}
if json_mode: body["response_format"] = {"type": "json_object"}
if json_mode: body["response_format"] = {"type": "json_schema", "json_schema": {"name": "shot", "schema": SCHEMA}} if SCHEMA else {"type": "json_object"}
req = urllib.request.Request(API, json.dumps(body).encode(), {"Content-Type": "application/json"})
return json.load(_open(req, timeout=900))["choices"][0]["message"]["content"]