GodsDevProject commited on
Commit
c7b002a
Β·
verified Β·
1 Parent(s): 777b8a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -41
app.py CHANGED
@@ -10,12 +10,21 @@ from datetime import datetime
10
 
11
  from ingest.registry import get_enabled_adapters
12
  from ingest.cluster import build_embeddings, cluster_embeddings
 
13
  from ingest.health import get_health_snapshot
14
- from ingest.coverage import build_coverage_heatmap
15
- from ingest.export import export_journalist_zip, export_pdf_report
16
- from ingest.utils import highlight_terms, classify_foia_exemptions, format_citation
 
 
 
 
 
 
 
17
  from ingest.timeline import build_timeline_figure
18
  from ingest.graph import build_cluster_graph
 
19
 
20
 
21
  TITLE = "πŸ›οΈ Federal FOIA Intelligence Search"
@@ -24,7 +33,7 @@ SUBTITLE = "Public Electronic Reading Rooms Only"
24
 
25
  # ---------------- Async-safe search ----------------
26
 
27
- async def _run_search(query: str, enable_live: bool, hide_stub: bool):
28
  adapters = get_enabled_adapters(enable_live=enable_live)
29
  tasks = [a.search(query) for a in adapters]
30
  responses = await asyncio.gather(*tasks, return_exceptions=True)
@@ -44,18 +53,22 @@ async def _run_search(query: str, enable_live: bool, hide_stub: bool):
44
  r["source"] = adapter.source_name
45
  r["latency"] = adapter.last_latency
46
  r["exemptions"] = classify_foia_exemptions(r.get("snippet", ""))
47
- r["citation"] = format_citation(r)
48
  r["date"] = r.get("date", datetime.utcnow().isoformat())
49
  results.append(r)
50
 
51
  embeddings = build_embeddings(results)
52
  clusters = cluster_embeddings(results, embeddings)
53
 
54
- coverage = build_coverage_heatmap(per_agency_counts)
55
- cluster_graph = build_cluster_graph(results, clusters)
56
- timeline_fig = build_timeline_figure(results)
57
-
58
- return results, clusters, per_agency_counts, coverage, cluster_graph, timeline_fig
 
 
 
 
59
 
60
 
61
  def search_ui(query, enable_live, hide_stub):
@@ -65,10 +78,11 @@ def search_ui(query, enable_live, hide_stub):
65
  (
66
  results,
67
  clusters,
68
- counts,
69
- coverage,
 
 
70
  cluster_graph,
71
- timeline_fig
72
  ) = loop.run_until_complete(
73
  _run_search(query, enable_live, hide_stub)
74
  )
@@ -81,10 +95,10 @@ def search_ui(query, enable_live, hide_stub):
81
  r["url"],
82
  r.get("snippet", ""),
83
  ",".join(r["exemptions"]),
84
- f"{r.get('latency', 0):.2f}s"
85
  ])
86
 
87
- return table, counts, coverage, cluster_graph, timeline_fig
88
 
89
 
90
  # ---------------- UI ----------------
@@ -92,10 +106,8 @@ def search_ui(query, enable_live, hide_stub):
92
  with gr.Blocks(title="Federal FOIA Intelligence Search") as demo:
93
  gr.Markdown(f"# {TITLE}")
94
  gr.Markdown(f"### {SUBTITLE}")
95
-
96
  gr.Markdown(
97
- "**Terms of Use:** Indexes only documents already released "
98
- "via official FOIA Electronic Reading Rooms."
99
  )
100
 
101
  with gr.Row():
@@ -107,26 +119,35 @@ with gr.Blocks(title="Federal FOIA Intelligence Search") as demo:
107
  hide_stub = gr.Checkbox(label="Hide Stub Sources", value=True)
108
 
109
  results_table = gr.Dataframe(
110
- headers=["Agency", "Title", "URL", "Snippet", "FOIA Exemptions", "Latency"],
111
- wrap=True
112
  )
113
 
114
- with gr.Tabs():
115
- with gr.Tab("πŸ“Š Coverage Heatmap"):
116
- coverage_box = gr.JSON()
117
 
118
- with gr.Tab("🧠 Semantic Cluster Graph"):
 
119
  cluster_plot = gr.Plot()
120
 
121
- with gr.Tab("πŸ—“οΈ Timeline View"):
 
 
 
 
 
 
122
  timeline_plot = gr.Plot()
123
 
124
- with gr.Tab("πŸ₯ Agency Health"):
 
 
 
125
  health_box = gr.JSON(value=get_health_snapshot())
126
 
127
  with gr.Row():
128
- export_zip_btn = gr.Button("🧾 Journalist ZIP Export")
129
- export_pdf_btn = gr.Button("πŸ“„ PDF Transparency Report")
 
130
 
131
  export_status = gr.Textbox(label="Export Status")
132
 
@@ -135,23 +156,21 @@ with gr.Blocks(title="Federal FOIA Intelligence Search") as demo:
135
  inputs=[query, enable_live, hide_stub],
136
  outputs=[
137
  results_table,
138
- coverage_box,
139
- coverage_box,
 
 
140
  cluster_plot,
141
- timeline_plot
142
- ]
143
  )
144
 
145
- export_zip_btn.click(
146
- fn=export_journalist_zip,
147
- inputs=[results_table],
148
- outputs=[export_status]
149
  )
150
 
151
- export_pdf_btn.click(
152
- fn=export_pdf_report,
153
- inputs=[results_table],
154
- outputs=[export_status]
155
- )
156
 
157
  demo.queue().launch()
 
