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"" 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="/")