Spaces:
Sleeping
Sleeping
File size: 2,761 Bytes
6ffe9e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import gradio as gr
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
import hashlib, io, time, requests, base64
from datetime import datetime, timedelta
from reportlab.platypus import SimpleDocTemplate, Paragraph, PageBreak
from reportlab.lib.styles import getSampleStyleSheet
from governance_site import load_governance_doc
# ======================================================
# HARD GOVERNANCE FLAGS
# ======================================================
ENABLE_FAISS_PHASE_4 = False # CRYPTOGRAPHICALLY LOCKED
ENABLE_AI = True
# ======================================================
# FASTAPI APP (PROVENANCE HEADERS)
# ======================================================
api = FastAPI()
@api.middleware("http")
async def provenance_headers(request: Request, call_next):
response = await call_next(request)
response.headers["X-FOIA-Tool"] = "Federal FOIA Intelligence Search"
response.headers["X-Provenance-UTC"] = datetime.utcnow().isoformat()
response.headers["X-AI-Usage"] = "User-Initiated Only"
response.headers["X-FAISS-Status"] = "DISABLED"
return response
# ======================================================
# GRADIO UI
# ======================================================
def sha256(text):
return hashlib.sha256(text.encode()).hexdigest()
LAST_RESULTS = []
SELECTED = None
def search(query):
global LAST_RESULTS
LAST_RESULTS = [{
"agency": "CIA",
"title": "CIA FOIA Reading Room",
"url": f"https://www.cia.gov/readingroom/search/site/{query}",
"hash": sha256(query)
}]
return LAST_RESULTS
def preview():
if not LAST_RESULTS:
return "No document selected."
return f"<iframe src='{LAST_RESULTS[0]['url']}' style='width:100%;height:700px'></iframe>"
def toa():
return "\n".join(f"Exhibit {i+1}: {r['agency']}" for i, r in enumerate(LAST_RESULTS))
with gr.Blocks(title="Federal FOIA Intelligence Search") as ui:
gr.Markdown("## Federal FOIA Intelligence Search")
with gr.Tab("Search"):
q = gr.Textbox()
out = gr.JSON()
gr.Button("Search").click(search, q, out)
with gr.Tab("Preview"):
gr.HTML().render(preview)
with gr.Tab("Exhibits"):
gr.Textbox(lines=10).render(toa)
with gr.Tab("Governance"):
gr.HTML(load_governance_doc("index.html"))
with gr.Tab("Trust & Safety"):
gr.HTML(load_governance_doc("trust_safety.html"))
with gr.Tab("Judicial / DOJ"):
gr.HTML(load_governance_doc("judicial_doj_memo.html"))
# ======================================================
# MOUNT GRADIO INTO FASTAPI
# ======================================================
app = gr.mount_gradio_app(api, ui, path="/") |