10
 
11
  from ingest.registry import get_enabled_adapters
12
  from ingest.cluster import build_embeddings, cluster_embeddings
13
+ from ingest.coverage import build_coverage_heatmap, build_agency_map
14
  from ingest.health import get_health_snapshot
15
+ from ingest.export import (
16
+ export_journalist_zip,
17
+ export_pdf_report,
18
+ export_congressional_briefing,
19
+ )
20
+ from ingest.utils import (
21
+ highlight_terms,
22
+ classify_foia_exemptions,
23
+ format_bluebook_citation,
24
+ )
25
  from ingest.timeline import build_timeline_figure
26
  from ingest.graph import build_cluster_graph
27
+ from ingest.trends import build_exemption_trend_chart
28
 
29
 
30
  TITLE = "πŸ›οΈ Federal FOIA Intelligence Search"
 
33
 
34
  # ---------------- Async-safe search ----------------
35
 
36
+ async def _run_search(query, enable_live, hide_stub):
37
  adapters = get_enabled_adapters(enable_live=enable_live)
38
  tasks = [a.search(query) for a in adapters]
39
  responses = await asyncio.gather(*tasks, return_exceptions=True)
 
53
  r["source"] = adapter.source_name
54
  r["latency"] = adapter.last_latency
55
  r["exemptions"] = classify_foia_exemptions(r.get("snippet", ""))
56
+ r["citation"] = format_bluebook_citation(r)
57
  r["date"] = r.get("date", datetime.utcnow().isoformat())
58
  results.append(r)
59
 
60
  embeddings = build_embeddings(results)
61
  clusters = cluster_embeddings(results, embeddings)
62
 
63
+ return (
64
+ results,
65
+ clusters,
66
+ build_coverage_heatmap(per_agency_counts),
67
+ build_agency_map(per_agency_counts),
68
+ build_timeline_figure(results),
69
+ build_exemption_trend_chart(results),
70
+ build_cluster_graph(results, clusters),
71
+ )
72
 
73
 
74
  def search_ui(query, enable_live, hide_stub):
 
78
  (
79
  results,
80
  clusters,
81
+ heatmap,
82
+ agency_map,
83
+ timeline,
84
+ exemption_trends,
85
  cluster_graph,
 
86
  ) = loop.run_until_complete(
87
  _run_search(query, enable_live, hide_stub)
88
  )
 
95
  r["url"],
96
  r.get("snippet", ""),
97
  ",".join(r["exemptions"]),
98
+ r["citation"],
99
  ])
100
 
101
+ return table, heatmap, agency_map, timeline, exemption_trends, cluster_graph
102
 
103
 
104
  # ---------------- UI ----------------
 
106
  with gr.Blocks(title="Federal FOIA Intelligence Search") as demo:
107
  gr.Markdown(f"# {TITLE}")
108
  gr.Markdown(f"### {SUBTITLE}")
 
109
  gr.Markdown(
110
+ "**Terms of Use:** Indexes only documents already released via official FOIA Electronic Reading Rooms."
 
111
  )
112
 
113
  with gr.Row():
 
119
  hide_stub = gr.Checkbox(label="Hide Stub Sources", value=True)
120
 
121
  results_table = gr.Dataframe(
122
+ headers=["Agency", "Title", "URL", "Snippet", "FOIA Exemptions", "Citation"],
123
+ wrap=True,
124
  )
125
 
126
+ preview_box = gr.Markdown(label="πŸ“„ Document Preview")
 
 
127
 
128
+ with gr.Tabs():
129
+ with gr.Tab("🧠 Cluster Graph"):
130
  cluster_plot = gr.Plot()
131
 
132
+ with gr.Tab("πŸ—ΊοΈ Agency Coverage Map"):
133
+ agency_map_plot = gr.Plot()
134
+
135
+ with gr.Tab("πŸ“Š Coverage Heatmap"):
136
+ heatmap_box = gr.JSON()
137
+
138
+ with gr.Tab("πŸ—“οΈ Timeline"):
139
  timeline_plot = gr.Plot()
140
 
141
+ with gr.Tab("βš–οΈ FOIA Exemption Trends"):
142
+ exemption_plot = gr.Plot()
143
+
144
+ with gr.Tab("πŸ₯ Health"):
145
  health_box = gr.JSON(value=get_health_snapshot())
146
 
147
  with gr.Row():
148
+ export_zip_btn = gr.Button("🧾 Journalist ZIP")
149
+ export_pdf_btn = gr.Button("πŸ“„ Transparency PDF")
150
+ export_congress_btn = gr.Button("πŸ›οΈ Congressional Briefing PDF")
151
 
152
  export_status = gr.Textbox(label="Export Status")
153
 
 
156
  inputs=[query, enable_live, hide_stub],
157
  outputs=[
158
  results_table,
159
+ heatmap_box,
160
+ agency_map_plot,
161
+ timeline_plot,
162
+ exemption_plot,
163
  cluster_plot,
164
+ ],
 
165
  )
166
 
167
+ results_table.select(
168
+ lambda df, evt: f"### {df[evt.index][1]}\n\n{df[evt.index][3]}\n\nπŸ”— {df[evt.index][2]}",
169
+ outputs=preview_box,
 
170
  )
171
 
172
+ export_zip_btn.click(export_journalist_zip, results_table, export_status)
173
+ export_pdf_btn.click(export_pdf_report, results_table, export_status)
174
+ export_congress_btn.click(export_congressional_briefing, results_table, export_status)
 
 
175
 
176
  demo.queue().launch()