Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,46 @@
|
|
| 1 |
-
|
| 2 |
-
# Public Electronic Reading Rooms Only
|
| 3 |
-
|
| 4 |
-
import gradio as gr
|
| 5 |
-
import asyncio
|
| 6 |
from ingest.registry import get_all_adapters
|
| 7 |
-
from ingest.cluster import
|
| 8 |
-
from ingest.
|
| 9 |
-
from ingest.
|
| 10 |
-
from ingest.health import adapter_health
|
| 11 |
|
| 12 |
adapters = get_all_adapters()
|
| 13 |
|
| 14 |
-
async def run_search(query
|
| 15 |
results = []
|
| 16 |
-
for
|
| 17 |
-
if live_only and not adapter.is_live:
|
| 18 |
-
continue
|
| 19 |
try:
|
| 20 |
-
|
| 21 |
-
results.extend(r)
|
| 22 |
except Exception:
|
| 23 |
-
|
| 24 |
return results
|
| 25 |
|
| 26 |
-
def search_ui(query
|
| 27 |
-
results = asyncio.run(run_search(query
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("## Federal FOIA Intelligence Search")
|
| 33 |
gr.Markdown("*Public Electronic Reading Rooms Only*")
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
results_table = gr.Dataframe(label="Results")
|
| 41 |
cluster_plot = gr.Plot(label="Semantic Clusters")
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
with gr.Tab("🧾 FOIA Request Generator"):
|
| 47 |
-
agency = gr.Textbox(label="Agency")
|
| 48 |
-
subject = gr.Textbox(label="Subject")
|
| 49 |
-
packet_btn = gr.Button("Generate FOIA Packet")
|
| 50 |
-
packet_out = gr.File()
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
inputs=[query, live_toggle],
|
| 55 |
-
outputs=[results_table, cluster_plot]
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
packet_btn.click(
|
| 59 |
-
generate_foia_packet,
|
| 60 |
-
inputs=[agency, subject],
|
| 61 |
-
outputs=packet_out
|
| 62 |
-
)
|
| 63 |
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr, asyncio, plotly.express as px
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from ingest.registry import get_all_adapters
|
| 3 |
+
from ingest.cluster import semantic_cluster_plot
|
| 4 |
+
from ingest.coverage import agency_coverage
|
| 5 |
+
from ingest.citations import bluebook_pdf
|
|
|
|
| 6 |
|
| 7 |
adapters = get_all_adapters()
|
| 8 |
|
| 9 |
+
async def run_search(query):
|
| 10 |
results = []
|
| 11 |
+
for a in adapters:
|
|
|
|
|
|
|
| 12 |
try:
|
| 13 |
+
results.extend(await a.search(query))
|
|
|
|
| 14 |
except Exception:
|
| 15 |
+
pass
|
| 16 |
return results
|
| 17 |
|
| 18 |
+
def search_ui(query):
|
| 19 |
+
results = asyncio.run(run_search(query))
|
| 20 |
+
coverage = agency_coverage(results)
|
| 21 |
+
heatmap = px.imshow(
|
| 22 |
+
[list(coverage.values())],
|
| 23 |
+
labels=dict(x="Agency", color="Docs"),
|
| 24 |
+
x=list(coverage.keys())
|
| 25 |
+
)
|
| 26 |
+
cluster_fig = semantic_cluster_plot(results)
|
| 27 |
+
return results, heatmap, cluster_fig
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
gr.Markdown("## Federal FOIA Intelligence Search")
|
| 31 |
gr.Markdown("*Public Electronic Reading Rooms Only*")
|
| 32 |
|
| 33 |
+
q = gr.Textbox(label="Search term")
|
| 34 |
+
btn = gr.Button("Search")
|
| 35 |
|
| 36 |
+
results_df = gr.Dataframe(label="Results")
|
| 37 |
+
heatmap_plot = gr.Plot(label="Agency Coverage")
|
|
|
|
| 38 |
cluster_plot = gr.Plot(label="Semantic Clusters")
|
| 39 |
|
| 40 |
+
pdf_btn = gr.Button("Export Bluebook PDF")
|
| 41 |
+
pdf_out = gr.File()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
btn.click(search_ui, q, [results_df, heatmap_plot, cluster_plot])
|
| 44 |
+
pdf_btn.click(bluebook_pdf, results_df, pdf_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
demo.launch()
|