Lara Monteagudo Tubau commited on
Commit ·
014b03e
1
Parent(s): 2a95ee9
Update app and transcript parser
Browse filesFiles changed (2)
- app.py+33-7
- transcript_parser.py+25-6
48 unmodified lines495051525354555657585960352 unmodified lines4134144154164174184191381 unmodified lines1801180218031804180518061807142 unmodified lines195019511952195319541955195619571958363 unmodified lines232223232324232548 unmodified lines)SESSIONS_ROOT = Path("sessions")SESSIONS_ROOT.mkdir(parents=True, exist_ok=True) # Gap 3: ensure exists at startup_STYLES_DIR = Path(__file__).parent / "static" / "styles"MODEL_ID = "Qwen/Qwen2.5-72B-Instruct"TEMPERATURE = 0.1# ---------------------------------------------------------------------------# CSS loading352 unmodified linesf'font-size:0.78em;color:#64748b;margin-bottom:4px">'f'<span>model: <strong style="color:#4338ca">{model}</strong></span>'f'<span>T={temp}</span>'f'<span><strong>{runtime_s}s</strong></span>'f'</div>'f'{extra_lines}'f'{prompts}'1381 unmodified linesCSS = _load_css() + EXTRA_CSSwith gr.Blocks(title="CollabCode", css=CSS, theme=gr.themes.Soft()) as demo:state = gr.State(_empty_state())142 unmodified lines# Left: transcriptwith gr.Column(scale=3):uncertainty_comp = gr.HTML()turns_html_comp = gr.HTML(label="Transcript", show_label=True)proposal_comp = gr.Markdown(visible=False)reveal_btn = gr.Button("Reveal AI proposal", variant="secondary", size="sm"363 unmodified linesif __name__ == "__main__":demo.launch(theme=gr.themes.Soft())48 unmodified lines495051525354555657585960616263646566676869707172737475767778798081828384858687352 unmodified lines4404414424434444454461381 unmodified lines1828182918301831183218331834142 unmodified lines19771978197919801981198219831984363 unmodified lines234823492350235148 unmodified lines)SESSIONS_ROOT = Path("sessions")SESSIONS_ROOT.mkdir(parents=True, exist_ok=True)_STYLES_DIR = Path(__file__).parent / "static" / "styles"MODEL_ID = "Qwen/Qwen2.5-72B-Instruct"TEMPERATURE = 0.1# ---------------------------------------------------------------------------# Startup diagnostics — printed once to the server log so the research team# can quickly verify the environment is configured correctly.# ---------------------------------------------------------------------------import sys as _sys, importlib.metadata as _metadef _startup_log() -> None:import gradio as _grtry:hf_ver = _meta.version("huggingface_hub")except Exception:hf_ver = "unknown"hf_tok = "SET" if __import__("os").environ.get("HF_TOKEN") else "MISSING ⚠"print("=" * 60)print(" CollabCode — startup")print("=" * 60)print(f" Python : {_sys.version.split()[0]}")print(f" Gradio : {_gr.__version__}")print(f" HF hub : {hf_ver}")print(f" HF_TOKEN : {hf_tok}")print(f" Sessions root: {SESSIONS_ROOT.resolve()}")print(f" Model : {MODEL_ID}")print(f" Temperature : {TEMPERATURE}")print("=" * 60)_startup_log()# ---------------------------------------------------------------------------# CSS loading352 unmodified linesf'font-size:0.78em;color:#64748b;margin-bottom:4px">'f'<span>model: <strong style="color:#4338ca">{model}</strong></span>'f'<span>T={temp}</span>'f'<span><strong>{runtime}s</strong></span>'f'</div>'f'{extra_lines}'f'{prompts}'1381 unmodified linesCSS = _load_css() + EXTRA_CSSwith gr.Blocks(title="CollabCode") as demo:state = gr.State(_empty_state())142 unmodified lines# Left: transcriptwith gr.Column(scale=3):uncertainty_comp = gr.HTML()gr.Markdown("**Transcript**", elem_classes=["label-md"])turns_html_comp = gr.HTML()proposal_comp = gr.Markdown(visible=False)reveal_btn = gr.Button("Reveal AI proposal", variant="secondary", size="sm"363 unmodified linesif __name__ == "__main__":demo.launch(css=CSS, theme=gr.themes.Soft())
119 unmodified lines120121122123124125126127110 unmodified lines238239240241242243244245246247248249250251252253254255256119 unmodified lines))turn_id += 1for line in lines:m = _TXT_HEADER_RE.match(line) or _TXT_HEADER_ALT_RE.match(line) or _TXT_HEADER_BRACKET_RE.match(line)if m:_flush()current_speaker = m.group("speaker").strip()110 unmodified linesif not path.exists():raise FileNotFoundError(f"Transcript not found: {filepath}")content = path.read_text(encoding="utf-8", errors="replace")fmt = detect_format(content)lines = content.splitlines()if fmt == "vtt":turns = _parse_vtt(lines)else:turns = _parse_txt(lines)if not turns:raise ValueError(f"No speaker turns extracted from {filepath}. ""Check that the file matches Zoom TXT or VTT export format.")return [asdict(t) for t in turns]119 unmodified lines120121122123124125126127128129130131132110 unmodified lines243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275119 unmodified lines))turn_id += 1for raw_line in lines:# Strip BOM, carriage returns, and leading/trailing whitespace that# could prevent regex anchors from matching (common in Windows exports)line = raw_line.strip().lstrip("")m = (_TXT_HEADER_RE.match(line)or _TXT_HEADER_ALT_RE.match(line)or _TXT_HEADER_BRACKET_RE.match(line))if m:_flush()current_speaker = m.group("speaker").strip()110 unmodified linesif not path.exists():raise FileNotFoundError(f"Transcript not found: {filepath}")# utf-8-sig strips the BOM (U+FEFF) automatically — common in Windows/Zoom exports.# Fall back to latin-1 (never raises decoding errors) if utf-8 fails.try:content = path.read_text(encoding="utf-8-sig")except UnicodeDecodeError:content = path.read_text(encoding="latin-1")fmt = detect_format(content)lines = content.splitlines()print(f"[Parser] {path.name}: {len(lines)} raw lines, detected format={fmt!r}")print(f"[Parser] First 3 lines: {lines[:3]}")if fmt == "vtt":turns = _parse_vtt(lines)else:turns = _parse_txt(lines)if not turns:# Provide diagnostic context so the log reveals the actual problemsample = "\n ".join(repr(l) for l in lines[:8])raise ValueError(f"No speaker turns extracted from {path.name}.\n"f"Format detected: {fmt!r}\n"f"File has {len(lines)} lines. First 8 lines:\n {sample}\n""Expected Zoom TXT format: '[Speaker Name] HH:MM:SS' header lines, ""or Zoom VTT export. Check encoding and file format.")return [asdict(t) for t in turns]
app.py+33-7
transcript_parser.py+25-6