GUI: upload, live progress + ETA, delete; report thinking; docs twg fix
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
edb8ee3731
commit
cbe111bc34
@@ -1,5 +1,5 @@
|
||||
"""SQLite index of meetings (out/meetings.db) + shared helpers."""
|
||||
import json, re, sqlite3
|
||||
import json, re, sqlite3, time
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).parent
|
||||
@@ -95,12 +95,86 @@ def out_dir(name) -> Path:
|
||||
return d
|
||||
|
||||
|
||||
# ---- progress + ETA (flow writes out/<name>/progress.json, server reads it) ----
|
||||
ORDER = ["audio", "transcribing", "diarizing", "identifying", "shots", "docs", "report", "memory"] # step statuses
|
||||
FROM = {"audio": "audio", "transcribe": "transcribing", "diarize": "diarizing", "speakers": "identifying",
|
||||
"shots": "shots", "docs": "docs", "report": "report", "memory": "memory", "render": "memory"}
|
||||
STATS = OUT / "step_stats.json"
|
||||
# seconds of work per minute of audio, measured 2026-11-02 on RTX 500 Ada 4 GB + Core Ultra 7 155H (40-min call);
|
||||
# replaced by a moving average of real runs as soon as one finishes (keys "<step>" or "<step>@<model>")
|
||||
SPM = {"audio": 1, "transcribing": 6, "diarizing": 9, "identifying": 1, "shots@qwen4b": 23, "shots@qwen35b": 48, "shots": 30,
|
||||
"docs": 2, "report@qwen35b": 21, "report@qwen4b": 7, "report": 15, "memory": 1}
|
||||
|
||||
|
||||
def _jload(p, default):
|
||||
try: return json.loads(p.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError): return default
|
||||
|
||||
|
||||
def _jsave(p, o):
|
||||
tmp = p.with_suffix(".tmp"); tmp.write_text(json.dumps(o), encoding="utf-8")
|
||||
try: tmp.replace(p)
|
||||
except OSError: pass # reader had it open: next tick writes again
|
||||
|
||||
|
||||
def spm(key):
|
||||
return {**SPM, **_jload(STATS, {})}.get(key) or SPM.get(key.split("@")[0], 5)
|
||||
|
||||
|
||||
def delete_recording(name):
|
||||
"""Remove a meeting everywhere: DB rows in every table keyed by name, out/<name>/ and out/<name>.* files."""
|
||||
import shutil
|
||||
c = connect()
|
||||
for t in ("recordings", "lines", "shots", "shot_text", "topics", "call_events", "speaker_map", "memory"):
|
||||
c.execute(f"DELETE FROM {t} WHERE name=?", (name,))
|
||||
shutil.rmtree(OUT / name, ignore_errors=True)
|
||||
for p in OUT.glob(f"{name}.*"): p.unlink(missing_ok=True)
|
||||
|
||||
|
||||
def progress(name):
|
||||
return _jload(OUT / name / "progress.json", None)
|
||||
|
||||
|
||||
def progress_start(name, start_from):
|
||||
now = time.time()
|
||||
_jsave(out_dir(name) / "progress.json", {"run_start": now, "start": FROM.get(start_from, "audio"), "step": None, "key": None,
|
||||
"step_start": now, "done": 0, "total": 0, "note": "", "updated": now, "steps": []})
|
||||
|
||||
|
||||
def step(name, status, key=None):
|
||||
"""Close the previous step (learn its speed), open `status` ("done" closes the run)."""
|
||||
set_status(name, status)
|
||||
p = progress(name)
|
||||
if not p: return
|
||||
now = time.time()
|
||||
if p["step"]:
|
||||
p["steps"].append([p["step"], p["step_start"], now])
|
||||
row = connect().execute("SELECT duration_s FROM recordings WHERE name=?", (name,)).fetchone()
|
||||
mins = (row[0] or 0) / 60 if row else 0
|
||||
if mins > 1 and now - p["step_start"] > 5: # skip no-op steps
|
||||
st = _jload(STATS, {}); k = p["key"] or p["step"]; v = (now - p["step_start"]) / mins
|
||||
st[k] = round(v if k not in st else 0.5 * st[k] + 0.5 * v, 2); _jsave(STATS, st)
|
||||
p.update(step=None if status == "done" else status, key=key or status, step_start=now, done=0, total=0, note="", updated=now)
|
||||
_jsave(OUT / name / "progress.json", p)
|
||||
|
||||
|
||||
def tick(name, done, total, note=""):
|
||||
"""In-step progress; also the heartbeat the GUI uses to show the run is alive."""
|
||||
p = progress(name)
|
||||
if not p: return
|
||||
now = time.time()
|
||||
if done == 0 and total: p["t0"] = now # loop starts now: rate excludes model load / frame extraction before it
|
||||
p.update(done=done, total=total, note=note, updated=now)
|
||||
_jsave(OUT / name / "progress.json", p)
|
||||
|
||||
|
||||
def media(name):
|
||||
def first(*exts):
|
||||
for e in exts:
|
||||
p = OUT / f"{name}{e}"
|
||||
if p.exists(): return p
|
||||
return first(".webm", ".wav"), first(".webm", ".mp4")
|
||||
# audio source, video source; .mkv/.mov/.m4a/.mp3 come from GUI uploads (meet_*)
|
||||
return first(".webm", ".wav", ".mp4", ".mkv", ".mov", ".m4a", ".mp3"), first(".webm", ".mp4", ".mkv", ".mov")
|
||||
|
||||
|
||||
def add_events(name, rows):
|
||||
|
||||
Reference in New Issue
Block a user