Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import asyncio | |
| from ingest.registry import get_all_adapters | |
| from ingest.cluster import semantic_clusters | |
| from ingest.export import export_results_zip | |
| from ingest.health import check_health | |
| ADAPTERS = get_all_adapters() | |
| async def federated_search(query: str): | |
| results = [] | |
| for adapter in ADAPTERS.values(): | |
| try: | |
| res = await adapter.search(query) | |
| results.extend(res) | |
| except Exception: | |
| continue | |
| return results | |
| def run_search(query): | |
| if not query.strip(): | |
| return [], [] | |
| results = asyncio.run(federated_search(query)) | |
| rows = [ | |
| [r["source"], r["title"], r["url"], r["snippet"]] | |
| for r in results | |
| ] | |
| texts = [r["snippet"] for r in results] | |
| clusters = semantic_clusters(texts) if texts else [] | |
| return rows, clusters | |
| def export_zip_handler(table): | |
| results = [] | |
| for row in table: | |
| results.append({ | |
| "source": row[0], | |
| "title": row[1], | |
| "url": row[2], | |
| "snippet": row[3], | |
| }) | |
| return export_results_zip(results) | |
| with gr.Blocks() as app: | |
| gr.Markdown( | |
| "# **Federal FOIA Intelligence Search**\n" | |
| "### Public Electronic Reading Rooms Only\n\n" | |
| "Live, robots-compliant search across U.S. government FOIA libraries." | |
| ) | |
| query = gr.Textbox(label="Search term", placeholder="e.g. UAP, procurement, surveillance") | |
| search_btn = gr.Button("Search") | |
| results_table = gr.Dataframe( | |
| headers=["Agency", "Title", "URL", "Snippet"], | |
| interactive=False, | |
| wrap=True | |
| ) | |
| cluster_output = gr.State() | |
| search_btn.click( | |
| fn=run_search, | |
| inputs=query, | |
| outputs=[results_table, cluster_output] | |
| ) | |
| gr.Markdown("### Export") | |
| export_btn = gr.Button("Export Results (ZIP)") | |
| zip_file = gr.File(label="Download ZIP") | |
| export_btn.click( | |
| fn=export_zip_handler, | |
| inputs=results_table, | |
| outputs=zip_file | |
| ) | |
| gr.Markdown("### Source Health") | |
| for adapter in ADAPTERS.values(): | |
| health = check_health(adapter) | |
| gr.Markdown( | |
| f"- **{health['source']}**: {health['status']} " | |
| f"({health['latency_ms']} ms)" | |
| ) | |
| app.launch() |