Spaces:
Running
Running
Commit Β·
dfbe0f0
1
Parent(s): 5ad4f48
updating the UI
Browse files
app.py
CHANGED
|
@@ -18,52 +18,209 @@ DEMO_RESULT = json.loads(SAMPLE_PATH.read_text(encoding="utf-8")) if SAMPLE_PATH
|
|
| 18 |
|
| 19 |
|
| 20 |
CSS = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
.gradio-container {
|
| 22 |
max-width: 1440px !important;
|
| 23 |
-
font-family:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
|
|
|
|
|
|
| 25 |
#uplan-header {
|
| 26 |
-
border-bottom: 1px solid
|
| 27 |
-
padding:
|
| 28 |
-
margin-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
#uplan-header h1 {
|
| 31 |
margin: 0;
|
| 32 |
-
font-size:
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
-webkit-background-clip: text;
|
| 36 |
-webkit-text-fill-color: transparent;
|
| 37 |
font-weight: 700;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
#uplan-header p {
|
| 40 |
-
margin:
|
| 41 |
-
color:
|
| 42 |
-
font-size:
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
|
|
|
|
|
|
| 44 |
.tool-card {
|
| 45 |
-
border: 1px solid
|
| 46 |
-
border-radius:
|
| 47 |
-
padding:
|
| 48 |
-
background:
|
| 49 |
-
backdrop-filter: blur(
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
.tool-card b {
|
| 53 |
color: rgba(255,255,255,0.95);
|
|
|
|
| 54 |
}
|
| 55 |
.tool-card hr {
|
| 56 |
border: 0;
|
| 57 |
-
border-top: 1px solid
|
| 58 |
-
margin:
|
| 59 |
}
|
| 60 |
-
|
|
|
|
| 61 |
.gradio-container textarea {
|
| 62 |
-
min-height:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
-
/* Better spacing for chat row */
|
| 65 |
.gradio-container .gap {
|
| 66 |
-
gap:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
"""
|
| 69 |
|
|
@@ -79,32 +236,40 @@ SEV_COLOR = {
|
|
| 79 |
def badge(text: str, severity: str) -> str:
|
| 80 |
bg, color = SEV_COLOR.get(severity, ("rgba(255,255,255,0.06)", "rgba(255,255,255,0.6)"))
|
| 81 |
return (
|
| 82 |
-
f"<span style='display:inline-
|
| 83 |
f"font-size:11px;font-weight:600;background:{bg};color:{color};"
|
| 84 |
-
f"border:1px solid {color}22;"
|
| 85 |
-
f"
|
|
|
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
|
| 89 |
def money(value: Any, currency: str = "") -> str:
|
| 90 |
if value is None:
|
| 91 |
-
return "<span style='color:rgba(
|
| 92 |
try:
|
| 93 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
except (TypeError, ValueError):
|
| 95 |
-
return f"<b style='color:
|
| 96 |
|
| 97 |
|
| 98 |
def score_bar(score: float) -> str:
|
| 99 |
pct = max(0, min(100, int(score * 100)))
|
| 100 |
color = "#f87171" if pct < 50 else "#fbbf24" if pct < 75 else "#34d399"
|
|
|
|
| 101 |
return f"""
|
| 102 |
-
<div style='margin-top:
|
| 103 |
-
<div style='display:flex;justify-content:space-between;font-size:
|
| 104 |
-
<span
|
|
|
|
| 105 |
</div>
|
| 106 |
-
<div style='height:
|
| 107 |
-
<div style='height:
|
| 108 |
</div>
|
| 109 |
</div>
|
| 110 |
"""
|
|
@@ -285,7 +450,7 @@ def backend_unavailable_result(message: str) -> dict[str, Any]:
|
|
| 285 |
def build_dashboard_html(raw_result: dict[str, Any]) -> str:
|
| 286 |
result = normalize_result(raw_result)
|
| 287 |
if not result:
|
| 288 |
-
return "<
|
| 289 |
|
| 290 |
fields = result.get("reliable_fields", {})
|
| 291 |
synthesis = result.get("narrative_synthesis", {})
|
|
@@ -299,96 +464,129 @@ def build_dashboard_html(raw_result: dict[str, Any]) -> str:
|
|
| 299 |
account_total = sum(float(item.get("amount") or 0) for item in fields.get("financial_accounts", []))
|
| 300 |
income_total = sum(float(item.get("annual_amount") or 0) for item in fields.get("income_sources", []))
|
| 301 |
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
|
| 306 |
html = f"""
|
| 307 |
-
<div style='font-family:
|
| 308 |
-
|
|
|
|
| 309 |
<div style='display:flex;justify-content:space-between;align-items:center'>
|
| 310 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
</div>
|
| 312 |
{score_bar(score)}
|
| 313 |
-
{
|
| 314 |
</div>
|
| 315 |
|
| 316 |
-
<div style='background:{card_bg};border:1px solid {card_border};border-radius:
|
| 317 |
-
<
|
| 318 |
-
|
| 319 |
-
<
|
| 320 |
-
<div><span style='{label_style}'>Sponsor</span><br><b style='color:#e2e8f0'>{result.get("sponsor_name") or "not found"}</b></div>
|
| 321 |
</div>
|
| 322 |
-
<div style='
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
</div>
|
| 324 |
|
| 325 |
-
<div style='background:{card_bg};border:1px solid {card_border};border-radius:
|
| 326 |
-
<
|
| 327 |
-
|
| 328 |
-
<
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
<div><span style='{label_style}'>
|
|
|
|
|
|
|
|
|
|
| 332 |
</div>
|
| 333 |
</div>
|
| 334 |
"""
|
| 335 |
|
| 336 |
if docs:
|
| 337 |
rows = "".join(
|
| 338 |
-
f"<div style='display:flex;justify-content:space-between;padding:
|
| 339 |
-
f"<span style='color:
|
| 340 |
-
f"<span style='color:rgba(
|
| 341 |
for doc in docs
|
| 342 |
)
|
| 343 |
-
html += card("Documents", rows)
|
| 344 |
|
| 345 |
if fields.get("name_variants"):
|
| 346 |
rows = "".join(
|
| 347 |
-
f"<div style='font-size:
|
| 348 |
for key, value in fields["name_variants"].items()
|
| 349 |
)
|
| 350 |
-
html += card("Name consistency", rows)
|
| 351 |
|
| 352 |
if findings:
|
| 353 |
rows = "".join(
|
| 354 |
-
f"<div style='padding:
|
| 355 |
-
f"<div><b style='color:
|
| 356 |
-
f"<div style='font-size:12px;color:rgba(
|
| 357 |
f"</div>"
|
| 358 |
for finding in findings
|
| 359 |
)
|
| 360 |
-
html += card("Agent findings", rows)
|
| 361 |
|
| 362 |
if synthesis.get("compound_flags"):
|
| 363 |
-
rows = "".join(f"<div style='font-size:
|
| 364 |
-
html += card("Cross-document risks", rows, bg="rgba(245,158,11,0.
|
| 365 |
|
| 366 |
adversarial = result.get("adversarial_audit", {})
|
| 367 |
if adversarial.get("rejection_case") or adversarial.get("rebuttal_case"):
|
| 368 |
rows = ""
|
| 369 |
if adversarial.get("rejection_case"):
|
| 370 |
-
rows += f"<div style='font-size:
|
| 371 |
if adversarial.get("rebuttal_case"):
|
| 372 |
-
rows += f"<div style='font-size:
|
| 373 |
-
html += card("Adversarial audit", rows)
|
| 374 |
|
| 375 |
if result.get("next_steps"):
|
| 376 |
rows = "".join(
|
| 377 |
-
f"<div style='display:flex;gap:
|
| 378 |
for step in result["next_steps"]
|
| 379 |
)
|
| 380 |
-
html += card("Next steps", rows)
|
| 381 |
|
| 382 |
cert = result.get("deletion_cert") or raw_result.get("full_result", {}).get("deletion_cert")
|
| 383 |
if cert:
|
| 384 |
-
html += f"<div style='background:rgba(255,255,255,0.
|
| 385 |
|
| 386 |
html += "</div>"
|
| 387 |
return html
|
| 388 |
|
| 389 |
|
| 390 |
-
def card(title: str, body: str, bg: str = "rgba(255,255,255,0.
|
| 391 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
|
| 394 |
def chat_response(message: str, history: list, result_state: dict) -> tuple[list, str]:
|
|
@@ -433,22 +631,31 @@ def handle_upload(files, demo_mode: bool):
|
|
| 433 |
HEADER_HTML = """
|
| 434 |
<div id='uplan-header'>
|
| 435 |
<h1>β‘ Uplan</h1>
|
| 436 |
-
<p>Immigration document intelligence β reads financial packets, audits evidence quality, flags inconsistencies, and builds a readiness roadmap.<
|
|
|
|
| 437 |
</div>
|
| 438 |
"""
|
| 439 |
|
| 440 |
|
| 441 |
CHECKLIST_HTML = """
|
| 442 |
-
<div class='tool-card' style='font-size:13px;line-height:
|
| 443 |
-
<
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
<
|
|
|
|
|
|
|
|
|
|
| 447 |
<hr>
|
| 448 |
-
<
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
</div>
|
| 453 |
"""
|
| 454 |
|
|
@@ -461,30 +668,30 @@ def build_ui():
|
|
| 461 |
gr.HTML(HEADER_HTML)
|
| 462 |
|
| 463 |
with gr.Row(equal_height=False):
|
| 464 |
-
with gr.Column(scale=1, min_width=
|
| 465 |
-
gr.Markdown("### Agent tools")
|
| 466 |
demo_toggle = gr.Checkbox(label="Demo mode", value=True, info="Uses a clearly marked sample analysis. Turn off for live AMD backend.")
|
| 467 |
upload_box = gr.File(label="Upload PDF packet", file_types=[".pdf"], file_count="multiple", visible=False)
|
| 468 |
demo_toggle.change(lambda enabled: gr.update(visible=not enabled), demo_toggle, upload_box)
|
| 469 |
-
analyse_btn = gr.Button("Analyse packet", variant="primary")
|
| 470 |
gr.HTML(CHECKLIST_HTML)
|
| 471 |
-
gr.Markdown("Raw documents are processed outside the UI in live mode. The extraction layer emits a deletion certificate after purge.")
|
| 472 |
|
| 473 |
with gr.Column(scale=2, min_width=360):
|
| 474 |
-
gr.Markdown("### Consultant")
|
| 475 |
chatbot = gr.Chatbot(
|
| 476 |
label="Consultant",
|
| 477 |
-
height=
|
| 478 |
show_label=False,
|
| 479 |
-
value=[{"role": "assistant", "content": "Welcome to Uplan. Load the sample demo or upload a packet when the AMD backend is online. The dashboard will
|
| 480 |
)
|
| 481 |
with gr.Row():
|
| 482 |
chat_input = gr.Textbox(placeholder="Ask about risks, missing evidence, or next steps...", show_label=False, container=False, scale=5)
|
| 483 |
send_btn = gr.Button("Send", variant="secondary", scale=1)
|
| 484 |
|
| 485 |
-
with gr.Column(scale=2, min_width=
|
| 486 |
-
gr.Markdown("### Readiness dashboard")
|
| 487 |
-
dashboard = gr.HTML("<
|
| 488 |
|
| 489 |
analyse_btn.click(handle_upload, [upload_box, demo_toggle], [dashboard, chatbot, result_state])
|
| 490 |
send_btn.click(chat_response, [chat_input, chatbot, result_state], [chatbot, chat_input])
|
|
@@ -498,6 +705,12 @@ if __name__ == "__main__":
|
|
| 498 |
server_name="0.0.0.0",
|
| 499 |
server_port=7860,
|
| 500 |
show_error=True,
|
| 501 |
-
theme=gr.themes.Soft(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
css=CSS,
|
| 503 |
)
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
CSS = """
|
| 21 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;450;500;600;700&display=swap');
|
| 22 |
+
|
| 23 |
+
:root {
|
| 24 |
+
--uplan-bg: #0c0d10;
|
| 25 |
+
--uplan-surface: rgba(255,255,255,0.035);
|
| 26 |
+
--uplan-surface-hover: rgba(255,255,255,0.06);
|
| 27 |
+
--uplan-border: rgba(255,255,255,0.07);
|
| 28 |
+
--uplan-border-accent: rgba(96,165,250,0.2);
|
| 29 |
+
--uplan-text: rgb(219,216,211);
|
| 30 |
+
--uplan-text-muted: rgba(219,216,211,0.55);
|
| 31 |
+
--uplan-text-dim: rgba(219,216,211,0.35);
|
| 32 |
+
--uplan-accent-1: #60a5fa;
|
| 33 |
+
--uplan-accent-2: #a78bfa;
|
| 34 |
+
--uplan-accent-3: #818cf8;
|
| 35 |
+
--uplan-green: #34d399;
|
| 36 |
+
--uplan-amber: #fbbf24;
|
| 37 |
+
--uplan-red: #f87171;
|
| 38 |
+
--uplan-radius: 14px;
|
| 39 |
+
--uplan-radius-sm: 10px;
|
| 40 |
+
--font-main: "Google Sans Flex", "Google Sans", "Inter", sans-serif;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* ββ Global Reset ββββββββββββββββββββββββββ */
|
| 44 |
.gradio-container {
|
| 45 |
max-width: 1440px !important;
|
| 46 |
+
font-family: var(--font-main) !important;
|
| 47 |
+
font-weight: 450 !important;
|
| 48 |
+
color: var(--uplan-text) !important;
|
| 49 |
+
background: var(--uplan-bg) !important;
|
| 50 |
+
font-size: 14px !important;
|
| 51 |
+
line-height: 1.6 !important;
|
| 52 |
+
-webkit-font-smoothing: antialiased;
|
| 53 |
+
-moz-osx-font-smoothing: grayscale;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.gradio-container .dark {
|
| 57 |
+
background: var(--uplan-bg) !important;
|
| 58 |
}
|
| 59 |
+
|
| 60 |
+
/* ββ Header ββββββββββββββββββββββββββββββββ */
|
| 61 |
#uplan-header {
|
| 62 |
+
border-bottom: 1px solid var(--uplan-border);
|
| 63 |
+
padding: 28px 0 24px;
|
| 64 |
+
margin-bottom: 20px;
|
| 65 |
+
position: relative;
|
| 66 |
+
}
|
| 67 |
+
#uplan-header::after {
|
| 68 |
+
content: '';
|
| 69 |
+
position: absolute;
|
| 70 |
+
bottom: -1px;
|
| 71 |
+
left: 0;
|
| 72 |
+
width: 120px;
|
| 73 |
+
height: 2px;
|
| 74 |
+
background: linear-gradient(90deg, var(--uplan-accent-1), var(--uplan-accent-2));
|
| 75 |
+
border-radius: 2px;
|
| 76 |
}
|
| 77 |
#uplan-header h1 {
|
| 78 |
margin: 0;
|
| 79 |
+
font-size: 54px;
|
| 80 |
+
line-height: 56px;
|
| 81 |
+
letter-spacing: -1.5px;
|
| 82 |
+
background: linear-gradient(135deg, var(--uplan-accent-1), var(--uplan-accent-2), var(--uplan-accent-3));
|
| 83 |
+
background-size: 200% 200%;
|
| 84 |
-webkit-background-clip: text;
|
| 85 |
-webkit-text-fill-color: transparent;
|
| 86 |
font-weight: 700;
|
| 87 |
+
animation: uplan-shimmer 6s ease-in-out infinite;
|
| 88 |
+
}
|
| 89 |
+
@keyframes uplan-shimmer {
|
| 90 |
+
0%, 100% { background-position: 0% 50%; }
|
| 91 |
+
50% { background-position: 100% 50%; }
|
| 92 |
}
|
| 93 |
#uplan-header p {
|
| 94 |
+
margin: 10px 0 0;
|
| 95 |
+
color: var(--uplan-text-muted);
|
| 96 |
+
font-size: 15px;
|
| 97 |
+
font-weight: 400;
|
| 98 |
+
max-width: 580px;
|
| 99 |
+
letter-spacing: 0.01em;
|
| 100 |
}
|
| 101 |
+
|
| 102 |
+
/* ββ Tool cards (sidebar) ββββββββββββββββββ */
|
| 103 |
.tool-card {
|
| 104 |
+
border: 1px solid var(--uplan-border);
|
| 105 |
+
border-radius: var(--uplan-radius);
|
| 106 |
+
padding: 18px 20px;
|
| 107 |
+
background: var(--uplan-surface);
|
| 108 |
+
backdrop-filter: blur(20px) saturate(1.2);
|
| 109 |
+
-webkit-backdrop-filter: blur(20px) saturate(1.2);
|
| 110 |
+
color: var(--uplan-text);
|
| 111 |
+
transition: border-color 0.3s ease, box-shadow 0.3s ease;
|
| 112 |
+
}
|
| 113 |
+
.tool-card:hover {
|
| 114 |
+
border-color: var(--uplan-border-accent);
|
| 115 |
+
box-shadow: 0 0 24px rgba(96,165,250,0.06);
|
| 116 |
}
|
| 117 |
.tool-card b {
|
| 118 |
color: rgba(255,255,255,0.95);
|
| 119 |
+
font-weight: 600;
|
| 120 |
}
|
| 121 |
.tool-card hr {
|
| 122 |
border: 0;
|
| 123 |
+
border-top: 1px solid var(--uplan-border);
|
| 124 |
+
margin: 14px 0;
|
| 125 |
}
|
| 126 |
+
|
| 127 |
+
/* ββ Chat styling ββββββββββββββββββββββββββ */
|
| 128 |
.gradio-container textarea {
|
| 129 |
+
min-height: 48px !important;
|
| 130 |
+
font-family: var(--font-main) !important;
|
| 131 |
+
font-weight: 450 !important;
|
| 132 |
+
border-radius: var(--uplan-radius-sm) !important;
|
| 133 |
+
border: 1px solid var(--uplan-border) !important;
|
| 134 |
+
background: var(--uplan-surface) !important;
|
| 135 |
+
transition: border-color 0.25s ease !important;
|
| 136 |
+
}
|
| 137 |
+
.gradio-container textarea:focus {
|
| 138 |
+
border-color: var(--uplan-accent-1) !important;
|
| 139 |
+
box-shadow: 0 0 0 3px rgba(96,165,250,0.1) !important;
|
| 140 |
}
|
|
|
|
| 141 |
.gradio-container .gap {
|
| 142 |
+
gap: 10px;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* ββ Buttons βββββββββββββββββββββββββββββββ */
|
| 146 |
+
.gradio-container button.primary {
|
| 147 |
+
background: linear-gradient(135deg, var(--uplan-accent-1), var(--uplan-accent-2)) !important;
|
| 148 |
+
border: none !important;
|
| 149 |
+
border-radius: var(--uplan-radius-sm) !important;
|
| 150 |
+
font-family: var(--font-main) !important;
|
| 151 |
+
font-weight: 600 !important;
|
| 152 |
+
letter-spacing: 0.02em;
|
| 153 |
+
padding: 10px 24px !important;
|
| 154 |
+
transition: transform 0.2s ease, box-shadow 0.25s ease !important;
|
| 155 |
+
box-shadow: 0 4px 16px rgba(96,165,250,0.15) !important;
|
| 156 |
+
}
|
| 157 |
+
.gradio-container button.primary:hover {
|
| 158 |
+
transform: translateY(-1px) !important;
|
| 159 |
+
box-shadow: 0 8px 28px rgba(96,165,250,0.25) !important;
|
| 160 |
+
}
|
| 161 |
+
.gradio-container button.secondary {
|
| 162 |
+
border-radius: var(--uplan-radius-sm) !important;
|
| 163 |
+
font-family: var(--font-main) !important;
|
| 164 |
+
font-weight: 500 !important;
|
| 165 |
+
border: 1px solid var(--uplan-border) !important;
|
| 166 |
+
background: var(--uplan-surface) !important;
|
| 167 |
+
transition: background 0.2s ease, border-color 0.2s ease !important;
|
| 168 |
+
}
|
| 169 |
+
.gradio-container button.secondary:hover {
|
| 170 |
+
background: var(--uplan-surface-hover) !important;
|
| 171 |
+
border-color: var(--uplan-accent-1) !important;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
/* ββ Chatbot bubble override βββββββββββββββ */
|
| 175 |
+
.gradio-container .chatbot .message {
|
| 176 |
+
font-family: var(--font-main) !important;
|
| 177 |
+
font-weight: 450 !important;
|
| 178 |
+
border-radius: var(--uplan-radius) !important;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
/* ββ Labels & markdown βββββββββββββββββββββ */
|
| 182 |
+
.gradio-container label, .gradio-container .label-wrap span {
|
| 183 |
+
font-family: var(--font-main) !important;
|
| 184 |
+
font-weight: 500 !important;
|
| 185 |
+
letter-spacing: 0.01em;
|
| 186 |
+
}
|
| 187 |
+
.gradio-container .prose h3, .gradio-container .markdown h3 {
|
| 188 |
+
font-family: var(--font-main) !important;
|
| 189 |
+
font-weight: 600 !important;
|
| 190 |
+
font-size: 18px !important;
|
| 191 |
+
letter-spacing: -0.3px;
|
| 192 |
+
color: var(--uplan-text) !important;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
/* ββ File upload βββββββββββββββββββββββββββ */
|
| 196 |
+
.gradio-container .upload-area {
|
| 197 |
+
border: 1px dashed var(--uplan-border) !important;
|
| 198 |
+
border-radius: var(--uplan-radius) !important;
|
| 199 |
+
background: var(--uplan-surface) !important;
|
| 200 |
+
transition: border-color 0.25s ease !important;
|
| 201 |
+
}
|
| 202 |
+
.gradio-container .upload-area:hover {
|
| 203 |
+
border-color: var(--uplan-accent-1) !important;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
/* ββ Scrollbar βββββββββββββββββββββββββββββ */
|
| 207 |
+
.gradio-container ::-webkit-scrollbar { width: 6px; }
|
| 208 |
+
.gradio-container ::-webkit-scrollbar-track { background: transparent; }
|
| 209 |
+
.gradio-container ::-webkit-scrollbar-thumb {
|
| 210 |
+
background: rgba(255,255,255,0.1);
|
| 211 |
+
border-radius: 3px;
|
| 212 |
+
}
|
| 213 |
+
.gradio-container ::-webkit-scrollbar-thumb:hover {
|
| 214 |
+
background: rgba(255,255,255,0.18);
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
/* ββ Animations ββββββββββββββββββββββββββββ */
|
| 218 |
+
@keyframes uplan-fade-in {
|
| 219 |
+
from { opacity: 0; transform: translateY(8px); }
|
| 220 |
+
to { opacity: 1; transform: translateY(0); }
|
| 221 |
+
}
|
| 222 |
+
.uplan-dash-card {
|
| 223 |
+
animation: uplan-fade-in 0.4s ease-out both;
|
| 224 |
}
|
| 225 |
"""
|
| 226 |
|
|
|
|
| 236 |
def badge(text: str, severity: str) -> str:
|
| 237 |
bg, color = SEV_COLOR.get(severity, ("rgba(255,255,255,0.06)", "rgba(255,255,255,0.6)"))
|
| 238 |
return (
|
| 239 |
+
f"<span style='display:inline-flex;align-items:center;padding:4px 12px;border-radius:999px;"
|
| 240 |
f"font-size:11px;font-weight:600;background:{bg};color:{color};"
|
| 241 |
+
f"border:1px solid {color}22;letter-spacing:0.03em;"
|
| 242 |
+
f"font-family:\"Google Sans Flex\",\"Inter\",sans-serif;"
|
| 243 |
+
f"backdrop-filter:blur(8px);"
|
| 244 |
+
f"margin:2px 4px 2px 0;transition:all 0.2s ease'>{text}</span>"
|
| 245 |
)
|
| 246 |
|
| 247 |
|
| 248 |
def money(value: Any, currency: str = "") -> str:
|
| 249 |
if value is None:
|
| 250 |
+
return "<span style='color:rgba(219,216,211,0.3);font-style:italic;font-size:13px'>not found</span>"
|
| 251 |
try:
|
| 252 |
+
return (
|
| 253 |
+
f"<b style='color:rgb(219,216,211);font-weight:600;font-size:16px;"
|
| 254 |
+
f"font-family:\"Google Sans Flex\",\"Inter\",sans-serif'>"
|
| 255 |
+
f"{currency} {float(value):,.0f}</b>"
|
| 256 |
+
)
|
| 257 |
except (TypeError, ValueError):
|
| 258 |
+
return f"<b style='color:rgb(219,216,211);font-weight:600'>{value}</b>"
|
| 259 |
|
| 260 |
|
| 261 |
def score_bar(score: float) -> str:
|
| 262 |
pct = max(0, min(100, int(score * 100)))
|
| 263 |
color = "#f87171" if pct < 50 else "#fbbf24" if pct < 75 else "#34d399"
|
| 264 |
+
glow = f"0 0 12px {color}44"
|
| 265 |
return f"""
|
| 266 |
+
<div style='margin-top:14px'>
|
| 267 |
+
<div style='display:flex;justify-content:space-between;font-size:13px;margin-bottom:8px;color:rgba(219,216,211,0.6);font-family:"Google Sans Flex","Inter",sans-serif'>
|
| 268 |
+
<span style='font-weight:500'>Narrative coherence</span>
|
| 269 |
+
<b style='color:{color};font-size:18px;font-weight:700'>{pct}<span style='font-size:12px;font-weight:500;opacity:0.7'>%</span></b>
|
| 270 |
</div>
|
| 271 |
+
<div style='height:6px;background:rgba(255,255,255,0.06);border-radius:999px;overflow:hidden;position:relative'>
|
| 272 |
+
<div style='height:6px;width:{pct}%;background:linear-gradient(90deg,{color}99,{color});border-radius:999px;box-shadow:{glow};transition:width 0.8s cubic-bezier(0.4,0,0.2,1)'></div>
|
| 273 |
</div>
|
| 274 |
</div>
|
| 275 |
"""
|
|
|
|
| 450 |
def build_dashboard_html(raw_result: dict[str, Any]) -> str:
|
| 451 |
result = normalize_result(raw_result)
|
| 452 |
if not result:
|
| 453 |
+
return "<div style='text-align:center;padding:48px 16px;color:rgba(219,216,211,0.35);font-family:\"Google Sans Flex\",\"Inter\",sans-serif'><div style='font-size:40px;margin-bottom:12px;opacity:0.4'>π</div><p style='font-size:15px;font-weight:450'>Upload documents or run demo mode to begin.</p></div>"
|
| 454 |
|
| 455 |
fields = result.get("reliable_fields", {})
|
| 456 |
synthesis = result.get("narrative_synthesis", {})
|
|
|
|
| 464 |
account_total = sum(float(item.get("amount") or 0) for item in fields.get("financial_accounts", []))
|
| 465 |
income_total = sum(float(item.get("annual_amount") or 0) for item in fields.get("income_sources", []))
|
| 466 |
|
| 467 |
+
font = '"Google Sans Flex","Inter",sans-serif'
|
| 468 |
+
label_style = f"color:rgba(219,216,211,0.4);font-size:10px;text-transform:uppercase;letter-spacing:0.08em;font-weight:600;font-family:{font}"
|
| 469 |
+
card_bg = "rgba(255,255,255,0.03)"
|
| 470 |
+
card_border = "rgba(255,255,255,0.07)"
|
| 471 |
+
|
| 472 |
+
human_review_html = ""
|
| 473 |
+
if synthesis.get("human_review_required"):
|
| 474 |
+
human_review_html = f"<div style='display:flex;align-items:center;gap:8px;font-size:12px;color:#f87171;margin-top:10px;padding:8px 12px;background:rgba(248,113,113,0.06);border:1px solid rgba(248,113,113,0.12);border-radius:8px;font-family:{font}'><span style='font-size:16px'>β </span> <span style='font-weight:500'>Human review required</span></div>"
|
| 475 |
+
|
| 476 |
+
text_primary = "rgb(219,216,211)"
|
| 477 |
+
accent_bg = "linear-gradient(135deg,rgba(96,165,250,0.06),rgba(167,139,250,0.06))"
|
| 478 |
+
sub_card = "background:rgba(255,255,255,0.025);border:1px solid rgba(255,255,255,0.05);border-radius:10px;padding:12px 14px"
|
| 479 |
|
| 480 |
html = f"""
|
| 481 |
+
<div style='font-family:{font};font-weight:450;font-size:14px;line-height:1.6;color:{text_primary}'>
|
| 482 |
+
|
| 483 |
+
<div class='uplan-dash-card' style='background:{accent_bg};border:1px solid {card_border};border-radius:14px;padding:20px;margin-bottom:14px;backdrop-filter:blur(20px)'>
|
| 484 |
<div style='display:flex;justify-content:space-between;align-items:center'>
|
| 485 |
+
<div style='display:flex;align-items:center;gap:10px'>
|
| 486 |
+
<span style='font-size:20px'>π</span>
|
| 487 |
+
<b style='color:{text_primary};font-size:15px;font-weight:600'>Readiness overview</b>
|
| 488 |
+
</div>
|
| 489 |
+
{badge(overall, overall_sev)}
|
| 490 |
</div>
|
| 491 |
{score_bar(score)}
|
| 492 |
+
{human_review_html}
|
| 493 |
</div>
|
| 494 |
|
| 495 |
+
<div class='uplan-dash-card' style='background:{card_bg};border:1px solid {card_border};border-radius:14px;padding:20px;margin-bottom:14px;backdrop-filter:blur(16px)'>
|
| 496 |
+
<div style='display:flex;align-items:center;gap:10px;margin-bottom:14px'>
|
| 497 |
+
<span style='font-size:18px'>π€</span>
|
| 498 |
+
<b style='color:{text_primary};font-size:15px;font-weight:600'>Parties</b>
|
|
|
|
| 499 |
</div>
|
| 500 |
+
<div style='display:grid;grid-template-columns:1fr 1fr;gap:14px'>
|
| 501 |
+
<div style='{sub_card}'>
|
| 502 |
+
<span style='{label_style}'>Applicant</span>
|
| 503 |
+
<div style='margin-top:6px;font-weight:500;color:{text_primary}'>{result.get("applicant_name") or fields.get("beneficiary_name") or "not found"}</div>
|
| 504 |
+
</div>
|
| 505 |
+
<div style='{sub_card}'>
|
| 506 |
+
<span style='{label_style}'>Sponsor</span>
|
| 507 |
+
<div style='margin-top:6px;font-weight:500;color:{text_primary}'>{result.get("sponsor_name") or "not found"}</div>
|
| 508 |
+
</div>
|
| 509 |
+
</div>
|
| 510 |
+
<div style='margin-top:10px;color:rgba(219,216,211,0.5);font-size:13px'>Relationship: <b style='color:{text_primary};font-weight:500'>{result.get("sponsor_relationship") or fields.get("spon_relationship") or "not found"}</b></div>
|
| 511 |
</div>
|
| 512 |
|
| 513 |
+
<div class='uplan-dash-card' style='background:{card_bg};border:1px solid {card_border};border-radius:14px;padding:20px;margin-bottom:14px;backdrop-filter:blur(16px)'>
|
| 514 |
+
<div style='display:flex;align-items:center;gap:10px;margin-bottom:14px'>
|
| 515 |
+
<span style='font-size:18px'>π°</span>
|
| 516 |
+
<b style='color:{text_primary};font-size:15px;font-weight:600'>Financial summary</b>
|
| 517 |
+
</div>
|
| 518 |
+
<div style='display:grid;grid-template-columns:1fr 1fr;gap:12px'>
|
| 519 |
+
<div style='{sub_card}'><span style='{label_style}'>Required funds</span><div style='margin-top:6px'>{money(t_req, currency)}</div></div>
|
| 520 |
+
<div style='{sub_card}'><span style='{label_style}'>Liquid / deposit evidence</span><div style='margin-top:6px'>{money(account_total or fields.get("balance_closing"), currency)}</div></div>
|
| 521 |
+
<div style='{sub_card}'><span style='{label_style}'>Affidavit income</span><div style='margin-top:6px'>{money(fields.get("i_aff") or income_total, currency)}</div></div>
|
| 522 |
+
<div style='{sub_card}'><span style='{label_style}'>Tax verified income</span><div style='margin-top:6px'>{money(fields.get("i_tax"), currency)}</div></div>
|
| 523 |
</div>
|
| 524 |
</div>
|
| 525 |
"""
|
| 526 |
|
| 527 |
if docs:
|
| 528 |
rows = "".join(
|
| 529 |
+
f"<div style='display:flex;justify-content:space-between;align-items:center;padding:8px 0;border-bottom:1px solid rgba(255,255,255,0.04)'>"
|
| 530 |
+
f"<span style='color:rgb(219,216,211);font-weight:500'>{doc.get('type','unknown').replace('_',' ').title()}</span>"
|
| 531 |
+
f"<span style='display:flex;align-items:center;gap:8px;color:rgba(219,216,211,0.4);font-size:12px'>{doc.get('pages',0)}p Β· {doc.get('quality','unknown')} {badge(doc.get('status','seen'), 'pass')}</span></div>"
|
| 532 |
for doc in docs
|
| 533 |
)
|
| 534 |
+
html += card("π Documents", rows)
|
| 535 |
|
| 536 |
if fields.get("name_variants"):
|
| 537 |
rows = "".join(
|
| 538 |
+
f"<div style='font-size:13px;color:rgba(219,216,211,0.6);padding:4px 0'><span style='color:rgba(219,216,211,0.35);font-weight:500'>{key.replace('_',' ').title()}</span>: <span style='color:rgb(219,216,211);font-weight:500'>{value}</span></div>"
|
| 539 |
for key, value in fields["name_variants"].items()
|
| 540 |
)
|
| 541 |
+
html += card("π Name consistency", rows)
|
| 542 |
|
| 543 |
if findings:
|
| 544 |
rows = "".join(
|
| 545 |
+
f"<div style='padding:10px 0;border-bottom:1px solid rgba(255,255,255,0.04)'>"
|
| 546 |
+
f"<div style='display:flex;align-items:center;gap:8px'><b style='color:rgb(219,216,211);font-weight:600'>{finding.get('rule_id','rule').replace('_',' ').title()}</b> {badge(finding.get('severity','info').title(), finding.get('severity','info'))}</div>"
|
| 547 |
+
f"<div style='font-size:12px;color:rgba(219,216,211,0.45);margin-top:4px;line-height:1.5'>{finding.get('message','')}</div>"
|
| 548 |
f"</div>"
|
| 549 |
for finding in findings
|
| 550 |
)
|
| 551 |
+
html += card("π Agent findings", rows)
|
| 552 |
|
| 553 |
if synthesis.get("compound_flags"):
|
| 554 |
+
rows = "".join(f"<div style='font-size:13px;padding:5px 0;color:rgba(219,216,211,0.7);line-height:1.5'>{item}</div>" for item in synthesis["compound_flags"])
|
| 555 |
+
html += card("β‘ Cross-document risks", rows, bg="rgba(245,158,11,0.05)", border="rgba(245,158,11,0.15)")
|
| 556 |
|
| 557 |
adversarial = result.get("adversarial_audit", {})
|
| 558 |
if adversarial.get("rejection_case") or adversarial.get("rebuttal_case"):
|
| 559 |
rows = ""
|
| 560 |
if adversarial.get("rejection_case"):
|
| 561 |
+
rows += f"<div style='font-size:13px;padding:6px 0;color:rgba(219,216,211,0.7);line-height:1.5'><b style='color:rgb(219,216,211);font-weight:600'>Officer rejection case:</b> {adversarial['rejection_case']}</div>"
|
| 562 |
if adversarial.get("rebuttal_case"):
|
| 563 |
+
rows += f"<div style='font-size:13px;padding:6px 0;color:rgba(219,216,211,0.7);line-height:1.5'><b style='color:rgb(219,216,211);font-weight:600'>Applicant rebuttal path:</b> {adversarial['rebuttal_case']}</div>"
|
| 564 |
+
html += card("βοΈ Adversarial audit", rows)
|
| 565 |
|
| 566 |
if result.get("next_steps"):
|
| 567 |
rows = "".join(
|
| 568 |
+
f"<div style='display:flex;gap:10px;padding:8px 0;border-bottom:1px solid rgba(255,255,255,0.04);align-items:flex-start'>{badge(step.get('priority','info').upper(), step.get('priority','info'))}<span style='color:rgba(219,216,211,0.7);font-size:13px;line-height:1.5'>{step.get('action','')}</span></div>"
|
| 569 |
for step in result["next_steps"]
|
| 570 |
)
|
| 571 |
+
html += card("π Next steps", rows)
|
| 572 |
|
| 573 |
cert = result.get("deletion_cert") or raw_result.get("full_result", {}).get("deletion_cert")
|
| 574 |
if cert:
|
| 575 |
+
html += f"<div class='uplan-dash-card' style='background:rgba(255,255,255,0.02);border:1px solid rgba(255,255,255,0.05);border-radius:14px;padding:16px;margin-bottom:6px'><div style='font-size:10px;color:rgba(219,216,211,0.35);text-transform:uppercase;letter-spacing:0.08em;font-weight:600'>π Deletion certificate</div><pre style='white-space:pre-wrap;font-size:11px;color:rgba(219,216,211,0.45);margin-top:8px;font-family:monospace;line-height:1.5'>{cert}</pre></div>"
|
| 576 |
|
| 577 |
html += "</div>"
|
| 578 |
return html
|
| 579 |
|
| 580 |
|
| 581 |
+
def card(title: str, body: str, bg: str = "rgba(255,255,255,0.03)", border: str = "rgba(255,255,255,0.07)") -> str:
|
| 582 |
+
return (
|
| 583 |
+
f"<div class='uplan-dash-card' style='background:{bg};border:1px solid {border};"
|
| 584 |
+
f"border-radius:14px;padding:20px;margin-bottom:14px;"
|
| 585 |
+
f"backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);"
|
| 586 |
+
f"font-family:\"Google Sans Flex\",\"Inter\",sans-serif'>"
|
| 587 |
+
f"<b style='color:rgb(219,216,211);font-size:15px;font-weight:600'>{title}</b>"
|
| 588 |
+
f"<div style='margin-top:12px'>{body}</div></div>"
|
| 589 |
+
)
|
| 590 |
|
| 591 |
|
| 592 |
def chat_response(message: str, history: list, result_state: dict) -> tuple[list, str]:
|
|
|
|
| 631 |
HEADER_HTML = """
|
| 632 |
<div id='uplan-header'>
|
| 633 |
<h1>β‘ Uplan</h1>
|
| 634 |
+
<p>Immigration document intelligence β reads financial packets, audits evidence quality, flags inconsistencies, and builds a readiness roadmap.<br>
|
| 635 |
+
<span style='font-size:11px;color:rgba(219,216,211,0.3);font-weight:400;letter-spacing:0.04em'>POWERED BY AMD MI300X Β· QWEN 3.6-27B VLM</span></p>
|
| 636 |
</div>
|
| 637 |
"""
|
| 638 |
|
| 639 |
|
| 640 |
CHECKLIST_HTML = """
|
| 641 |
+
<div class='tool-card' style='font-size:13px;line-height:2.0'>
|
| 642 |
+
<div style='display:flex;align-items:center;gap:8px;margin-bottom:6px'>
|
| 643 |
+
<span style='font-size:16px'>π</span>
|
| 644 |
+
<b style='font-weight:600;font-size:14px'>Packet checklist</b>
|
| 645 |
+
</div>
|
| 646 |
+
<div style='display:flex;align-items:center;gap:6px'><span style='display:inline-block;width:8px;height:8px;border-radius:50%;background:#f87171'></span> <span style='color:#f87171;font-weight:500'>Required:</span> affidavit, bank statement, tax return</div>
|
| 647 |
+
<div style='display:flex;align-items:center;gap:6px'><span style='display:inline-block;width:8px;height:8px;border-radius:50%;background:#fbbf24'></span> <span style='color:#fbbf24;font-weight:500'>Recommended:</span> bank balance certificate</div>
|
| 648 |
+
<div style='display:flex;align-items:center;gap:6px'><span style='display:inline-block;width:8px;height:8px;border-radius:50%;background:#60a5fa'></span> <span style='color:#60a5fa;font-weight:500'>Optional:</span> passport / identity document</div>
|
| 649 |
<hr>
|
| 650 |
+
<div style='display:flex;align-items:center;gap:8px;margin-bottom:6px'>
|
| 651 |
+
<span style='font-size:16px'>π€</span>
|
| 652 |
+
<b style='font-weight:600;font-size:14px'>Agent tools</b>
|
| 653 |
+
</div>
|
| 654 |
+
<div style='color:rgba(219,216,211,0.65);line-height:1.8'>
|
| 655 |
+
<span style='color:rgba(219,216,211,0.85);font-weight:500'>Auditor</span> Β· document readiness and quality checks<br>
|
| 656 |
+
<span style='color:rgba(219,216,211,0.85);font-weight:500'>Strategist</span> Β· roadmap and missing-evidence checklist<br>
|
| 657 |
+
<span style='color:rgba(219,216,211,0.85);font-weight:500'>Synthesis</span> Β· cross-document risk narrative
|
| 658 |
+
</div>
|
| 659 |
</div>
|
| 660 |
"""
|
| 661 |
|
|
|
|
| 668 |
gr.HTML(HEADER_HTML)
|
| 669 |
|
| 670 |
with gr.Row(equal_height=False):
|
| 671 |
+
with gr.Column(scale=1, min_width=280):
|
| 672 |
+
gr.Markdown("### βοΈ Agent tools")
|
| 673 |
demo_toggle = gr.Checkbox(label="Demo mode", value=True, info="Uses a clearly marked sample analysis. Turn off for live AMD backend.")
|
| 674 |
upload_box = gr.File(label="Upload PDF packet", file_types=[".pdf"], file_count="multiple", visible=False)
|
| 675 |
demo_toggle.change(lambda enabled: gr.update(visible=not enabled), demo_toggle, upload_box)
|
| 676 |
+
analyse_btn = gr.Button("β‘ Analyse packet", variant="primary")
|
| 677 |
gr.HTML(CHECKLIST_HTML)
|
| 678 |
+
gr.Markdown("<span style='font-size:12px;color:rgba(219,216,211,0.35)'>Raw documents are processed outside the UI in live mode. The extraction layer emits a deletion certificate after purge.</span>")
|
| 679 |
|
| 680 |
with gr.Column(scale=2, min_width=360):
|
| 681 |
+
gr.Markdown("### π¬ Consultant")
|
| 682 |
chatbot = gr.Chatbot(
|
| 683 |
label="Consultant",
|
| 684 |
+
height=580,
|
| 685 |
show_label=False,
|
| 686 |
+
value=[{"role": "assistant", "content": "Welcome to **Uplan**. Load the sample demo or upload a packet when the AMD backend is online. The dashboard will reflect whether the result is live or backend-offline.\n\n*Ask me about risks, missing evidence, or strategy.*"}],
|
| 687 |
)
|
| 688 |
with gr.Row():
|
| 689 |
chat_input = gr.Textbox(placeholder="Ask about risks, missing evidence, or next steps...", show_label=False, container=False, scale=5)
|
| 690 |
send_btn = gr.Button("Send", variant="secondary", scale=1)
|
| 691 |
|
| 692 |
+
with gr.Column(scale=2, min_width=400):
|
| 693 |
+
gr.Markdown("### π Readiness dashboard")
|
| 694 |
+
dashboard = gr.HTML("<div style='text-align:center;padding:48px 16px;color:rgba(219,216,211,0.35);font-family:\"Google Sans Flex\",\"Inter\",sans-serif'><div style='font-size:40px;margin-bottom:12px;opacity:0.4'>π</div><p style='font-size:15px;font-weight:450'>Load demo or upload documents to begin.</p></div>")
|
| 695 |
|
| 696 |
analyse_btn.click(handle_upload, [upload_box, demo_toggle], [dashboard, chatbot, result_state])
|
| 697 |
send_btn.click(chat_response, [chat_input, chatbot, result_state], [chatbot, chat_input])
|
|
|
|
| 705 |
server_name="0.0.0.0",
|
| 706 |
server_port=7860,
|
| 707 |
show_error=True,
|
| 708 |
+
theme=gr.themes.Soft(
|
| 709 |
+
primary_hue="blue",
|
| 710 |
+
secondary_hue="violet",
|
| 711 |
+
neutral_hue="slate",
|
| 712 |
+
font=["Google Sans Flex", "Google Sans", "Inter", "sans-serif"],
|
| 713 |
+
font_mono=["JetBrains Mono", "Fira Code", "monospace"],
|
| 714 |
+
),
|
| 715 |
css=CSS,
|
| 716 |
)
|