db/report/server/UI updates
This commit is contained in:
@@ -116,7 +116,7 @@ def set_meta(name, **kw):
|
||||
# ---- 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"}
|
||||
"shots": "shots", "docs": "docs", "report": "report", "memory": "memory", "render": "memory", "title": "memory"}
|
||||
STATS = GLOBAL / "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>")
|
||||
|
||||
@@ -332,6 +332,18 @@ def run(name, window_words=3000):
|
||||
db.replace_topics(name, topics)
|
||||
|
||||
|
||||
def retitle(name):
|
||||
"""Regenerate the meeting title from the saved topics (LLM overview pass); drops the manual title. Render is done by the caller."""
|
||||
p = db.out_dir(name) / "report.json"
|
||||
rep = json.loads(p.read_text(encoding="utf-8"))
|
||||
ov = chat(SYS_B, json.dumps([{"title": t["title"], "summary": [x["text"] for x in t["summary"]], "shown": t["shown"], "decisions": t["decisions"], "actions": t["actions"]} for t in rep["topics"]], ensure_ascii=False), 800, think=True) or {}
|
||||
t = str(ov.get("title") or "").strip()
|
||||
if not t: raise RuntimeError("title: nessun titolo generato")
|
||||
db.set_meta(name, title="")
|
||||
rep["meeting_title"] = t
|
||||
p.write_text(json.dumps(rep, ensure_ascii=False, indent=1), encoding="utf-8")
|
||||
|
||||
|
||||
def _head(i, t): return f"{i}. {t['title']} ({mmss(t['start_s'])}–{mmss(t['end_s'])})"
|
||||
|
||||
|
||||
|
||||
+27
-8
@@ -29,7 +29,7 @@ NOPROXY = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||||
EDGE = Path(os.path.expandvars(r"%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"))
|
||||
PRINT_CSS = "@media print{body{max-width:none;padding:0}img,tr{break-inside:avoid}h2,h3{break-after:avoid}}"
|
||||
LOCK = threading.Lock()
|
||||
STEPS = ["audio", "transcribe", "diarize", "speakers", "shots", "docs", "report", "memory", "render"]
|
||||
STEPS = ["audio", "transcribe", "diarize", "speakers", "shots", "docs", "report", "memory", "render", "title"]
|
||||
QUEUE = [] # (name, start_from, speakers) waiting for the single runner, oldest first
|
||||
BATCH = None # runner thread, None when idle
|
||||
QLOCK = threading.Lock()
|
||||
@@ -466,6 +466,14 @@ class H(BaseHTTPRequestHandler):
|
||||
else: self._send(b"not found", 404)
|
||||
def video(self, name):
|
||||
a, v = db.media(name); f = v or a
|
||||
if f and f.suffix == ".webm" and name not in R:
|
||||
# MediaRecorder webm has no duration/cues: the player treats it as an endless stream. Cache a stream-copy remux (header with length + seek index).
|
||||
pv = f.with_name("preview.webm")
|
||||
if not pv.exists() or pv.stat().st_mtime < f.stat().st_mtime:
|
||||
t = pv.with_suffix(".part.webm")
|
||||
if subprocess.run(["ffmpeg", "-y", "-v", "error", "-i", str(f), "-c", "copy", str(t)], capture_output=True).returncode == 0: t.replace(pv)
|
||||
else: t.unlink(missing_ok=True)
|
||||
if pv.exists(): f = pv
|
||||
if not f: return self._send(b"not found", 404)
|
||||
size = f.stat().st_size; lo, hi = 0, size - 1
|
||||
m = re.match(r"bytes=(\d*)-(\d*)$", self.headers.get("Range", ""))
|
||||
@@ -491,7 +499,10 @@ class H(BaseHTTPRequestHandler):
|
||||
try: s, e = float(q["start"]), float(q["end"])
|
||||
except (KeyError, ValueError): return self._send(b"bad times", 400)
|
||||
if not 0 <= s < e: return self._send("intervallo non valido".encode(), 400)
|
||||
new = "meet_" + time.strftime("%Y-%m-%dT%H-%M-%S"); ext = ".mp4" if v else ".m4a"
|
||||
inplace = q.get("inplace") == "1" # replace this meeting's source (and shift its call events) instead of creating a new meeting
|
||||
j = JOBS.get(name)
|
||||
if inplace and ((j and j.poll() is None) or any(x[0] == name for x in QUEUE)): return self._send("elaborazione in corso: ferma prima".encode(), 409)
|
||||
new = name if inplace else "meet_" + time.strftime("%Y-%m-%dT%H-%M-%S"); ext = ".mp4" if v else ".m4a"
|
||||
dst = db.out_dir(new) / f"source{ext}"; tmp = dst.with_name(f"source{ext}.part")
|
||||
enc = ["-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", "-c:v", "libx264", "-preset", "veryfast", "-crf", "23", "-pix_fmt", "yuv420p"] if v else ["-vn"]
|
||||
CROP[name] = 0
|
||||
@@ -501,13 +512,21 @@ class H(BaseHTTPRequestHandler):
|
||||
if ln.startswith("out_time_us=") and ln[12:].strip().lstrip("-").isdigit(): CROP[name] = min(99, max(0, int(ln[12:]) / 1e4 / (e - s)))
|
||||
err = p.stderr.read(); p.wait(); CROP.pop(name, None)
|
||||
r = type("R", (), {"returncode": p.returncode, "stderr": err})
|
||||
if r.returncode or not tmp.exists() or not tmp.stat().st_size:
|
||||
tmp.unlink(missing_ok=True); dst.parent.rmdir(); return self._send(f"ffmpeg: {r.stderr[-300:]}".encode(), 500)
|
||||
fail = lambda msg: (tmp.unlink(missing_ok=True), None if inplace else dst.parent.rmdir(), self._send(msg.encode(), 500))
|
||||
if r.returncode or not tmp.exists() or not tmp.stat().st_size: return fail(f"ffmpeg: {r.stderr[-300:]}")
|
||||
try: dur = db.duration(tmp)
|
||||
except ValueError as x: return fail(f"ritaglio non leggibile: {x}")
|
||||
if inplace:
|
||||
for f in (a, v, dst.with_name("preview.webm")):
|
||||
if f and f != dst: f.unlink(missing_ok=True)
|
||||
c = db.connect()
|
||||
c.execute("DELETE FROM call_events WHERE name=? AND (t<? OR t>?)", (name, s, e))
|
||||
c.execute("UPDATE call_events SET t=t-? WHERE name=?", (s, name))
|
||||
tmp.replace(dst)
|
||||
try: dur = db.duration(dst)
|
||||
except ValueError as x: dst.unlink(); dst.parent.rmdir(); return self._send(f"ritaglio non leggibile: {x}".encode(), 500)
|
||||
db.set_meta(new, upload=f"{title(name) or name} [{int(s)}s-{int(e)}s]")
|
||||
db.upsert_recording(new, source="upload", started_at=now(), status="queued", bytes=dst.stat().st_size, duration_s=dur)
|
||||
if inplace: db.upsert_recording(name, bytes=dst.stat().st_size, duration_s=dur, status="queued")
|
||||
else:
|
||||
db.set_meta(new, upload=f"{title(name) or name} [{int(s)}s-{int(e)}s]")
|
||||
db.upsert_recording(new, source="upload", started_at=now(), status="queued", bytes=dst.stat().st_size, duration_s=dur)
|
||||
launch(new, "audio")
|
||||
self._json({"name": new, "duration_s": dur})
|
||||
def upload(self, q):
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
<video id=cv controls preload=metadata></video>
|
||||
<div class=row style="margin-top:10px"><button onclick="cs.value=fmt(cv.currentTime)">⇤ inizio = qui</button><input class=tm id=cs value="00:00">
|
||||
<input class=tm id=ce><button onclick="ce.value=fmt(cv.currentTime)">fine = qui ⇥</button>
|
||||
<button onclick=cplay()>▶ anteprima ritaglio</button><button class=pri id=cgo_ onclick=cgo()>✂ Ritaglia e salva come nuova riunione</button></div>
|
||||
<button onclick=cplay()>▶ anteprima ritaglio</button><button class=pri id=cgo_ onclick="cgo(0)">✂ Ritaglia e salva come nuova riunione</button><button id=cgi_ onclick="cgo(1)">✂ Ritaglia e salva in questa riunione</button></div>
|
||||
<progress id=cpr max=100 value=0 hidden style="width:100%"></progress>
|
||||
<div id=cmsg>L'originale resta intatto: il ritaglio diventa una nuova riunione (mm:ss o h:mm:ss).</div></dialog>
|
||||
<script src=/ui.js></script>
|
||||
|
||||
@@ -18,6 +18,7 @@ th{font-size:12px;font-weight:600;color:var(--mut);text-transform:uppercase;lett
|
||||
.b{display:inline-block;padding:2px 10px;border-radius:99px;font-size:12px;font-weight:500;background:var(--gry);color:var(--gryf)}
|
||||
.recording,.error,.cancelled{background:var(--red);color:var(--redf)}.audio,.transcribing,.diarizing,.identifying,.shots,.docs,.report,.memory{background:var(--amb);color:var(--ambf)}.done{background:var(--grn);color:var(--grnf)}
|
||||
a{color:var(--acc);cursor:pointer;margin-right:10px;text-decoration:none}a:hover{text-decoration:underline}small{color:var(--mut)}.sp td{background:var(--soft)}.sp div{margin-bottom:8px}
|
||||
.sp .sa{display:flex;gap:8px;justify-content:flex-end;margin-top:12px;padding-top:12px;border-top:1px solid var(--line)}.sp .sa button{padding:7px 16px;font-weight:500}.sp td{padding:14px 16px}
|
||||
td button,td select{margin:0 4px 4px 0}#qs{color:var(--mut)}
|
||||
.pg{padding:14px 16px 12px;background:var(--soft);border:1px solid var(--line);border-radius:12px;margin:0 0 8px}
|
||||
.pgh{display:flex;justify-content:space-between;align-items:baseline;gap:12px;flex-wrap:wrap;margin-bottom:8px}.pgh b{font-size:15px}.pgh .n{color:var(--mut)}
|
||||
|
||||
+10
-7
@@ -25,9 +25,10 @@ async function spk(n){editing=false;open_.has(n)?open_.delete(n):open_.add(n);ti
|
||||
async function panel(n){const j=await (await fetch("/speakers?name="+n)).json();
|
||||
return `<tr class=sp><td colspan=7><datalist id="cand-${n}">${j.candidates.map(c=>`<option value="${E(c)}">`).join("")}</datalist>`+
|
||||
j.rows.map(r=>`<div><b>${E(r.label)}</b> ${fmt(r.talk_s)} <input data-n="${n}" data-l="${E(r.label)}" list="cand-${n}" value="${E(r.person)}"> ${r.source}${r.source=="auto"&&r.overlap_s!=null?" "+Math.round(r.overlap_s)+"s":""}<br><small>${r.samples.map(E).join(" | ")}</small></div>`).join("")+
|
||||
`<button onclick="saveSpk('${n}')">salva nomi</button>`}
|
||||
`<div class=sa><button class=pri onclick="saveSpk('${n}')">✓ Salva nomi</button><button onclick="spk('${n}')">✕ Chiudi</button></div>`}
|
||||
async function saveSpk(n){const m={};document.querySelectorAll(`input[data-n="${n}"]`).forEach(i=>m[i.dataset.l]=i.value);
|
||||
const r=await fetch("/speaker_map?name="+n,{method:"POST",body:JSON.stringify(m)});editing=false;alert(await r.text())}
|
||||
const r=await fetch("/speaker_map?name="+n,{method:"POST",body:JSON.stringify(m)});editing=false;const t=await r.text();open_.delete(n);tick();alert(t)}
|
||||
async function retitle(n){const r=await fetch(`/run?name=${n}&from=title`,{method:"POST"});if(!r.ok)alert(await r.text());tick()}
|
||||
const sel={};
|
||||
async function del_(n,label){if(!confirm(`Eliminare definitivamente "${label}"?
|
||||
Vengono cancellati registrazione, trascrizione, schermate e report. Non si può annullare.`))return;
|
||||
@@ -42,12 +43,14 @@ function play(n,d,t){cv.src="/video?name="+n;ctitle.textContent=t;cs.value="00:0
|
||||
function cclose(){cv.pause();cv.removeAttribute("src");cv.load();cdlg.close()}
|
||||
cdlg.addEventListener("cancel",cclose);
|
||||
function cplay(){cv.currentTime=sec(cs.value);cv.play();const e=sec(ce.value);cv.ontimeupdate=()=>{if(e>0&&cv.currentTime>=e){cv.pause();cv.ontimeupdate=null}}}
|
||||
async function cgo(){const a=sec(cs.value),b=sec(ce.value),n=new URL(cv.src).searchParams.get("name");
|
||||
async function cgo(inplace){const a=sec(cs.value),b=sec(ce.value),n=new URL(cv.src).searchParams.get("name");
|
||||
if(!(a>=0&&b>a)){cmsg.textContent="intervallo non valido";return}
|
||||
cgo_.disabled=true;cmsg.textContent="ritaglio in corso… (ricodifica, può richiedere minuti)";cpr.value=0;cpr.hidden=false;
|
||||
if(inplace&&!confirm("Sostituire il video di questa riunione con il ritaglio? L'originale va perso e la riunione viene rielaborata da zero."))return;
|
||||
if(inplace){cv.pause();cv.removeAttribute("src");cv.load()} // release the file: Windows can't replace a source the browser has open
|
||||
cgo_.disabled=cgi_.disabled=true;cmsg.textContent="ritaglio in corso… (ricodifica, può richiedere minuti)";cpr.value=0;cpr.hidden=false;
|
||||
const iv=setInterval(async()=>{try{const p=(await(await fetch("/crop_progress?name="+n,{method:"POST"})).json()).pct;if(p!=null){cpr.value=p;cmsg.textContent=`ritaglio in corso… ${Math.round(p)}%`}}catch(e){}},700);
|
||||
const r=await fetch(`/crop?name=${n}&start=${a}&end=${b}`,{method:"POST"});clearInterval(iv);cgo_.disabled=false;cpr.hidden=true;
|
||||
if(!r.ok){cmsg.textContent="errore: "+await r.text();return}cmsg.textContent="✓ creata nuova riunione, elaborazione avviata";tick()}
|
||||
const r=await fetch(`/crop?name=${n}&start=${a}&end=${b}${inplace?"&inplace=1":""}`,{method:"POST"});clearInterval(iv);cgo_.disabled=cgi_.disabled=false;cpr.hidden=true;
|
||||
if(!r.ok){cmsg.textContent="errore: "+await r.text();return}cmsg.textContent=inplace?"✓ riunione ritagliata, rielaborazione avviata":"✓ creata nuova riunione, elaborazione avviata";tick()}
|
||||
async function stopRun(n){if(!confirm(`Fermare ${n}?`))return;await fetch("/cancel?name="+n,{method:"POST"});tick()}
|
||||
async function setLlm(){const r=await fetch(`/llm?shots=${llm.value}&report=${llmr.value}`,{method:"POST"});if(!r.ok)alert(await r.text());tick()}
|
||||
async function setSkip(){await fetch("/skip_shots?v="+(skp.checked?1:0),{method:"POST"});tick()}
|
||||
@@ -103,7 +106,7 @@ document.querySelectorAll("select[id^=f-]").forEach(s=>sel[s.id]=s.value);
|
||||
let h="<thead><tr><th>recording<th>status<th>duration<th>speakers<th>MB<th>links<th>actions</tr></thead>";
|
||||
for(const r of j.recs){const st=r.running&&r.status=="done"?"running":r.status;
|
||||
const nm=r.title||r.upload;
|
||||
h+=`<tbody class=rec><tr class=main><td><input type=checkbox class=mg value="${r.name}">${nm?`<b>${E(nm)}</b><br><small>${r.name}</small>`:r.name} <button class=del title="modifica titolo" onclick="setTitle('${r.name}','${E(r.title||r.upload||"").replace(/'/g,"")}')">✎</button><td><span class="b ${r.status}" title="${E(r.error)}">${r.status}</span>${r.receiving_age_s!=null&&r.status=="recording"?` <small>${r.receiving_age_s}s ago</small>`:""}${r.error?`<br><small>${E(r.error)}</small>`:""}<td>${r.duration_s?fmt(r.duration_s):""}<td>${r.speakers??""}<td>${r.mb}
|
||||
h+=`<tbody class=rec><tr class=main><td><input type=checkbox class=mg value="${r.name}">${nm?`<b>${E(nm)}</b><br><small>${r.name}</small>`:r.name} <button class=del title="modifica titolo" onclick="setTitle('${r.name}','${E(r.title||r.upload||"").replace(/'/g,"")}')">✎</button>${r.mb&&r.files.includes("report.html")?`<button class=del title="ricalcola titolo" onclick="retitle('${r.name}')">↻</button>`:""}<td><span class="b ${r.status}" title="${E(r.error)}">${r.status}</span>${r.receiving_age_s!=null&&r.status=="recording"?` <small>${r.receiving_age_s}s ago</small>`:""}${r.error?`<br><small>${E(r.error)}</small>`:""}<td>${r.duration_s?fmt(r.duration_s):""}<td>${r.speakers??""}<td>${r.mb}
|
||||
<td>${r.files.includes("report.html")?`<a href="/report?name=${r.name}" target=_blank>report</a><a href="/pdf?name=${r.name}" target=_blank>pdf</a>`:""}${r.flow_run_id?`<a href="http://127.0.0.1:4200/runs/flow-run/${r.flow_run_id}" target=_blank>prefect</a>`:""}
|
||||
<td>${r.mb?`<select id="f-${r.name}">${["audio","transcribe","diarize","speakers","shots","docs","report","memory","render"].map(s=>`<option>${s}`).join("")}</select><button onclick="run('${r.name}')">run</button>`:""}<button onclick="spk('${r.name}')">speakers</button>${r.mb?`<button title="anteprima e ritaglio" onclick="play('${r.name}',${r.duration_s||0},'${E(nm||r.name).replace(/'/g,"")}')">▶ video</button>`:""}${r.mb&&r.status=="done"&&!r.running?`<button title="elimina solo il file video: report, trascrizione e schermate restano, ma non si può più rielaborare" onclick="dropVid('${r.name}',${r.mb})">🎞 elimina video</button>`:""}${r.running||r.status=="queued"?`<button onclick="stopRun('${r.name}')">stop</button>`:`<button class=del title="elimina la riunione" onclick="del_('${r.name}','${E(nm||r.name).replace(/'/g,"")}')">🗑</button>`}`;
|
||||
h+=progPanel(r);
|
||||
|
||||
Reference in New Issue
Block a user