"""Review Pilot — web UI (Gradio). A small front end over the Review Pilot agent: paste a GitHub pull request, get a risk-flagged review briefing. Runs the same Strands agent as the CLI. Backend is chosen by the MODEL_BACKEND env var (groq | gemini | bedrock | ollama). Deployed demo uses `groq` (free tier); local dev uses `ollama`. """ from __future__ import annotations import time import gradio as gr from dotenv import load_dotenv load_dotenv() # load .env locally; a no-op in hosted envs that use real env vars from pr_review_agent.agent import ( assemble_context, current_model_label, reason_over, ) from pr_review_agent.tools import ( get_pr_diff, get_pr_metadata, get_repo_conventions, parse_pr_ref, ) # Hugging Face's free Gradio Spaces run on ZeroGPU, which refuses to start unless a # @spaces.GPU function exists. Review Pilot only does network I/O (it calls a hosted # model), so it needs no GPU — this tiny no-op just satisfies that startup check. # Wrapped in try/except so local dev (where `spaces` isn't installed) is unaffected. try: # pragma: no cover - only runs on Hugging Face Spaces import spaces @spaces.GPU(duration=15) def _zerogpu_startup_probe() -> bool: return True except Exception: pass # Which model is answering — shown in the header as a small technical detail. # Resolved from the agent module so the label can't drift from what actually runs. _MODEL_LABEL = current_model_label() CSS = """ @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap'); :root, .gradio-container { --rp-bg: #FBFAF8; --rp-surface: #FFFFFF; --rp-ink: #1C1B19; --rp-ink2: #605B54; --rp-ink3: #948E85; --rp-border: #E9E5DE; --rp-border-strong: #D9D4CB; --rp-accent: #3E39C9; --rp-accent-hover: #302CA6; --rp-accent-soft: #EEEDFB; color-scheme: light; } /* force the light "paper" look regardless of the viewer's dark mode */ html, body, gradio-app, .gradio-container, .app, .main { background: var(--rp-bg) !important; color: var(--rp-ink) !important; } .gradio-container { font-family: 'IBM Plex Sans', system-ui, sans-serif !important; max-width: 780px !important; margin: 0 auto !important; /* override Gradio's theme text vars so nothing inherits dark-mode light text */ --body-text-color: #1C1B19 !important; --body-text-color-subdued: #605B54 !important; --block-title-text-color: #1C1B19 !important; --block-label-text-color: #605B54 !important; --block-background-fill: var(--rp-surface) !important; } footer { display: none !important; } /* header */ #rp-header { border-bottom: 1px solid var(--rp-border); padding: 4px 0 18px; margin-bottom: 26px; } #rp-header .rp-bar { display: flex; align-items: center; justify-content: space-between; } #rp-header .rp-brand { display: flex; align-items: center; gap: 11px; } #rp-header .rp-name { font-family: 'Space Grotesk', system-ui, sans-serif; font-weight: 700; font-size: 17px; letter-spacing: -0.02em; color: var(--rp-ink); } #rp-header .rp-tag { font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; letter-spacing: 0.12em; color: var(--rp-ink3); border: 1px solid #E4E0D8; border-radius: 3px; padding: 3px 6px; } #rp-header .rp-model { display: flex; align-items: center; gap: 8px; font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--rp-ink3); } #rp-header .rp-dot { width: 6px; height: 6px; border-radius: 50%; background: #3B8C5A; } #rp-header .rp-eyebrow { font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; letter-spacing: 0.16em; color: var(--rp-accent); margin: 28px 0 14px; } #rp-header h1.rp-headline { font-family: 'Space Grotesk', system-ui, sans-serif !important; font-weight: 600; font-size: 34px; line-height: 1.1; letter-spacing: -0.03em; margin: 0 0 14px; color: var(--rp-ink) !important; } #rp-header p.rp-sub { font-size: 15.5px; line-height: 1.6; color: var(--rp-ink2) !important; margin: 0; max-width: 560px; } /* input row */ #pr-input textarea, #pr-input input { font-family: 'IBM Plex Mono', monospace !important; font-size: 14px !important; background: var(--rp-surface) !important; border: 1px solid var(--rp-border-strong) !important; border-radius: 9px !important; color: var(--rp-ink) !important; box-shadow: 0 1px 2px rgba(28,27,25,0.03) !important; } #pr-input textarea:focus, #pr-input input:focus { border-color: var(--rp-accent) !important; box-shadow: 0 0 0 3px var(--rp-accent-soft) !important; } #pr-input .container, #pr-input label { background: transparent !important; } #review-btn { min-width: 128px; } #review-btn button { background: var(--rp-accent) !important; color: #fff !important; border: none !important; border-radius: 9px !important; font-family: 'IBM Plex Sans', system-ui, sans-serif !important; font-weight: 600 !important; font-size: 14.5px !important; box-shadow: 0 1px 2px rgba(62,57,201,0.25) !important; } #review-btn button:hover { background: var(--rp-accent-hover) !important; } /* examples */ #rp-examples { margin-top: 6px; } #rp-examples .label-wrap, #rp-examples label, #rp-examples span { font-family: 'IBM Plex Mono', monospace !important; font-size: 11.5px !important; color: var(--rp-ink2) !important; letter-spacing: 0.08em; } #rp-examples button, #rp-examples td, #rp-examples .token { font-family: 'IBM Plex Mono', monospace !important; font-size: 12.5px !important; background: #F2EFE9 !important; border: 1px solid #E4E0D8 !important; border-radius: 6px !important; color: #46423C !important; } /* output report */ #review-output { background: var(--rp-surface); border: 1px solid var(--rp-border); border-radius: 14px; padding: 12px 30px 26px; margin-top: 22px; color: #34302B; } #review-output h2 { font-family: 'Space Grotesk', system-ui, sans-serif !important; font-weight: 600; font-size: 15px; letter-spacing: 0.02em; margin: 34px 0 12px; padding-bottom: 10px; border-bottom: 1px solid var(--rp-border); color: var(--rp-ink) !important; } #review-output h2:first-child { margin-top: 14px; } #review-output h1, #review-output h3, #review-output strong { color: var(--rp-ink) !important; } #review-output p, #review-output li { font-size: 14.5px; line-height: 1.65; color: #34302B !important; } #review-output code { font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; background: #F2EFE9; padding: 1px 5px; border-radius: 4px; color: #2A2723 !important; } #review-output pre { background: var(--rp-ink) !important; border-radius: 11px; padding: 16px 18px; } #review-output pre code { background: transparent !important; color: #E8E4DC !important; font-size: 13px; line-height: 1.7; } #review-output ul { padding-left: 20px; } #review-output a { color: var(--rp-accent); } .rp-footnote { font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--rp-ink3); margin-top: 18px; text-align: center; } /* staged loader */ @keyframes rp-spin { to { transform: rotate(360deg); } } @keyframes rp-pulse { 0%,100% { opacity: 0.6; } 50% { opacity: 1; } } .rp-spin { animation: rp-spin 0.9s linear infinite; transform-origin: center; } .rp-loader { display: flex; flex-direction: column; gap: 2px; padding: 6px 2px; } .rp-step { display: flex; align-items: flex-start; gap: 13px; padding: 11px 14px; border-radius: 10px; } .rp-step.on { background: var(--rp-accent-soft); border: 1px solid #DAD7F6; animation: rp-pulse 1.5s ease-in-out infinite; } .rp-ic { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; } .rp-ic.done { background: #EAF4EE; border: 1px solid #CBE6D5; } .rp-ic.wait { border: 1.5px dashed #C9C3B9; } .rp-step .rp-t { font-size: 14px; font-weight: 500; color: var(--rp-ink); } .rp-step.on .rp-t { color: #2A2597; font-weight: 600; } .rp-step.pending .rp-t { color: var(--rp-ink2); } .rp-step .rp-s { font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--rp-ink3); margin-top: 2px; } .rp-step.on .rp-s { color: #6B67B8; } """ COMPASS = ( '' ) HEADER = f"""
Review Pilot reads the diff and the repository's own conventions, then hands your reviewer a risk-flagged briefing. It prepares the review — a human still decides.
""" PLACEHOLDER = "_Your review briefing will appear here — Summary, Risk Flags, Convention Check, Checklist, and a suggested PR description._" _CHECK = ('') _SPIN = ('') _STEPS = [ ("Fetching the pull request", "contacting GitHub"), ("Reading the diff", "parsing the changes"), ("Checking repo conventions", "CONTRIBUTING · CLAUDE.md"), ("Reasoning over the changes", "weighing risk & impact"), ("Writing the briefing", "summary · flags · checklist"), ] def _loader(active: int) -> str: """Render the staged loading stepper as HTML; `active` is the in-progress step.""" rows = [] for i, (title, sub) in enumerate(_STEPS): if i < active: cls, ic = "done", f'{_CHECK}' elif i == active: cls, ic = "on", f'{_SPIN}' else: cls, ic = "pending", '' rows.append( f'