Auto speaker count from roster, one-to-one speaker map, clean LLM junk, merge recordings, Teams caption scraping
This commit is contained in:
+36
-4
@@ -63,7 +63,7 @@ def ask_once(q):
|
||||
def now(): return time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
def launch(name, start_from, speakers=5):
|
||||
def launch(name, start_from, speakers=0):
|
||||
"""Queue a flow run. One flow at a time (one GPU): the rest wait. False if `name` is already running or queued."""
|
||||
global BATCH
|
||||
with QLOCK:
|
||||
@@ -159,6 +159,34 @@ def cancel(name, reason="cancelled from web UI"):
|
||||
return bool(pids)
|
||||
|
||||
|
||||
def merge(names):
|
||||
"""Join webm parts of one call (restarted recording): stream copy in start order, events shifted by the cumulative length.
|
||||
Returns (merged_name, None) or (None, error). Originals stay; delete them from the GUI once the merged report is fine."""
|
||||
c = db.connect()
|
||||
rows = [c.execute("SELECT name, started_at, ended_at, chunks, bytes, status FROM recordings WHERE name=?", (n,)).fetchone() for n in names]
|
||||
if len(names) < 2 or None in rows: return None, "servono almeno 2 registrazioni esistenti"
|
||||
if any(r["status"] == "recording" or r["name"] in R or r["name"] in JOBS and JOBS[r["name"]].poll() is None for r in rows): return None, "ferma prima le registrazioni in corso"
|
||||
rows.sort(key=lambda r: r["started_at"] or "")
|
||||
files = [out / f"{r['name']}.webm" for r in rows]
|
||||
if not all(f.exists() for f in files): return None, "solo registrazioni .webm"
|
||||
merged = rows[0]["name"] + "_merged"
|
||||
if c.execute("SELECT 1 FROM recordings WHERE name=?", (merged,)).fetchone(): return None, "unione già esistente"
|
||||
lst = out / f"{merged}.concat.txt"
|
||||
lst.write_text("".join(f"file '{f.name}'\n" for f in files), encoding="utf-8")
|
||||
dst = out / f"{merged}.webm"
|
||||
r = subprocess.run(["ffmpeg", "-y", "-v", "error", "-f", "concat", "-safe", "0", "-i", str(lst), "-c", "copy", str(dst)], capture_output=True, text=True)
|
||||
lst.unlink(missing_ok=True)
|
||||
if r.returncode: return None, r.stderr[-300:]
|
||||
offs, o = [], 0.0
|
||||
for f in files: offs.append(o); o += db.duration(f)
|
||||
db.upsert_recording(merged, source="ext", started_at=rows[0]["started_at"], ended_at=rows[-1]["ended_at"], chunks=sum(r["chunks"] or 0 for r in rows),
|
||||
bytes=dst.stat().st_size, duration_s=o, status="queued")
|
||||
for r, off in zip(rows, offs):
|
||||
c.execute("INSERT INTO call_events(name,t,kind,who_key,who,text) SELECT ?,t+?,kind,who_key,who,text FROM call_events WHERE name=?", (merged, off, r["name"]))
|
||||
launch(merged, "audio")
|
||||
return merged, None
|
||||
|
||||
|
||||
def reaper():
|
||||
"""Prefect cannot stop flows it did not launch: honour 'Cancel' from its UI and close runs whose process died."""
|
||||
while True:
|
||||
@@ -351,7 +379,7 @@ body.drag main{outline:3px dashed var(--acc);outline-offset:8px;border-radius:14
|
||||
button.del{color:var(--redf)}button.del:hover{background:var(--red);border-color:var(--redf)}
|
||||
dialog{border:1px solid var(--line);border-radius:14px;background:var(--card);color:var(--fg);padding:16px;width:min(960px,94vw)}dialog::backdrop{background:rgba(0,0,0,.5)}
|
||||
dialog video{width:100%;max-height:68vh;background:#000;border-radius:8px}dialog input.tm{width:90px}#cmsg{color:var(--mut);font-size:13px}</style>
|
||||
<main><header><h1>Riunioni</h1><div class=row><span id=qs></span><select id=llm title="modello per le schermate (shots)" onchange=setLlm()></select><select id=llmr title="modello per il report" onchange=setLlm()></select><button class=pri onclick=pick() title="mp4, mkv, mov, webm, wav, m4a, mp3">⬆ Carica video</button>
|
||||
<main><header><h1>Riunioni</h1><div class=row><span id=qs></span><select id=llm title="modello per le schermate (shots)" onchange=setLlm()></select><select id=llmr title="modello per il report" onchange=setLlm()></select><button onclick=mergeSel() title="unisce in un solo video le registrazioni spuntate (stessa chiamata riavviata)">Unisci spuntati</button><button class=pri onclick=pick() title="mp4, mkv, mov, webm, wav, m4a, mp3">⬆ Carica video</button>
|
||||
<input type=file id=up accept="video/*,audio/*,.mkv" hidden></div></header>
|
||||
<div id=hint>Trascina qui un video o un audio di una riunione per elaborarlo.</div>
|
||||
<div class="card" id=ub hidden><div class=pg style="margin:0;border:0;padding:0;background:none"><div class=pgh><span><span class=big id=ubig>0%</span> <b id=utitle></b></span><button id=ucancel>annulla</button></div>
|
||||
@@ -377,6 +405,7 @@ j.sources.map(s=>`<div><small>[${s.n}] ${E(s.date)} ${E(s.meeting)} — ${E(s.to
|
||||
async function srch(){if(!q.value){sr.innerHTML="";return}const j=await (await fetch("/search?q="+encodeURIComponent(q.value))).json();
|
||||
sr.innerHTML=j.speech.map(r=>`<div>${E(r[0])} ${fmt(r[1])} ${E(r[2]||"")}: ${E(r[3])}</div>`).join("")+j.screen.map(r=>`<div>🖥 <a href="/shot?name=${r[0]}&file=shots/${r[4]}" target=_blank>${E(r[0])} ${fmt(r[1])}</a> ${E(r[2]||"")}: ${E(r[3])}</div>`).join("")}
|
||||
async function run(n){const f=document.getElementById("f-"+n).value;const r=await fetch(`/run?name=${n}&from=${f}`,{method:"POST"});if(r.status==409)alert("già in esecuzione");tick()}
|
||||
async function mergeSel(){const n=[...document.querySelectorAll(".mg:checked")].map(x=>x.value);if(n.length<2)return alert("spunta almeno 2 registrazioni");const r=await fetch("/merge?names="+n.join(","),{method:"POST"});if(!r.ok)alert(await r.text());tick()}
|
||||
const open_=new Set();
|
||||
async function spk(n){open_.has(n)?open_.delete(n):open_.add(n);tick()}
|
||||
async function panel(n){const j=await (await fetch("/speakers?name="+n)).json();
|
||||
@@ -450,7 +479,7 @@ document.querySelectorAll("select[id^=f-]").forEach(s=>sel[s.id]=s.value);
|
||||
let h="<tr><th>recording<th>status<th>duration<th>speakers<th>MB<th>links<th>actions</tr>";
|
||||
for(const r of j.recs){const st=r.running&&r.status=="done"?"running":r.status;
|
||||
const nm=r.title||r.upload;
|
||||
h+=`<tr><td>${nm?`<b>${E(nm)}</b><br><small>${r.name}</small>`:r.name}<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+=`<tr><td><input type=checkbox class=mg value="${r.name}">${nm?`<b>${E(nm)}</b><br><small>${r.name}</small>`:r.name}<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><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.running?`<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);
|
||||
@@ -523,8 +552,11 @@ class H(BaseHTTPRequestHandler):
|
||||
elif u.path == "/crop": self.crop(name, q)
|
||||
elif u.path == "/cancel":
|
||||
self._send(b"") if cancel(name) else self._send("nessun processo attivo: run chiusa".encode(), 200)
|
||||
elif u.path == "/merge":
|
||||
m, err = merge([n for n in q.get("names", "").split(",") if n])
|
||||
self._send(m.encode() if m else err.encode(), 200 if m else 400)
|
||||
elif u.path == "/run":
|
||||
ok = launch(name, q.get("from", "audio"), int(q.get("speakers") or 5))
|
||||
ok = launch(name, q.get("from", "audio"), int(q.get("speakers") or 0))
|
||||
self._send(b"" if ok else "già in coda o in esecuzione".encode(), 200 if ok else 409)
|
||||
elif u.path == "/run_all":
|
||||
f = q.get("from", "audio")
|
||||
|
||||
Reference in New Issue
Block a user