Lara Monteagudo Tubau commited on
Commit Β·
6f73902
1
Parent(s): ba2c0b3
Fix app.py syntax errors blocking Space startup
Browse files467 unmodified lines4684694704714724734744 unmodified lines479480481482483484485486487488489490491492493494495496497498499759 unmodified lines1259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513369 unmodified lines1346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394467 unmodified linesorder = [s[0] for s in stages]cur = order.index(stage) if stage in order else 0parts = []for i, (_, label) in enumerate(stages):if i < cur:bg, col, fw = "#ecfdf5", "#065f46", "600"4 unmodified lineselse:bg, col, fw = "transparent", "#94a3b8", "400"prefix = ""stages = [("upload", "Parse", "π Upload & parse transcript"),("parsed", "Sections", "π Detect topical sections"),("sectioned", "Confirm", "β Review & confirm sections"),("coding", "Analyze", "π― Boundary detection & coding"),("complete", "Done", "β Coding complete"),]f'<div style="display:flex;align-items:center;gap:4px;flex-wrap:wrap;'f'background:#f8fafc;border:1px solid #e2e8f0;border-radius:10px;'f'padding:10px 18px;margin-bottom:12px">'f'<span style="font-size:0.72em;font-weight:700;letter-spacing:0.1em;'f'color:#94a3b8;margin-right:8px">PIPELINE</span>'for i, (_, label, _) in enumerate(stages):f'</div>')def _section_cards_html(sections: list[dict], stages: dict, current_idx: int) -> str:759 unmodified linessections = state.get("sections", [])if not sections:raise gr.Error("Confirm sections first.")session_overview = state.get("_agent0_overview", "")# Validation without pop-ups β return error state for inline displayerrors = []if file_obj is None:errors.append("π Upload a transcript file first.")if not session_id.strip():errors.append("π Enter a Session ID (e.g. dyad_01).")if not researcher_id.strip():errors.append("π€ Enter your Researcher ID (e.g. R1).")if errors:error_html = (f'<div style="background:#fef2f2;border:2px solid #fca5a5;'f'border-radius:8px;padding:16px;margin:12px 0">'f'<div style="color:#991b1b;font-weight:700;margin-bottom:8px">β Please complete required fields:</div>'+ "".join(f'<div style="color:#7f1d1d;font-size:0.93em;margin:4px 0">β’ {e}</div>' for e in errors) +f'</div>')return (state,_pipeline_html("upload"),error_html, # Show inline instead of pop-upgr.update(visible=False),)# Processing started β show progressstatus_html = (f'<div style="background:#eff6ff;border:1px solid #93c5fd;'f'border-radius:8px;padding:12px 16px;margin:12px 0;font-size:0.88em;'f'color:#1e40af">β³ Parsing transcript...</div>')f"(max {min(n, 3)} concurrent workers)β¦","",gr.update(visible=False),gr.update(visible=False),"",error_html = (f'<div style="background:#fef2f2;border:2px solid #fca5a5;'f'border-radius:8px;padding:16px;margin:12px 0">'f'<div style="color:#991b1b;font-weight:700;margin-bottom:8px">β Parse Error</div>'f'<div style="color:#7f1d1d;font-size:0.88em;font-family:monospace">{_h(str(e))}</div>'f'</div>')return (state,_pipeline_html("upload"),error_html,gr.update(visible=False),))error_html = (f'<div style="background:#fef2f2;border:2px solid #fca5a5;'f'border-radius:8px;padding:16px;margin:12px 0">'f'<div style="color:#991b1b;font-weight:700;margin-bottom:8px">β Insufficient Data</div>'f'<div style="color:#7f1d1d;font-size:0.88em">Only {len(turns)} turns found. 'f'Please check the transcript format β at least 5 turns needed.</div>'f'</div>')return (state,_pipeline_html("upload"),error_html,gr.update(visible=False),)pipeline_stats_html = ""# Initialise pstats before the loop so references after the try block are# always safe even if run_boundaries_parallel raises before its first yield.pstats = PipelineStats(agent_name="Agent 1a β Boundary Detector",n_sections=len(sections),)try:9 unmodified linesgr.Warning(f"Section {sr.section_id} failed: {sr.error}")# Build live progress tabledone = len(collected_results)pending = [s for s in sections if s["section_id"] not in collected_results and# Success report cardsuccess_html = (f'<div style="background:#f0fdf4;border:2px solid #86efac;'f'border-radius:8px;padding:16px;margin:12px 0">'f'<div style="color:#065f46;font-weight:700;margin-bottom:8px">β Transcript Parsed</div>'f'<div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;font-size:0.88em;color:#14532d">'f'<div><strong>{len(turns)}</strong> turns</div>'f'<div><strong>{len(speakers)}</strong> speakers</div>'f'<div><strong>{rt}s</strong> processing time</div>'f'<div>Session: <code style="background:#dcfce7;padding:2px 4px;border-radius:3px">{_h(session_id.strip())}</code></div>'f'</div>'f'<p style="margin:12px 0 0;font-size:0.85em;color:#14532d">Ready for section detection. Click "<strong>Detect Sections</strong>" below.</p>'f'</div>')not any(not x.success and x.section_id == s["section_id"]for x in pstats.results)]prog_lines = []for s in sections:res = collected_results.get(s["section_id"])failed = any(not x.success and x.section_id == s["section_id"]for x in pstats.results)if res:b = len(res.get("boundaries", []))e = len(res.get("segments", []))prog_lines.append(f"β **{s['section_id']}** {s['label']} β {b} boundaries β {e} episodes")elif failed:prog_lines.append(f"β **{s['section_id']}** {s['label']} β ERROR")else:prog_lines.append(f"β³ **{s['section_id']}** {s['label']}β¦")status_md = f"**{done}/{n} sections complete**\n\n" + "\n\n".join(prog_lines)pipeline_stats_html = render_pipeline_stats_html(pstats)yield (state,status_md,pipeline_stats_html,gr.update(visible=False),gr.update(visible=False),"","",)except Exception as e:467 unmodified lines4684694704714724734744754764774784794804 unmodified lines485486487488489490491492493494495496497498759 unmodified lines1258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612879 unmodified lines12971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328467 unmodified linesorder = [s[0] for s in stages]cur = order.index(stage) if stage in order else 0parts = ['<div style="display:flex;align-items:center;gap:4px;flex-wrap:wrap;''background:#f8fafc;border:1px solid #e2e8f0;border-radius:10px;''padding:10px 18px;margin-bottom:12px">','<span style="font-size:0.72em;font-weight:700;letter-spacing:0.1em;''color:#94a3b8;margin-right:8px">PIPELINE</span>',]for i, (_, label) in enumerate(stages):if i < cur:bg, col, fw = "#ecfdf5", "#065f46", "600"4 unmodified lineselse:bg, col, fw = "transparent", "#94a3b8", "400"prefix = ""parts.append(f'<span style="display:inline-flex;align-items:center;gap:6px;'f'padding:6px 10px;border-radius:999px;background:{bg};'f'border:1px solid {col};color:{col};font-weight:{fw};'f'font-size:0.78em;line-height:1">{prefix}{label}</span>')parts.append('</div>')return "".join(parts)def _section_cards_html(sections: list[dict], stages: dict, current_idx: int) -> str:759 unmodified linessections = state.get("sections", [])if not sections:raise gr.Error("Confirm sections first.")if not state.get("turns"):raise gr.Error("No parsed turns found. Parse the transcript first.")n = len(sections)session_overview = state.get("_agent0_overview", "")collected_results = {}pipeline_stats_html = ""# Initial streaming updateyield (state,f"β³ Running Agent 1a in parallel on {n} section(s) (max {min(n, 3)} concurrent workers)β¦","",gr.update(visible=False, value=""),gr.update(visible=False, value=""),"",_agent_log_html(state.get("agent_logs", [])),)# Initialise pstats before the loop so references after the try block are# always safe even if run_boundaries_parallel raises before its first yield.pstats = PipelineStats(agent_name="Agent 1a β Boundary Detector",n_sections=n,)try:9 unmodified linesgr.Warning(f"Section {sr.section_id} failed: {sr.error}")# Build live progress tableprocessed = len(pstats.results)prog_lines = []for s in sections:sid = s["section_id"]res = collected_results.get(sid)failed = any((not x.success) and x.section_id == sid for x in pstats.results)if res:b = len(res.get("boundaries", []))e = len(res.get("segments", []))prog_lines.append(f"β **{sid}** {s['label']} β {b} boundaries β {e} episodes")elif failed:prog_lines.append(f"β **{sid}** {s['label']} β ERROR")else:prog_lines.append(f"β³ **{sid}** {s['label']}β¦")status_md = f"**{processed}/{n} sections complete**\n\n" + "\n\n".join(prog_lines)pipeline_stats_html = render_pipeline_stats_html(pstats)yield (state,status_md,pipeline_stats_html,gr.update(visible=False, value=""),gr.update(visible=False, value=""),"",_agent_log_html(state.get("agent_logs", [])),)except Exception as e:
app.py+40-106