Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,7 +51,7 @@ LAST_RESULTS = []
|
|
| 51 |
SELECTED_INDEX = None
|
| 52 |
|
| 53 |
# ======================================================
|
| 54 |
-
# HELPERS
|
| 55 |
# ======================================================
|
| 56 |
|
| 57 |
def citation_hash(r):
|
|
@@ -230,27 +230,30 @@ def render_cards():
|
|
| 230 |
status.append("SEALED")
|
| 231 |
if r.get("redacted"):
|
| 232 |
status.append("REDACTED")
|
| 233 |
-
|
| 234 |
badge = " • ".join(status) if status else "PUBLIC"
|
| 235 |
|
| 236 |
thumbs = "".join(
|
| 237 |
-
f'<img src="data:image/png;base64,{t}"
|
|
|
|
| 238 |
for t in r["thumbnails"]
|
| 239 |
)
|
| 240 |
|
| 241 |
-
preview = thumbs or
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
cards.append(f"""
|
| 244 |
<div class="card">
|
| 245 |
<div class="card-header">
|
| 246 |
-
<
|
| 247 |
<span class="badge">{badge}</span>
|
| 248 |
</div>
|
| 249 |
<div class="card-title">{r['title']}</div>
|
| 250 |
-
{preview}
|
| 251 |
<div class="actions">
|
| 252 |
<button onclick="selectDoc({idx})">Select</button>
|
| 253 |
-
<a href="{r['resolved_url']}" target="_blank">View</a>
|
| 254 |
</div>
|
| 255 |
</div>
|
| 256 |
""")
|
|
@@ -267,7 +270,7 @@ def select_doc(idx):
|
|
| 267 |
return f"Selected document #{idx + 1}"
|
| 268 |
|
| 269 |
# ======================================================
|
| 270 |
-
# AI ASK
|
| 271 |
# ======================================================
|
| 272 |
|
| 273 |
def ask_ai(opt_in, pdf_opt_in, question):
|
|
@@ -326,16 +329,7 @@ def generate_exhibit_packet(circuit):
|
|
| 326 |
story.append(PageBreak())
|
| 327 |
|
| 328 |
for i, r in enumerate(LAST_RESULTS, start=1):
|
| 329 |
-
|
| 330 |
-
if r.get("sealed"):
|
| 331 |
-
marker.append("SEALED")
|
| 332 |
-
if r.get("redacted"):
|
| 333 |
-
marker.append("REDACTED")
|
| 334 |
-
|
| 335 |
-
story.append(Paragraph(
|
| 336 |
-
f"EXHIBIT {i} {'(' + ', '.join(marker) + ')' if marker else ''}",
|
| 337 |
-
styles["Heading1"]
|
| 338 |
-
))
|
| 339 |
story.append(Paragraph(r["resolved_url"], styles["Normal"]))
|
| 340 |
story.append(Paragraph(f"SHA-256 Hash: {r['hash']}", styles["Code"]))
|
| 341 |
story.append(PageBreak())
|
|
@@ -352,8 +346,8 @@ def generate_rule26_attestation():
|
|
| 352 |
lines = [
|
| 353 |
"RULE 26(e) DISCOVERY HASH ATTESTATION",
|
| 354 |
"",
|
| 355 |
-
"
|
| 356 |
-
"Hashes
|
| 357 |
""
|
| 358 |
]
|
| 359 |
|
|
@@ -369,40 +363,76 @@ def generate_rule26_attestation():
|
|
| 369 |
# ======================================================
|
| 370 |
|
| 371 |
CSS = """
|
| 372 |
-
.card {
|
| 373 |
-
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
"""
|
| 376 |
|
| 377 |
with gr.Blocks(css=CSS, title="Federal FOIA Intelligence Search") as app:
|
| 378 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
with gr.Tab("Search"):
|
| 381 |
agencies = gr.CheckboxGroup(
|
| 382 |
choices=list(ALL_ADAPTERS.keys()),
|
| 383 |
-
value=list(ALL_ADAPTERS.keys())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
)
|
| 385 |
-
query = gr.Textbox(placeholder="Search FOIA reading rooms")
|
| 386 |
-
table = gr.Dataframe(headers=["Agency","Title","Resolved URL","Hash","Latency"])
|
| 387 |
gallery = gr.HTML()
|
| 388 |
-
status = gr.Textbox()
|
| 389 |
-
gr.Button("Search").click(
|
|
|
|
|
|
|
| 390 |
|
| 391 |
with gr.Tab("Ask AI"):
|
|
|
|
|
|
|
|
|
|
| 392 |
ai_opt = gr.Checkbox(label="Enable AI (Explicit Opt-In)")
|
| 393 |
pdf_opt = gr.Checkbox(label="Allow PDF Text Extraction")
|
| 394 |
-
q = gr.Textbox(lines=4)
|
| 395 |
-
a = gr.Textbox(lines=18)
|
| 396 |
gr.Button("Ask AI").click(ask_ai, [ai_opt, pdf_opt, q], a)
|
| 397 |
|
| 398 |
with gr.Tab("Court / Clerk"):
|
| 399 |
circuit = gr.Radio(
|
| 400 |
["FIRST CIRCUIT", "SECOND CIRCUIT", "D.C. CIRCUIT", "NINTH CIRCUIT"],
|
| 401 |
-
value="D.C. CIRCUIT"
|
| 402 |
-
|
| 403 |
-
gr.File(label="Clerk-Compliant Exhibit Packet (PDF)").upload(
|
| 404 |
-
lambda c=circuit: generate_exhibit_packet(c)
|
| 405 |
)
|
|
|
|
|
|
|
|
|
|
| 406 |
|
| 407 |
attest = gr.Textbox(lines=12, label="Rule 26 Hash Attestation")
|
| 408 |
gr.Button("Generate Rule 26 Attestation").click(
|
|
@@ -424,4 +454,30 @@ with gr.Blocks(css=CSS, title="Federal FOIA Intelligence Search") as app:
|
|
| 424 |
render_timeline, req_date, timeline_out
|
| 425 |
)
|
| 426 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
app.launch()
|
|
|
|
| 51 |
SELECTED_INDEX = None
|
| 52 |
|
| 53 |
# ======================================================
|
| 54 |
+
# HELPERS
|
| 55 |
# ======================================================
|
| 56 |
|
| 57 |
def citation_hash(r):
|
|
|
|
| 230 |
status.append("SEALED")
|
| 231 |
if r.get("redacted"):
|
| 232 |
status.append("REDACTED")
|
|
|
|
| 233 |
badge = " • ".join(status) if status else "PUBLIC"
|
| 234 |
|
| 235 |
thumbs = "".join(
|
| 236 |
+
f'<img src="data:image/png;base64,{t}" '
|
| 237 |
+
f'style="width:30%;margin:4px;border-radius:6px;border:1px solid #ccc" />'
|
| 238 |
for t in r["thumbnails"]
|
| 239 |
)
|
| 240 |
|
| 241 |
+
preview = thumbs or (
|
| 242 |
+
f'<a href="{r["resolved_url"]}" target="_blank">'
|
| 243 |
+
f'Open FOIA Reading Room</a>'
|
| 244 |
+
)
|
| 245 |
|
| 246 |
cards.append(f"""
|
| 247 |
<div class="card">
|
| 248 |
<div class="card-header">
|
| 249 |
+
<span class="agency">{r['agency']}</span>
|
| 250 |
<span class="badge">{badge}</span>
|
| 251 |
</div>
|
| 252 |
<div class="card-title">{r['title']}</div>
|
| 253 |
+
<div class="preview">{preview}</div>
|
| 254 |
<div class="actions">
|
| 255 |
<button onclick="selectDoc({idx})">Select</button>
|
| 256 |
+
<a href="{r['resolved_url']}" target="_blank">View Source</a>
|
| 257 |
</div>
|
| 258 |
</div>
|
| 259 |
""")
|
|
|
|
| 270 |
return f"Selected document #{idx + 1}"
|
| 271 |
|
| 272 |
# ======================================================
|
| 273 |
+
# AI ASK
|
| 274 |
# ======================================================
|
| 275 |
|
| 276 |
def ask_ai(opt_in, pdf_opt_in, question):
|
|
|
|
| 329 |
story.append(PageBreak())
|
| 330 |
|
| 331 |
for i, r in enumerate(LAST_RESULTS, start=1):
|
| 332 |
+
story.append(Paragraph(f"EXHIBIT {i}", styles["Heading1"]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
story.append(Paragraph(r["resolved_url"], styles["Normal"]))
|
| 334 |
story.append(Paragraph(f"SHA-256 Hash: {r['hash']}", styles["Code"]))
|
| 335 |
story.append(PageBreak())
|
|
|
|
| 346 |
lines = [
|
| 347 |
"RULE 26(e) DISCOVERY HASH ATTESTATION",
|
| 348 |
"",
|
| 349 |
+
"Materials retrieved from public FOIA reading rooms.",
|
| 350 |
+
"Hashes provided for integrity verification only.",
|
| 351 |
""
|
| 352 |
]
|
| 353 |
|
|
|
|
| 363 |
# ======================================================
|
| 364 |
|
| 365 |
CSS = """
|
| 366 |
+
.card {
|
| 367 |
+
border:1px solid #ddd;
|
| 368 |
+
border-radius:16px;
|
| 369 |
+
padding:16px;
|
| 370 |
+
margin-bottom:20px;
|
| 371 |
+
background:#fafafa;
|
| 372 |
+
}
|
| 373 |
+
.card-header {
|
| 374 |
+
display:flex;
|
| 375 |
+
justify-content:space-between;
|
| 376 |
+
margin-bottom:6px;
|
| 377 |
+
}
|
| 378 |
+
.card-title {
|
| 379 |
+
font-weight:600;
|
| 380 |
+
margin-bottom:8px;
|
| 381 |
+
}
|
| 382 |
+
.actions {
|
| 383 |
+
margin-top:10px;
|
| 384 |
+
display:flex;
|
| 385 |
+
gap:12px;
|
| 386 |
+
}
|
| 387 |
+
.badge {
|
| 388 |
+
background:#eef;
|
| 389 |
+
padding:4px 10px;
|
| 390 |
+
border-radius:999px;
|
| 391 |
+
font-size:0.8em;
|
| 392 |
+
}
|
| 393 |
"""
|
| 394 |
|
| 395 |
with gr.Blocks(css=CSS, title="Federal FOIA Intelligence Search") as app:
|
| 396 |
+
gr.Markdown(
|
| 397 |
+
"## Federal FOIA Intelligence Search\n"
|
| 398 |
+
"Public FOIA reading rooms only • Educational and research use"
|
| 399 |
+
)
|
| 400 |
|
| 401 |
with gr.Tab("Search"):
|
| 402 |
agencies = gr.CheckboxGroup(
|
| 403 |
choices=list(ALL_ADAPTERS.keys()),
|
| 404 |
+
value=list(ALL_ADAPTERS.keys()),
|
| 405 |
+
label="Agencies"
|
| 406 |
+
)
|
| 407 |
+
query = gr.Textbox(placeholder="e.g. surveillance, AATIP, procurement")
|
| 408 |
+
table = gr.Dataframe(
|
| 409 |
+
headers=["Agency","Title","Resolved URL","Hash","Latency"]
|
| 410 |
)
|
|
|
|
|
|
|
| 411 |
gallery = gr.HTML()
|
| 412 |
+
status = gr.Textbox(label="Selection Status")
|
| 413 |
+
gr.Button("Search").click(
|
| 414 |
+
run_search, [query, agencies], [table, gallery, status]
|
| 415 |
+
)
|
| 416 |
|
| 417 |
with gr.Tab("Ask AI"):
|
| 418 |
+
gr.Markdown(
|
| 419 |
+
"**AI analysis is optional, user-initiated, and limited to public PDFs.**"
|
| 420 |
+
)
|
| 421 |
ai_opt = gr.Checkbox(label="Enable AI (Explicit Opt-In)")
|
| 422 |
pdf_opt = gr.Checkbox(label="Allow PDF Text Extraction")
|
| 423 |
+
q = gr.Textbox(lines=4, label="Question")
|
| 424 |
+
a = gr.Textbox(lines=18, label="AI Output")
|
| 425 |
gr.Button("Ask AI").click(ask_ai, [ai_opt, pdf_opt, q], a)
|
| 426 |
|
| 427 |
with gr.Tab("Court / Clerk"):
|
| 428 |
circuit = gr.Radio(
|
| 429 |
["FIRST CIRCUIT", "SECOND CIRCUIT", "D.C. CIRCUIT", "NINTH CIRCUIT"],
|
| 430 |
+
value="D.C. CIRCUIT",
|
| 431 |
+
label="Circuit"
|
|
|
|
|
|
|
| 432 |
)
|
| 433 |
+
gr.File(
|
| 434 |
+
label="Clerk-Compliant Exhibit Packet (PDF)"
|
| 435 |
+
).upload(lambda c=circuit: generate_exhibit_packet(c))
|
| 436 |
|
| 437 |
attest = gr.Textbox(lines=12, label="Rule 26 Hash Attestation")
|
| 438 |
gr.Button("Generate Rule 26 Attestation").click(
|
|
|
|
| 454 |
render_timeline, req_date, timeline_out
|
| 455 |
)
|
| 456 |
|
| 457 |
+
# ==================================================
|
| 458 |
+
# GOVERNANCE TAB (NEW)
|
| 459 |
+
# ==================================================
|
| 460 |
+
|
| 461 |
+
with gr.Tab("Governance & Trust"):
|
| 462 |
+
gr.Markdown(
|
| 463 |
+
"### Governance, Ethics, and Safety Documentation\n"
|
| 464 |
+
"This documentation explains scope, limitations, governance controls, "
|
| 465 |
+
"and compliance posture for reviewers, journalists, courts, and institutions."
|
| 466 |
+
)
|
| 467 |
+
|
| 468 |
+
gr.HTML(
|
| 469 |
+
"""
|
| 470 |
+
<iframe
|
| 471 |
+
src="/governance-site/index.html"
|
| 472 |
+
style="width:100%; height:700px; border:1px solid #ccc; border-radius:12px;"
|
| 473 |
+
></iframe>
|
| 474 |
+
<p style="margin-top:10px;">
|
| 475 |
+
If the page does not load,
|
| 476 |
+
<a href="/governance-site/index.html" target="_blank">
|
| 477 |
+
open the governance site in a new tab
|
| 478 |
+
</a>.
|
| 479 |
+
</p>
|
| 480 |
+
"""
|
| 481 |
+
)
|
| 482 |
+
|
| 483 |
app.launch()
|