Lara Monteagudo Tubau commited on
Commit Β·
7d23ffa
1
Parent(s): e8a5038
style: remove emojis, restore system font, three-card session layout
Browse files124 unmodified lines12512612712812913013113 unmodified lines145146147148149150151152153154155156151 unmodified lines3083093103113123133143153169 unmodified lines3263273283293303313323333343353363373383393403413428 unmodified lines35135235335435535635723 unmodified lines3813823833843853863873883893903918 unmodified lines40040140240340440540640740840941041141241341441541641741841942042122 unmodified lines44444544644744844945045145245345424 unmodified lines47948048148248348448514 unmodified lines5005015025035045055066 unmodified lines51351451551651751851962 unmodified lines58258358458558658758858959038 unmodified lines62963063163263363463531 unmodified lines66766866967067167267318 unmodified lines69269369469569669769828 unmodified lines72772872973073173273385 unmodified lines81982082182282382482510 unmodified lines83683783883984084184284384484536 unmodified lines88288388488588688788851 unmodified lines94094194294394494594621 unmodified lines9689699709719729739741 unmodified line97697797897998098198298398498598698798898954 unmodified lines10441045104610471048104910501051105219 unmodified lines10721073107410751076107710781079108010811082108383 unmodified lines116711681169117011711172117310 unmodified lines1184118511861187118811891190524 unmodified lines171517161717171817191720172129 unmodified lines175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117823 unmodified lines178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181621 unmodified lines18381839184018411842184318441 unmodified line184618471848184918501851185220 unmodified lines187318741875187618771878187918801881188218831884188518867 unmodified lines189418951896189718981899190010 unmodified lines1911191219131914191519161917191819191920192119221923192421 unmodified lines194619471948194919501951195234 unmodified lines19871988198919901991199219931 unmodified line199519961997199819992000200110 unmodified lines20122013201420152016201720189 unmodified lines20282029203020312032203320344 unmodified lines203920402041204220432044204555 unmodified lines21012102210321042105210621072 unmodified lines211021112112211321142115211621172118211921201 unmodified line212221232124212521262127212825 unmodified lines21542155215621572158215921602161216221636 unmodified lines2170217121722173217421752176217720 unmodified lines21982199220022012202220322041 unmodified line22062207220822092210221122123 unmodified lines22162217221822192220222122222223124 unmodified lines# SSRL metacognitive phases β shown alongside D1-D9 in Review tabSSRL_PHASES = [("M-MON", "Metacognitive Monitoring", "#4338ca", "#eef2ff"),("M-REG", "Metacognitive Regulation", "#065f46", "#ecfdf5"),("CO-REG", "Co-Regulation", "#b45309", "#fffbeb"),("SSRL", "Socially Shared Regulation", "#9a3412", "#fff7ed"),13 unmodified linesSEC_ID_FROM_CHOICE = {SEC_NONE: None, **DIM_ID_FROM_CHOICE}SPEAKER_PALETTE = [("#4338ca", "#eef2ff", "#c7d2fe", "π΅"),("#b45309", "#fffbeb", "#fde68a", "π‘"),("#065f46", "#ecfdf5", "#a7f3d0", "π’"),("#9a3412", "#fff7ed", "#fed7aa", "π "),("#6b21a8", "#faf5ff", "#e9d5ff", "π£"),("#0e7490", "#ecfeff", "#a5f3fc", "π·"),]151 unmodified linesif i < cur_idx:bg, tc, border, dot = "#dcfce7", "#15803d", "#86efac", "β"elif i == cur_idx:bg, tc, border, dot = "#eff6ff", "#1d4ed8", "#93c5fd", "βΆ"else:bg, tc, border, dot = "#f8fafc", "#94a3b8", "#e2e8f0", "β"steps.append(f'<div style="display:flex;flex-direction:column;align-items:center;'f'gap:3px;padding:6px 12px;border-radius:8px;background:{bg};'9 unmodified linesn_wins = len(screener["candidate_windows"]) if screener else "β"return (f'<div style="background:#fff;border-bottom:2px solid #e2e8f0;'f'padding:12px 20px;display:flex;align-items:center;gap:16px;'f'flex-wrap:wrap;font-family:system-ui,sans-serif">'f'<div style="display:flex;align-items:center;gap:8px;margin-right:8px">'f'<span style="font-size:1.1em">π¬</span>'f'<div style="line-height:1.3">'f'<div style="font-weight:800;color:#1e293b;font-size:0.9em">{session}</div>'f'<div style="font-size:0.72em;color:#94a3b8">'f'{turns} turns Β· screener: {n_wins} windows Β· ~{savings} LLM savings'f'</div></div></div>'f'<div style="display:flex;gap:6px;flex-wrap:wrap">{"".join(steps)}</div>'f'</div>')8 unmodified lines"success": ("#f0fdf4", "#065f46", "#86efac", "β"),"error": ("#fef2f2", "#991b1b", "#fca5a5", "β"),"warning": ("#fffbeb", "#78350f", "#fbbf24", "β "),"processing": ("#eff6ff", "#1e40af", "#93c5fd", "β³"),}bg, tc, bc, icon = colors.get(status, colors["success"])detail_html = ""23 unmodified linesdef _loading_card(title: str, subtitle: str = "Please waitβ¦", spin: str = "β") -> str:return ('<div style="background:#eff6ff;border:2px solid #93c5fd;border-radius:12px;''padding:18px 20px;margin:10px 0;font-family:system-ui,sans-serif">''<div style="display:flex;align-items:center;gap:12px">'f'<div style="font-size:1.35em;color:#1e3a8a">{spin}</div>'f'<div><div style="font-weight:800;color:#1e3a8a;font-size:1.02em">{_h(title)}</div>'f'<div style="margin-top:4px;font-size:0.86em;color:#475569">{_h(subtitle)}</div></div>''</div></div>')8 unmodified linescirc_icon = "β" if circ == "CLOSED" else "β " if circ == "HALF_OPEN" else "β"eta_str = f"~{remaining}s" if remaining > 5 else "finishingβ¦"return (f'<div style="background:#eff6ff;border:2px solid #93c5fd;'f'border-radius:12px;padding:16px 20px;font-family:system-ui,sans-serif">'f'<div style="display:flex;align-items:center;gap:10px;margin-bottom:12px">'f'<span style="font-size:1.3em">{spinner}</span>'f'<span style="font-weight:700;color:#1e3a8a;font-size:0.94em">{_h(message)}</span>'f'<span style="margin-left:auto;font-family:monospace;font-size:0.84em;'f'background:#dbeafe;padding:3px 9px;border-radius:6px;color:#1e40af">'f'{elapsed}s elapsed</span></div>'f'<div style="background:#dbeafe;border-radius:5px;height:9px;'f'margin-bottom:10px;overflow:hidden">'f'<div style="height:100%;width:{pct}%;background:#4338ca;border-radius:5px"></div>'f'</div>'f'<div style="display:flex;flex-wrap:wrap;gap:14px;font-size:0.8em;color:#475569">'f'<span>β± Est: ~{est_total}s</span>'f'<span>β ETA: {eta_str}</span>'f'<span>π’ ~{tokens_in:,} tokens</span>'f'<span style="color:{circ_color};font-weight:600">'f'Circuit: {circ_icon} {circ}</span>'f'</div></div>'22 unmodified linesf'<div style="border:1px solid #e2e8f0;border-radius:8px;'f'padding:10px 12px;margin-bottom:8px;background:white">'f'<div style="display:flex;justify-content:space-between;margin-bottom:4px">'f'<span style="font-weight:700;font-size:0.88em;color:#1e293b">{agent}</span>'f'<span style="font-size:0.72em;color:#94a3b8">{ts} Β· {runtime}s</span>'f'</div>'f'<div style="font-size:0.76em;color:#94a3b8">model: 'f'<strong style="color:#4338ca">{model}</strong></div>'f'{extra_lines}'f'</div>')24 unmodified linesf'<span style="font-family:monospace;font-size:0.7em;color:#94a3b8">{ts}</span>'f'<span style="font-family:monospace;font-size:0.67em;color:#cbd5e1">#{turn_id}</span>'f'</div>'f'<div style="line-height:1.6;color:#1e293b;font-size:0.93em">{text}</div>'f'</div></div>')return f'<div style="font-family:system-ui,sans-serif">{"".join(parts)}</div>'14 unmodified linesif score >= 0.40:return "#fef9c3", "#854d0e"if score >= 0.2:return "#eff6ff", "#1d4ed8"return "#f8fafc", "#94a3b8"6 unmodified linesreturn (f'<div style="display:flex;gap:12px;flex-wrap:wrap;'f'font-family:system-ui,sans-serif;margin-bottom:16px">'+ _stat_chip(str(total), "Total turns", "#4338ca", "#eef2ff")+ _stat_chip(str(flagged), "Flagged turns", "#065f46", "#dcfce7")+ _stat_chip(str(windows), "Candidate windows", "#b45309", "#fffbeb")+ _stat_chip(f"{savings:.0%}", "LLM savings", "#be123c", "#fef2f2")62 unmodified linesph = hit.get("phase", "")lbl = hit.get("category_label", "")tier = hit.get("tier", 1)tchip_bg = {"planning": "#eff6ff", "monitoring": "#f0fdf4","evaluating": "#fff7ed", "ssrl": "#faf5ff"}.get(ph, "#f8fafc")tchip_c = {"planning": "#1d4ed8", "monitoring": "#15803d","evaluating": "#c2410c", "ssrl": "#7c3aed"}.get(ph, "#64748b")tier_mark = "β¨2β©" if tier == 2 else "β¨3?β©" if tier == 3 else ""trigger_chips += (38 unmodified linesf'</div>'# Textf'<div style="font-size:0.85em;color:#1e293b;line-height:1.5">'f'{display_text}</div>'# Triggers31 unmodified linesf'font-family:monospace;min-width:44px;text-align:center">'f'{i:02d}</div>'f'<div style="flex:1">'f'<div style="font-weight:700;font-size:0.9em;color:#1e293b">'f'Turns {_h(str(start))}β{_h(str(end))} 'f'<span style="font-weight:400;color:#64748b">({n} turns)</span></div>'f'<div style="font-size:0.8em;color:#475569;margin-top:2px">'18 unmodified linesreturn '<p style="color:#94a3b8">Lexicon file not found.</p>'phase_colors = {"planning": ("#1d4ed8", "#eff6ff", "#dbeafe"),"monitoring": ("#15803d", "#f0fdf4", "#dcfce7"),"evaluating": ("#c2410c", "#fff7ed", "#fed7aa"),"ssrl": ("#7c3aed", "#faf5ff", "#e9d5ff"),28 unmodified linesf'<div style="display:flex;align-items:baseline;gap:10px;margin-bottom:6px">'f'<span style="font-family:monospace;font-size:0.8em;font-weight:700;'f'background:{bg};color:{tc};padding:2px 8px;border-radius:4px">{cat_id}</span>'f'<span style="font-weight:700;color:#1e293b">{label}</span>'f'<span style="margin-left:auto;font-size:0.78em;color:{tc};font-weight:600">'f'w={weight} Β· {_h(phase)}</span>'f'</div>'85 unmodified linesf'padding:12px 16px;margin-bottom:10px;background:#fffbeb">'f'<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px">'f'<span style="font-size:0.82em;font-weight:700;color:#b45309">β³ Pending</span>'f'<span style="font-weight:700;color:#1e293b">{label}</span>'f'<span style="margin-left:auto;font-size:0.72em;color:#94a3b8">{session}</span>'f'</div>'f'<div style="margin-bottom:8px">{term_chips}</div>'10 unmodified linesdef _dim_badge(did: str) -> str:colors = {"D1": ("#4338ca","#eef2ff"), "D2": ("#0e7490","#ecfeff"),"D3": ("#065f46","#ecfdf5"), "D4": ("#b45309","#fffbeb"),"D5": ("#6b21a8","#faf5ff"), "D6": ("#9a3412","#fff7ed"),"D7": ("#1e40af","#dbeafe"), "D8": ("#be123c","#fef2f2"),"D9": ("#374151","#f3f4f6"), "NS": ("#78716c","#f5f5f4"),"NA": ("#94a3b8","#f8fafc"),}36 unmodified linesscreener_tag = ('<span style="background:#d1fae5;color:#065f46;font-size:0.72em;''padding:2px 6px;border-radius:4px;margin-left:6px">''π screener hit</span>')uncertain_tag = ""51 unmodified linesheader = (f'<div style="display:flex;gap:10px;margin-bottom:14px;flex-wrap:wrap">'+ _stat_chip(str(total), "Segments", "#4338ca", "#eef2ff")+ _stat_chip(str(coded), "D1-D9 coded", "#065f46", "#dcfce7")+ _stat_chip(str(ssrl_ct), "SSRL tagged", "#7c3aed", "#faf5ff")+ f'</div>'21 unmodified linescards.append(f'<div style="border:2px solid #e2e8f0;border-radius:10px;'f'padding:14px 16px;background:white">'f'<div style="font-weight:800;color:#1e293b;font-size:0.92em">'f'{_h(s["label"])}</div>'f'<div style="font-family:monospace;font-size:0.75em;color:#94a3b8;'f'margin:4px 0">{_h(s["start_time"])}β{_h(s["end_time"])}</div>'1 unmodified linef'{s["end_turn_id"]} ({n} turns Β· {pct}%)</div>'f'<div style="height:4px;background:#e2e8f0;border-radius:2px;'f'margin-top:8px;overflow:hidden">'f'<div style="height:100%;width:{pct}%;background:#4338ca;border-radius:2px">'f'</div></div>'f'</div>')return (f'<div style="font-family:system-ui,sans-serif">'f'<div style="display:flex;gap:8px;margin-bottom:10px;flex-wrap:wrap">'+ _stat_chip(str(n_turns), "Turns", "#4338ca", "#eef2ff")+ _stat_chip(str(len(sections)), "Sections", "#065f46", "#dcfce7")+ _stat_chip(str(n_speakers), "Speakers", "#b45309", "#fffbeb")+ _stat_chip(f"{elapsed}s", "Agent 0", "#7c3aed", "#faf5ff")54 unmodified linesif not desc:return ""return (f'<div style="background:#eff6ff;border-left:3px solid #4338ca;'f'border-radius:0 6px 6px 0;padding:7px 12px;font-size:0.85em;'f'color:#1e40af;margin-top:6px">{_h(desc)}</div>')19 unmodified linesf'padding:12px 16px;margin-bottom:12px">'f'<div style="display:flex;justify-content:space-between;align-items:baseline;'f'margin-bottom:6px">'f'<div style="font-size:0.88em;font-weight:700;color:#1e293b">'f'Section {idx+1}/{len(sections)} β {_h(sec.get("label",""))}</div>'f'<div style="font-size:0.82em;color:#64748b">Episode {min(cidx,total-1)+1} of {total}</div>'f'</div>'f'<div style="height:6px;background:#e2e8f0;border-radius:3px;overflow:hidden">'f'<div style="height:100%;width:{pct}%;background:#4338ca;border-radius:3px"></div>'f'</div>'f'<div style="display:flex;justify-content:space-between;margin-top:4px;'f'font-size:0.75em;color:#94a3b8">'83 unmodified linesseg_map = {s["segment_id"]: s for s in all_segs}parts = [f'<div style="font-family:system-ui,sans-serif">'f'<div style="font-weight:700;margin-bottom:10px;color:#1e293b">'f'{len(disags)} unresolved disagreements</div>']for d in disags:10 unmodified linesf'<span style="background:#fff7ed;color:#c2410c;font-weight:700;'f'padding:2px 8px;border-radius:4px">R1: {r1}</span>'f'<span style="color:#94a3b8">vs</span>'f'<span style="background:#eff6ff;color:#1d4ed8;font-weight:700;'f'padding:2px 8px;border-radius:4px">R2: {r2}</span>'f'</div>'f'<div style="font-size:0.82em;color:#64748b;font-style:italic">{rat}</div>'524 unmodified linesf'padding:12px 14px;margin-bottom:8px">'f'<div style="font-family:monospace;font-size:0.78em;'f'color:#94a3b8;margin-bottom:4px">{rid}</div>'f'<div style="font-size:0.9em;color:#1e293b">{desc}</div>'f'<div style="font-size:0.75em;color:#64748b;margin-top:4px">'f'From sessions: {src}</div>'f'</div>'29 unmodified lines# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββCUSTOM_CSS = """:root {--primary: #4338ca;--primary-light: #eef2ff;--surface: #ffffff;--border: #e2e8f0;--text: #1e293b;--muted: #64748b;}body { font-family: system-ui, -apple-system, sans-serif; }.gr-box { border-radius: 10px !important; }.pipeline-header { position: sticky; top: 0; z-index: 100; }.tab-nav button { font-weight: 600 !important; }.screener-table { overflow-x: auto; }""" + _load_css()def build_ui():with gr.Blocks(title="CollabCode v5",css=CUSTOM_CSS,theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="slate"),) as demo:state = gr.State(_empty_state())# ββ Persistent pipeline header ββββββββββββββββββββββββββββββββββββββββwith gr.Row(elem_classes=["pipeline-header"]):pipeline_header = gr.HTML(value=_pipeline_status_html(_empty_state()))3 unmodified lines# ================================================================# TAB 1 β SESSION# ================================================================with gr.Tab("π Session"):gr.Markdown("## Session Setup\nLoad a transcript and identify yourself as a researcher.")with gr.Row():with gr.Column(scale=1):researcher_id = gr.Textbox(label="Researcher ID",placeholder="e.g. R1_Lara",info="Used to namespace your codings and Drive sessions.")gr.Markdown("### Upload transcript (local file)")local_file = gr.File(label="Upload .txt or .vtt transcript",file_types=[".txt", ".vtt", ".srt"],)upload_btn = gr.Button("β¬ Load local file", variant="primary")with gr.Column(scale=1):gr.Markdown("### Or load from Google Drive")refresh_drive_btn = gr.Button("π Connect to Drive")drive_dropdown = gr.Dropdown(label="Select transcript from Drive",choices=[], interactive=False,)drive_load_btn = gr.Button("β¬ Load from Drive")load_session_btn = gr.Button("π Restore previous session")session_status = gr.HTML()21 unmodified lines# ================================================================# TAB 2 β SCREENER# ================================================================with gr.Tab("π Screener"):gr.Markdown("## Metacognitive Talk Screener\n""Scans every turn with the research-backed trigger lexicon before any LLM call. "1 unmodified line"Yellow β structural signal (question mark, interruption, rapid exchange).")with gr.Row():run_screener_btn = gr.Button("βΆ Run Screener", variant="primary", scale=2)screener_info = gr.HTML(scale=3)screener_status = gr.HTML()20 unmodified lines# ================================================================# TAB 3 β SECTIONS# ================================================================with gr.Tab("π Sections"):gr.Markdown("## Structural Sections (Agent 0)\n""Agent 0 detects the high-level structure of the session ""(e.g. warm-up, main task, wrap-up). Review and edit labels before coding.")with gr.Row():run_agent0_btn = gr.Button("βΆ Run Agent 0 β Detect sections", variant="primary")sections_status = gr.HTML()sections_display = gr.HTML()7 unmodified lineslines=6, placeholder="Introduction\nMain Task\nWrap-up")with gr.Row():confirm_sections_btn = gr.Button("β Confirm sections", variant="primary")sections_confirm_status = gr.HTML()run_agent0_btn.click(10 unmodified lines# ================================================================# TAB 4 β PIPELINE# ================================================================with gr.Tab("β Pipeline"):gr.Markdown("## Coding Pipeline (Agent 1a + 1b)\n""Runs boundary detection and dimension coding on all confirmed sections. ""Uses screener windows to focus LLM calls on metacognitive candidate turns.")with gr.Row():run_pipeline_btn = gr.Button("βΆ Run full pipeline", variant="primary", scale=2)pipeline_info = gr.HTML(scale=3)pipeline_status_out = gr.HTML()21 unmodified linessec_dropdown = gr.Dropdown(label="Secondary dimension (optional)",choices=SEC_DIM_CHOICES, value=SEC_NONE)coding_note = gr.Textbox(label="Note (optional)", lines=2)save_btn = gr.Button("πΎ Save coding", variant="primary")save_status_out = gr.HTML()manual_btn_visible = gr.Column(visible=False)34 unmodified lines# ================================================================# TAB 5 β REVIEW# ================================================================with gr.Tab("π Review"):gr.Markdown("## Segment Review & Editing\n""All coded segments. Green π badge = screener flagged this segment "1 unmodified line)with gr.Row():refresh_review_btn = gr.Button("βΊ Refresh view", scale=1)review_info = gr.HTML(scale=4)review_display = gr.HTML()10 unmodified lineschoices=SSRL_CHOICES,value=SSRL_CHOICES[-1], # NONE)save_ssrl_btn = gr.Button("πΎ Save SSRL tag", variant="secondary")ssrl_status = gr.HTML()refresh_review_btn.click(9 unmodified lines# ================================================================# TAB 6 β AGREEMENT# ================================================================with gr.Tab("π€ Agreement"):gr.Markdown("## Inter-Rater Reliability\n""Upload coding files from both researchers. "4 unmodified linesr1_file = gr.File(label="R1 codings (.json)", file_types=[".json"])r2_file = gr.File(label="R2 codings (.json)", file_types=[".json"])calc_kappa_btn = gr.Button("π Calculate agreement", variant="primary")kappa_status_out = gr.HTML()kappa_summary_out = gr.HTML()disagreement_out = gr.HTML()55 unmodified lines# ================================================================# TAB 7 β LEXICON# ================================================================with gr.Tab("π Lexicon"):gr.Markdown("## Trigger Word Lexicon\n""The research-backed vocabulary used to screen turns before LLM coding. "2 unmodified lines"Tier 3 holds candidates proposed by the system β review and approve or reject them.")with gr.Row():load_lexicon_btn = gr.Button("π Load / refresh lexicon", variant="primary")lexicon_status = gr.HTML()with gr.Tabs():with gr.Tab("π Tier 1 β Research-locked"):gr.Markdown("Source: Halmo et al. 2022, Zimmerman SRL model, ""JΓ€rvelΓ€ & Hadwin SSRL, LIWC cognitive categories, "1 unmodified line)tier1_html = gr.HTML()with gr.Tab("β Tier 2 β Your validated terms"):gr.Markdown("Terms you've validated in your specific participant population. ""These are used at full weight by the screener."25 unmodified lines)t2_note = gr.Textbox(label="Note / source", lines=2,placeholder="Observed in Session 3 and 4.")add_t2_btn = gr.Button("β Add to Tier 2", variant="primary")add_t2_status = gr.HTML()with gr.Tab("β³ Tier 3 β Candidates (system-proposed)"):gr.Markdown("Words that appeared in LLM-coded metacognitive segments but ""aren't in Tier 1 or 2 yet. Review each one: approve to move to Tier 2, "6 unmodified linest3_term = gr.Textbox(label="Term to approve/reject")t3_note = gr.Textbox(label="Rejection note (optional)")with gr.Row():approve_t3_btn = gr.Button("β Approve", variant="primary")reject_t3_btn = gr.Button("β Reject")t3_action_status = gr.HTML()load_lexicon_btn.click(20 unmodified lines# ================================================================# TAB 8 β LEARNING# ================================================================with gr.Tab("π§ Learning"):gr.Markdown("## Agent 2 β Rule Learning\n""After sessions accumulate disagreements, Agent 2 proposes coding rules "1 unmodified line"before they become active in Tier 2.")with gr.Row():load_rules_btn = gr.Button("π Load pending rules", variant="primary")learning_status = gr.HTML()pending_rules_html = gr.HTML()3 unmodified linesrule_id_box = gr.Textbox(label="Rule ID")rule_note_box = gr.Textbox(label="Rejection note (optional)")with gr.Row():approve_rule_btn = gr.Button("β Approve rule", variant="primary")reject_rule_btn = gr.Button("β Reject rule")rule_action_status = gr.HTML()load_rules_btn.click(124 unmodified lines12512612712812913013113 unmodified lines145146147148149150151152153154155156151 unmodified lines3083093103113123133143153169 unmodified lines3263273283293303313323333343353363373383393403413423438 unmodified lines35235335435535635735823 unmodified lines3823833843853863873883893903913928 unmodified lines40140240340440540640740840941041141241341441541641741841942042142222 unmodified lines44544644744844945045145245345445524 unmodified lines48048148248348448548614 unmodified lines5015025035045055065076 unmodified lines51451551651751851952062 unmodified lines58358458558658758858959059138 unmodified lines63063163263363463563631 unmodified lines66866967067167267367418 unmodified lines69369469569669769869928 unmodified lines72872973073173273373485 unmodified lines82082182282382482582610 unmodified lines83783883984084184284384484584636 unmodified lines88388488588688788888951 unmodified lines94194294394494594694721 unmodified lines9699709719729739749751 unmodified line97797897998098198298398498598698798898999054 unmodified lines10451046104710481049105010511052105319 unmodified lines10731074107510761077107810791080108110821083108483 unmodified lines116811691170117111721173117410 unmodified lines1185118611871188118911901191524 unmodified lines171617171718171917201721172229 unmodified lines17521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619473 unmodified lines1951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202421 unmodified lines20462047204820492050205120521 unmodified line205420552056205720582059206020 unmodified lines208120822083208420852086208720882089209020912092209320947 unmodified lines210221032104210521062107210810 unmodified lines2119212021212122212321242125212621272128212921302131213221 unmodified lines215421552156215721582159216034 unmodified lines21952196219721982199220022011 unmodified line220322042205220622072208220910 unmodified lines22202221222222232224222522269 unmodified lines22362237223822392240224122424 unmodified lines224722482249225022512252225355 unmodified lines23092310231123122313231423152 unmodified lines231823192320232123222323232423252326232723281 unmodified line233023312332233323342335233625 unmodified lines23622363236423652366236723682369237023716 unmodified lines2378237923802381238223832384238520 unmodified lines24062407240824092410241124121 unmodified line24142415241624172418241924203 unmodified lines24242425242624272428242924302431124 unmodified lines# SSRL metacognitive phases β shown alongside D1-D9 in Review tabSSRL_PHASES = [("M-MON", "Metacognitive Monitoring", "#ea580c", "#fff7ed"),("M-REG", "Metacognitive Regulation", "#065f46", "#ecfdf5"),("CO-REG", "Co-Regulation", "#b45309", "#fffbeb"),("SSRL", "Socially Shared Regulation", "#9a3412", "#fff7ed"),13 unmodified linesSEC_ID_FROM_CHOICE = {SEC_NONE: None, **DIM_ID_FROM_CHOICE}SPEAKER_PALETTE = [("#ea580c", "#fff7ed", "#fed7aa", "π "),("#0e7490", "#ecfeff", "#a5f3fc", "π·"),("#065f46", "#ecfdf5", "#a7f3d0", "π’"),("#6b21a8", "#faf5ff", "#e9d5ff", "π£"),("#b45309", "#fffbeb", "#fde68a", "π‘"),("#be123c", "#fff1f2", "#fecdd3", "π΄"),]151 unmodified linesif i < cur_idx:bg, tc, border, dot = "#dcfce7", "#15803d", "#86efac", "β"elif i == cur_idx:bg, tc, border, dot = "#fff7ed", "#c2410c", "#fdba74", "βΆ"else:bg, tc, border, dot = "#fafaf9", "#a8a29e", "#e7e5e4", "β"steps.append(f'<div style="display:flex;flex-direction:column;align-items:center;'f'gap:3px;padding:6px 12px;border-radius:8px;background:{bg};'9 unmodified linesn_wins = len(screener["candidate_windows"]) if screener else "β"return (f'<div style="background:white;padding:10px 24px;display:flex;'f'align-items:center;gap:16px;flex-wrap:wrap;font-family:Inter,system-ui,sans-serif">'f'<div style="display:flex;align-items:center;gap:10px;margin-right:8px">'f'<div style="width:8px;height:8px;border-radius:50%;'f'background:#ea580c;box-shadow:0 0 0 3px #ffedd5"></div>'f'<div style="line-height:1.3">'f'<div style="font-weight:800;color:#1c1917;font-size:0.88em;'f'letter-spacing:-0.01em">{session}</div>'f'<div style="font-size:0.7em;color:#a8a29e">'f'{turns} turns Β· {n_wins} candidate windows Β· ~{savings} LLM savings'f'</div></div></div>'f'<div style="display:flex;gap:5px;flex-wrap:wrap">{"".join(steps)}</div>'f'</div>')8 unmodified lines"success": ("#f0fdf4", "#065f46", "#86efac", "β"),"error": ("#fef2f2", "#991b1b", "#fca5a5", "β"),"warning": ("#fffbeb", "#78350f", "#fbbf24", "β "),"processing": ("#fff7ed", "#9a3412", "#fdba74", "β³"),}bg, tc, bc, icon = colors.get(status, colors["success"])detail_html = ""23 unmodified linesdef _loading_card(title: str, subtitle: str = "Please waitβ¦", spin: str = "β") -> str:return ('<div style="background:#fff7ed;border:2px solid #fdba74;border-radius:12px;''padding:18px 20px;margin:10px 0;font-family:system-ui,sans-serif">''<div style="display:flex;align-items:center;gap:12px">'f'<div style="font-size:1.35em;color:#7c2d12">{spin}</div>'f'<div><div style="font-weight:800;color:#7c2d12;font-size:1.02em">{_h(title)}</div>'f'<div style="margin-top:4px;font-size:0.86em;color:#475569">{_h(subtitle)}</div></div>''</div></div>')8 unmodified linescirc_icon = "β" if circ == "CLOSED" else "β " if circ == "HALF_OPEN" else "β"eta_str = f"~{remaining}s" if remaining > 5 else "finishingβ¦"return (f'<div style="background:#fff7ed;border:2px solid #fdba74;'f'border-radius:12px;padding:16px 20px;font-family:system-ui,sans-serif">'f'<div style="display:flex;align-items:center;gap:10px;margin-bottom:12px">'f'<span style="font-size:1.3em">{spinner}</span>'f'<span style="font-weight:700;color:#7c2d12;font-size:0.94em">{_h(message)}</span>'f'<span style="margin-left:auto;font-family:monospace;font-size:0.84em;'f'background:#ffedd5;padding:3px 9px;border-radius:6px;color:#9a3412">'f'{elapsed}s elapsed</span></div>'f'<div style="background:#ffedd5;border-radius:5px;height:9px;'f'margin-bottom:10px;overflow:hidden">'f'<div style="height:100%;width:{pct}%;background:#ea580c;border-radius:5px"></div>'f'</div>'f'<div style="display:flex;flex-wrap:wrap;gap:14px;font-size:0.8em;color:#475569">'f'<span>Est: ~{est_total}s</span>'f'<span>ETA: {eta_str}</span>'f'<span>~{tokens_in:,} tokens</span>'f'<span style="color:{circ_color};font-weight:600">'f'Circuit: {circ_icon} {circ}</span>'f'</div></div>'22 unmodified linesf'<div style="border:1px solid #e2e8f0;border-radius:8px;'f'padding:10px 12px;margin-bottom:8px;background:white">'f'<div style="display:flex;justify-content:space-between;margin-bottom:4px">'f'<span style="font-weight:700;font-size:0.88em;color:#1c1917">{agent}</span>'f'<span style="font-size:0.72em;color:#94a3b8">{ts} Β· {runtime}s</span>'f'</div>'f'<div style="font-size:0.76em;color:#94a3b8">model: 'f'<strong style="color:#ea580c">{model}</strong></div>'f'{extra_lines}'f'</div>')24 unmodified linesf'<span style="font-family:monospace;font-size:0.7em;color:#94a3b8">{ts}</span>'f'<span style="font-family:monospace;font-size:0.67em;color:#cbd5e1">#{turn_id}</span>'f'</div>'f'<div style="line-height:1.6;color:#1c1917;font-size:0.93em">{text}</div>'f'</div></div>')return f'<div style="font-family:system-ui,sans-serif">{"".join(parts)}</div>'14 unmodified linesif score >= 0.40:return "#fef9c3", "#854d0e"if score >= 0.2:return "#fff7ed", "#c2410c"return "#f8fafc", "#94a3b8"6 unmodified linesreturn (f'<div style="display:flex;gap:12px;flex-wrap:wrap;'f'font-family:system-ui,sans-serif;margin-bottom:16px">'+ _stat_chip(str(total), "Total turns", "#ea580c", "#fff7ed")+ _stat_chip(str(flagged), "Flagged turns", "#065f46", "#dcfce7")+ _stat_chip(str(windows), "Candidate windows", "#b45309", "#fffbeb")+ _stat_chip(f"{savings:.0%}", "LLM savings", "#be123c", "#fef2f2")62 unmodified linesph = hit.get("phase", "")lbl = hit.get("category_label", "")tier = hit.get("tier", 1)tchip_bg = {"planning": "#fff7ed", "monitoring": "#f0fdf4","evaluating": "#fff7ed", "ssrl": "#faf5ff"}.get(ph, "#f8fafc")tchip_c = {"planning": "#c2410c", "monitoring": "#15803d","evaluating": "#c2410c", "ssrl": "#7c3aed"}.get(ph, "#64748b")tier_mark = "β¨2β©" if tier == 2 else "β¨3?β©" if tier == 3 else ""trigger_chips += (38 unmodified linesf'</div>'# Textf'<div style="font-size:0.85em;color:#1c1917;line-height:1.5">'f'{display_text}</div>'# Triggers31 unmodified linesf'font-family:monospace;min-width:44px;text-align:center">'f'{i:02d}</div>'f'<div style="flex:1">'f'<div style="font-weight:700;font-size:0.9em;color:#1c1917">'f'Turns {_h(str(start))}β{_h(str(end))} 'f'<span style="font-weight:400;color:#64748b">({n} turns)</span></div>'f'<div style="font-size:0.8em;color:#475569;margin-top:2px">'18 unmodified linesreturn '<p style="color:#94a3b8">Lexicon file not found.</p>'phase_colors = {"planning": ("#c2410c", "#fff7ed", "#ffedd5"),"monitoring": ("#15803d", "#f0fdf4", "#dcfce7"),"evaluating": ("#c2410c", "#fff7ed", "#fed7aa"),"ssrl": ("#7c3aed", "#faf5ff", "#e9d5ff"),28 unmodified linesf'<div style="display:flex;align-items:baseline;gap:10px;margin-bottom:6px">'f'<span style="font-family:monospace;font-size:0.8em;font-weight:700;'f'background:{bg};color:{tc};padding:2px 8px;border-radius:4px">{cat_id}</span>'f'<span style="font-weight:700;color:#1c1917">{label}</span>'f'<span style="margin-left:auto;font-size:0.78em;color:{tc};font-weight:600">'f'w={weight} Β· {_h(phase)}</span>'f'</div>'85 unmodified linesf'padding:12px 16px;margin-bottom:10px;background:#fffbeb">'f'<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px">'f'<span style="font-size:0.82em;font-weight:700;color:#b45309">β³ Pending</span>'f'<span style="font-weight:700;color:#1c1917">{label}</span>'f'<span style="margin-left:auto;font-size:0.72em;color:#94a3b8">{session}</span>'f'</div>'f'<div style="margin-bottom:8px">{term_chips}</div>'10 unmodified linesdef _dim_badge(did: str) -> str:colors = {"D1": ("#ea580c","#fff7ed"), "D2": ("#0e7490","#ecfeff"),"D3": ("#065f46","#ecfdf5"), "D4": ("#b45309","#fffbeb"),"D5": ("#6b21a8","#faf5ff"), "D6": ("#9a3412","#fff7ed"),"D7": ("#9a3412","#ffedd5"), "D8": ("#be123c","#fef2f2"),"D9": ("#374151","#f3f4f6"), "NS": ("#78716c","#f5f5f4"),"NA": ("#94a3b8","#f8fafc"),}36 unmodified linesscreener_tag = ('<span style="background:#d1fae5;color:#065f46;font-size:0.72em;''padding:2px 6px;border-radius:4px;margin-left:6px">''screener hit</span>')uncertain_tag = ""51 unmodified linesheader = (f'<div style="display:flex;gap:10px;margin-bottom:14px;flex-wrap:wrap">'+ _stat_chip(str(total), "Segments", "#ea580c", "#fff7ed")+ _stat_chip(str(coded), "D1-D9 coded", "#065f46", "#dcfce7")+ _stat_chip(str(ssrl_ct), "SSRL tagged", "#7c3aed", "#faf5ff")+ f'</div>'21 unmodified linescards.append(f'<div style="border:2px solid #e2e8f0;border-radius:10px;'f'padding:14px 16px;background:white">'f'<div style="font-weight:800;color:#1c1917;font-size:0.92em">'f'{_h(s["label"])}</div>'f'<div style="font-family:monospace;font-size:0.75em;color:#94a3b8;'f'margin:4px 0">{_h(s["start_time"])}β{_h(s["end_time"])}</div>'1 unmodified linef'{s["end_turn_id"]} ({n} turns Β· {pct}%)</div>'f'<div style="height:4px;background:#e2e8f0;border-radius:2px;'f'margin-top:8px;overflow:hidden">'f'<div style="height:100%;width:{pct}%;background:#ea580c;border-radius:2px">'f'</div></div>'f'</div>')return (f'<div style="font-family:system-ui,sans-serif">'f'<div style="display:flex;gap:8px;margin-bottom:10px;flex-wrap:wrap">'+ _stat_chip(str(n_turns), "Turns", "#ea580c", "#fff7ed")+ _stat_chip(str(len(sections)), "Sections", "#065f46", "#dcfce7")+ _stat_chip(str(n_speakers), "Speakers", "#b45309", "#fffbeb")+ _stat_chip(f"{elapsed}s", "Agent 0", "#7c3aed", "#faf5ff")54 unmodified linesif not desc:return ""return (f'<div style="background:#fff7ed;border-left:3px solid #ea580c;'f'border-radius:0 6px 6px 0;padding:7px 12px;font-size:0.85em;'f'color:#9a3412;margin-top:6px">{_h(desc)}</div>')19 unmodified linesf'padding:12px 16px;margin-bottom:12px">'f'<div style="display:flex;justify-content:space-between;align-items:baseline;'f'margin-bottom:6px">'f'<div style="font-size:0.88em;font-weight:700;color:#1c1917">'f'Section {idx+1}/{len(sections)} β {_h(sec.get("label",""))}</div>'f'<div style="font-size:0.82em;color:#64748b">Episode {min(cidx,total-1)+1} of {total}</div>'f'</div>'f'<div style="height:6px;background:#e2e8f0;border-radius:3px;overflow:hidden">'f'<div style="height:100%;width:{pct}%;background:#ea580c;border-radius:3px"></div>'f'</div>'f'<div style="display:flex;justify-content:space-between;margin-top:4px;'f'font-size:0.75em;color:#94a3b8">'83 unmodified linesseg_map = {s["segment_id"]: s for s in all_segs}parts = [f'<div style="font-family:system-ui,sans-serif">'f'<div style="font-weight:700;margin-bottom:10px;color:#1c1917">'f'{len(disags)} unresolved disagreements</div>']for d in disags:10 unmodified linesf'<span style="background:#fff7ed;color:#c2410c;font-weight:700;'f'padding:2px 8px;border-radius:4px">R1: {r1}</span>'f'<span style="color:#94a3b8">vs</span>'f'<span style="background:#fff7ed;color:#c2410c;font-weight:700;'f'padding:2px 8px;border-radius:4px">R2: {r2}</span>'f'</div>'f'<div style="font-size:0.82em;color:#64748b;font-style:italic">{rat}</div>'524 unmodified linesf'padding:12px 14px;margin-bottom:8px">'f'<div style="font-family:monospace;font-size:0.78em;'f'color:#94a3b8;margin-bottom:4px">{rid}</div>'f'<div style="font-size:0.9em;color:#1c1917">{desc}</div>'f'<div style="font-size:0.75em;color:#64748b;margin-top:4px">'f'From sessions: {src}</div>'f'</div>'29 unmodified lines# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββCUSTOM_CSS = """/* ββ Brand palette βββββββββββββββββββββββββββββββββββββ */:root {--primary: #ea580c;--primary-dark: #c2410c;--primary-darker: #7c2d12;--primary-light: #fff7ed;--primary-border: #fed7aa;--primary-mid: #fdba74;--surface: #ffffff;--surface-alt: #fafaf9;--border: #e7e5e4;--text: #1c1917;--text-muted: #78716c;--text-faint: #a8a29e;}/* ββ Global reset & type βββββββββββββββββββββββββββββββ */body, .gradio-container {font-family: system-ui, -apple-system, sans-serif !important;background: #fafaf9 !important;color: #1c1917 !important;}/* ββ App shell β remove Gradio's default grey box ββββ */.gradio-container > .main > .wrap { padding: 0 !important; }.gradio-container { max-width: 100% !important; padding: 0 !important; }footer { display: none !important; }/* ββ Branded top header βββββββββββββββββββββββββββββββββ */.cc-header {background: linear-gradient(135deg, #7c2d12 0%, #ea580c 60%, #f97316 100%);padding: 18px 32px;display: flex;align-items: center;gap: 16px;box-shadow: 0 2px 12px rgba(234,88,12,0.25);}.cc-header-logo {font-size: 1.6em;font-weight: 900;color: white;letter-spacing: -0.03em;}.cc-header-logo span { opacity: 0.7; font-weight: 400; }.cc-header-tag {font-size: 0.72em;background: rgba(255,255,255,0.18);color: white;padding: 3px 10px;border-radius: 20px;font-weight: 600;letter-spacing: 0.06em;text-transform: uppercase;}.cc-header-right {margin-left: auto;font-size: 0.78em;color: rgba(255,255,255,0.65);}/* ββ Pipeline status bar βββββββββββββββββββββββββββββββ */.pipeline-header {position: sticky;top: 0;z-index: 100;background: white;border-bottom: 2px solid var(--primary-border);box-shadow: 0 2px 8px rgba(234,88,12,0.08);}/* ββ Tabs βββββββββββββββββββββββββββββββββββββββββββββββ */.tabs > .tab-nav { border-bottom: 2px solid var(--primary-border) !important; }.tabs > .tab-nav button {font-weight: 700 !important;font-size: 0.88em !important;color: var(--text-muted) !important;padding: 10px 18px !important;border-radius: 0 !important;transition: color 0.15s, border-color 0.15s !important;}.tabs > .tab-nav button.selected {color: var(--primary) !important;border-bottom: 3px solid var(--primary) !important;background: transparent !important;}.tabs > .tab-nav button:hover { color: var(--primary-dark) !important; }/* ββ Cards / containers βββββββββββββββββββββββββββββββββ */.gr-box, .gr-panel, .gr-form {border-radius: 12px !important;border-color: var(--border) !important;box-shadow: 0 1px 4px rgba(0,0,0,0.06) !important;}/* ββ Inputs βββββββββββββββββββββββββββββββββββββββββββββ */input[type=text], textarea, .gr-input {border-color: var(--border) !important;border-radius: 8px !important;font-size: 0.9em !important;}input[type=text]:focus, textarea:focus {border-color: var(--primary) !important;box-shadow: 0 0 0 3px rgba(234,88,12,0.12) !important;outline: none !important;}/* ββ Buttons ββββββββββββββββββββββββββββββββββββββββββββ */.gr-button-primary, button[class*="primary"] {background: linear-gradient(135deg, var(--primary-dark), var(--primary)) !important;border: none !important;color: white !important;font-weight: 700 !important;border-radius: 8px !important;box-shadow: 0 2px 8px rgba(234,88,12,0.3) !important;transition: opacity 0.15s, box-shadow 0.15s !important;}.gr-button-primary:hover, button[class*="primary"]:hover {opacity: 0.93 !important;box-shadow: 0 4px 14px rgba(234,88,12,0.4) !important;}/* ββ Dropdowns ββββββββββββββββββββββββββββββββββββββββββ */.gr-dropdown { border-radius: 8px !important; }/* ββ Sliders ββββββββββββββββββββββββββββββββββββββββββββ */input[type=range]::-webkit-slider-thumb { background: var(--primary) !important; }input[type=range]::-webkit-slider-runnable-track { background: var(--primary-border) !important; }/* ββ Scrollbars βββββββββββββββββββββββββββββββββββββββββ */::-webkit-scrollbar { width: 6px; height: 6px; }::-webkit-scrollbar-track { background: #f5f5f4; }::-webkit-scrollbar-thumb { background: var(--primary-border); border-radius: 3px; }::-webkit-scrollbar-thumb:hover { background: var(--primary-mid); }/* ββ Markdown headings ββββββββββββββββββββββββββββββββββ */.gr-markdown h2 {font-size: 1.25em !important;font-weight: 800 !important;color: var(--primary-darker) !important;border-bottom: 2px solid var(--primary-border) !important;padding-bottom: 8px !important;margin-bottom: 12px !important;}.gr-markdown h3 {font-size: 1.02em !important;font-weight: 700 !important;color: var(--primary-dark) !important;}/* ββ Accordion ββββββββββββββββββββββββββββββββββββββββββ */.gr-accordion { border-color: var(--primary-border) !important; border-radius: 10px !important; }.gr-accordion > .label { color: var(--primary-dark) !important; font-weight: 700 !important; }""" + _load_css()_BRANDED_HEADER = """<div class="cc-header"><div class="cc-header-logo">Collab<span>Code</span></div><div class="cc-header-tag">Research Preview</div><div style="display:flex;gap:10px;margin-left:12px"><span style="background:rgba(255,255,255,0.15);color:white;font-size:0.72em;padding:3px 10px;border-radius:20px;font-weight:600">Metacognitive Talk Detector</span><span style="background:rgba(255,255,255,0.15);color:white;font-size:0.72em;padding:3px 10px;border-radius:20px;font-weight:600">SSRL Β· D1-D9</span></div><div class="cc-header-right">v5 Β· Qwen2.5-72B</div></div>"""def build_ui():with gr.Blocks(title="CollabCode β Metacognitive Talk Detector",css=CUSTOM_CSS,theme=gr.themes.Soft(primary_hue="orange",neutral_hue="stone",),) as demo:state = gr.State(_empty_state())# ββ Branded top header ββββββββββββββββββββββββββββββββββββββββββββββββgr.HTML(value=_BRANDED_HEADER)# ββ Persistent pipeline status ββββββββββββββββββββββββββββββββββββββββwith gr.Row(elem_classes=["pipeline-header"]):pipeline_header = gr.HTML(value=_pipeline_status_html(_empty_state()))3 unmodified lines# ================================================================# TAB 1 β SESSION# ================================================================with gr.Tab("Session"):gr.Markdown("## Session Setup")gr.HTML("""<div style="font-family:system-ui,sans-serif;font-size:0.9em;color:#78716c;margin-bottom:20px;max-width:600px">Enter your researcher ID, then choose how to load a transcript below.Your ID is used to namespace codings and keep sessions separate across researchers.</div>""")researcher_id = gr.Textbox(label="Researcher ID",placeholder="e.g. R1_Lara",info="Used to namespace your codings and Drive sessions.",scale=1,)# Three cardsgr.HTML("""<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin:20px 0;font-family:system-ui,sans-serif"><div style="background:white;border:2px solid #fed7aa;border-radius:14px;padding:20px 20px 14px;box-shadow:0 2px 8px rgba(234,88,12,0.08)"><div style="font-size:0.68em;font-weight:800;letter-spacing:0.1em;text-transform:uppercase;color:#ea580c;margin-bottom:6px">Option A</div><div style="font-weight:800;font-size:1.05em;color:#1c1917;margin-bottom:4px">Upload local file</div><div style="font-size:0.82em;color:#78716c;line-height:1.5">Upload a .txt, .vtt, or .srt transcript file from your computer.</div></div><div style="background:white;border:2px solid #e7e5e4;border-radius:14px;padding:20px 20px 14px;box-shadow:0 2px 8px rgba(0,0,0,0.04)"><div style="font-size:0.68em;font-weight:800;letter-spacing:0.1em;text-transform:uppercase;color:#78716c;margin-bottom:6px">Option B</div><div style="font-weight:800;font-size:1.05em;color:#1c1917;margin-bottom:4px">Load from Drive</div><div style="font-size:0.82em;color:#78716c;line-height:1.5">Connect to Google Drive and pick a transcript from your shared folder.</div></div><div style="background:white;border:2px solid #e7e5e4;border-radius:14px;padding:20px 20px 14px;box-shadow:0 2px 8px rgba(0,0,0,0.04)"><div style="font-size:0.68em;font-weight:800;letter-spacing:0.1em;text-transform:uppercase;color:#78716c;margin-bottom:6px">Option C</div><div style="font-weight:800;font-size:1.05em;color:#1c1917;margin-bottom:4px">Restore session</div><div style="font-size:0.82em;color:#78716c;line-height:1.5">Continue a previous coding session saved to Drive.</div></div></div>""")with gr.Row():with gr.Column(scale=1):local_file = gr.File(label="A β Upload .txt / .vtt / .srt transcript",file_types=[".txt", ".vtt", ".srt"],)upload_btn = gr.Button("Load local file", variant="primary")with gr.Column(scale=1):refresh_drive_btn = gr.Button("Connect to Drive")drive_dropdown = gr.Dropdown(label="B β Select transcript from Drive",choices=[], interactive=False,)drive_load_btn = gr.Button("Load from Drive")with gr.Column(scale=1):load_session_btn = gr.Button("C β Restore previous session")session_status = gr.HTML()21 unmodified lines# ================================================================# TAB 2 β SCREENER# ================================================================with gr.Tab("Screener"):gr.Markdown("## Metacognitive Talk Screener\n""Scans every turn with the research-backed trigger lexicon before any LLM call. "1 unmodified line"Yellow β structural signal (question mark, interruption, rapid exchange).")with gr.Row():run_screener_btn = gr.Button("Run Screener", variant="primary", scale=2)screener_info = gr.HTML(scale=3)screener_status = gr.HTML()20 unmodified lines# ================================================================# TAB 3 β SECTIONS# ================================================================with gr.Tab("Sections"):gr.Markdown("## Structural Sections (Agent 0)\n""Agent 0 detects the high-level structure of the session ""(e.g. warm-up, main task, wrap-up). Review and edit labels before coding.")with gr.Row():run_agent0_btn = gr.Button("Run Agent 0 β Detect sections", variant="primary")sections_status = gr.HTML()sections_display = gr.HTML()7 unmodified lineslines=6, placeholder="Introduction\nMain Task\nWrap-up")with gr.Row():confirm_sections_btn = gr.Button("Confirm sections", variant="primary")sections_confirm_status = gr.HTML()run_agent0_btn.click(10 unmodified lines# ================================================================# TAB 4 β PIPELINE# ================================================================with gr.Tab("Pipeline"):gr.Markdown("## Coding Pipeline (Agent 1a + 1b)\n""Runs boundary detection and dimension coding on all confirmed sections. ""Uses screener windows to focus LLM calls on metacognitive candidate turns.")with gr.Row():run_pipeline_btn = gr.Button("Run full pipeline", variant="primary", scale=2)pipeline_info = gr.HTML(scale=3)pipeline_status_out = gr.HTML()21 unmodified linessec_dropdown = gr.Dropdown(label="Secondary dimension (optional)",choices=SEC_DIM_CHOICES, value=SEC_NONE)coding_note = gr.Textbox(label="Note (optional)", lines=2)save_btn = gr.Button("Save coding", variant="primary")save_status_out = gr.HTML()manual_btn_visible = gr.Column(visible=False)34 unmodified lines# ================================================================# TAB 5 β REVIEW# ================================================================with gr.Tab("Review"):gr.Markdown("## Segment Review & Editing\n""All coded segments. Green π badge = screener flagged this segment "1 unmodified line)with gr.Row():refresh_review_btn = gr.Button("Refresh view", scale=1)review_info = gr.HTML(scale=4)review_display = gr.HTML()10 unmodified lineschoices=SSRL_CHOICES,value=SSRL_CHOICES[-1], # NONE)save_ssrl_btn = gr.Button("Save SSRL tag", variant="secondary")ssrl_status = gr.HTML()refresh_review_btn.click(9 unmodified lines# ================================================================# TAB 6 β AGREEMENT# ================================================================with gr.Tab("Agreement"):gr.Markdown("## Inter-Rater Reliability\n""Upload coding files from both researchers. "4 unmodified linesr1_file = gr.File(label="R1 codings (.json)", file_types=[".json"])r2_file = gr.File(label="R2 codings (.json)", file_types=[".json"])calc_kappa_btn = gr.Button("Calculate agreement", variant="primary")kappa_status_out = gr.HTML()kappa_summary_out = gr.HTML()disagreement_out = gr.HTML()55 unmodified lines# ================================================================# TAB 7 β LEXICON# ================================================================with gr.Tab("Lexicon"):gr.Markdown("## Trigger Word Lexicon\n""The research-backed vocabulary used to screen turns before LLM coding. "2 unmodified lines"Tier 3 holds candidates proposed by the system β review and approve or reject them.")with gr.Row():load_lexicon_btn = gr.Button("Load / refresh lexicon", variant="primary")lexicon_status = gr.HTML()with gr.Tabs():with gr.Tab("Tier 1 β Research-locked"):gr.Markdown("Source: Halmo et al. 2022, Zimmerman SRL model, ""JΓ€rvelΓ€ & Hadwin SSRL, LIWC cognitive categories, "1 unmodified line)tier1_html = gr.HTML()with gr.Tab("Tier 2 β Validated terms"):gr.Markdown("Terms you've validated in your specific participant population. ""These are used at full weight by the screener."25 unmodified lines)t2_note = gr.Textbox(label="Note / source", lines=2,placeholder="Observed in Session 3 and 4.")add_t2_btn = gr.Button("Add to Tier 2", variant="primary")add_t2_status = gr.HTML()with gr.Tab("Tier 3 β Candidates"):gr.Markdown("Words that appeared in LLM-coded metacognitive segments but ""aren't in Tier 1 or 2 yet. Review each one: approve to move to Tier 2, "6 unmodified linest3_term = gr.Textbox(label="Term to approve/reject")t3_note = gr.Textbox(label="Rejection note (optional)")with gr.Row():approve_t3_btn = gr.Button("Approve", variant="primary")reject_t3_btn = gr.Button("Reject")t3_action_status = gr.HTML()load_lexicon_btn.click(20 unmodified lines# ================================================================# TAB 8 β LEARNING# ================================================================with gr.Tab("Learning"):gr.Markdown("## Agent 2 β Rule Learning\n""After sessions accumulate disagreements, Agent 2 proposes coding rules "1 unmodified line"before they become active in Tier 2.")with gr.Row():load_rules_btn = gr.Button("Load pending rules", variant="primary")learning_status = gr.HTML()pending_rules_html = gr.HTML()3 unmodified linesrule_id_box = gr.Textbox(label="Rule ID")rule_note_box = gr.Textbox(label="Rejection note (optional)")with gr.Row():approve_rule_btn = gr.Button("Approve rule", variant="primary")reject_rule_btn = gr.Button("Reject rule")rule_action_status = gr.HTML()load_rules_btn.click(
app.py+316-108