GodsDevProject commited on
Commit
d4bfa02
·
verified ·
1 Parent(s): d013225

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -105
app.py CHANGED
@@ -1,121 +1,41 @@
 
1
  import gradio as gr
2
- import pandas as pd
3
 
4
- # Optional Plotly
5
- try:
6
- import plotly.express as px
7
- import plotly.graph_objects as go
8
- PLOTLY = True
9
- except Exception:
10
- PLOTLY = False
11
 
12
- # ---------------------------
13
- # Demo FOIA Data
14
- # ---------------------------
15
- DATA = pd.DataFrame([
16
- {
17
- "title": "MKULTRA Behavioral Experiments",
18
- "agency": "CIA",
19
- "date": "1977-08-03",
20
- "year": 1977,
21
- "summary": "CIA behavioral research involving human subjects.",
22
- "entities": ["CIA", "MKULTRA"]
23
- },
24
- {
25
- "title": "Human Performance Research",
26
- "agency": "DoD",
27
- "date": "1975-01-12",
28
- "year": 1975,
29
- "summary": "DoD-funded cognition research.",
30
- "entities": ["DoD", "Cognition"]
31
- }
32
- ])
33
 
34
- AGENCIES = sorted(DATA["agency"].unique().tolist())
 
 
 
35
 
36
- # ---------------------------
37
- # Search
38
- # ---------------------------
39
- def run_search(query, agencies):
40
- df = DATA.copy()
41
- if query:
42
- df = df[df["title"].str.contains(query, case=False)]
43
- if agencies:
44
- df = df[df["agency"].isin(agencies)]
45
- return df[["title", "agency", "date"]]
46
 
47
- def preview_row(evt: gr.SelectData):
48
- row = DATA.iloc[evt.index]
49
- return f"""
50
- ### {row['title']}
51
- **Agency:** {row['agency']}
52
- **Date:** {row['date']}
53
 
54
- {row['summary']}
55
- """
56
-
57
- # ---------------------------
58
- # Visuals
59
- # ---------------------------
60
- def coverage_heatmap():
61
- if not PLOTLY:
62
- return None
63
-
64
- heat = DATA.groupby(["agency", "year"]).size().reset_index(name="count")
65
- fig = px.density_heatmap(
66
- heat,
67
- x="year",
68
- y="agency",
69
- z="count",
70
- color_continuous_scale="Blues"
71
- )
72
- fig.update_layout(height=300)
73
- return fig
74
-
75
- def entity_graph():
76
- if not PLOTLY:
77
- return None
78
-
79
- nodes = list(set(sum(DATA["entities"].tolist(), [])))
80
- fig = go.Figure(
81
- data=go.Scatter(
82
- x=list(range(len(nodes))),
83
- y=[0]*len(nodes),
84
- mode="markers+text",
85
- text=nodes
86
- )
87
- )
88
- fig.update_layout(height=300)
89
- return fig
90
-
91
- # ---------------------------
92
- # UI
93
- # ---------------------------
94
  with gr.Blocks() as demo:
95
-
96
  gr.Markdown("""
97
  # 🏛️ Federal FOIA Intelligence Search
98
- **Public Electronic Reading Rooms Only**
 
99
  """)
100
 
101
- if not PLOTLY:
102
- gr.Markdown("⚠️ Plotly not installed — graphs disabled.")
103
-
104
- with gr.Tab("🔍 Search"):
105
- query = gr.Textbox(label="Search query", value="MKULTRA")
106
- agencies = gr.CheckboxGroup(AGENCIES, value=AGENCIES)
107
- search_btn = gr.Button("Search")
108
 
109
- table = gr.Dataframe(headers=["Title", "Agency", "Date"])
110
- preview = gr.Markdown()
111
-
112
- search_btn.click(run_search, [query, agencies], table)
113
- table.select(preview_row, preview)
114
-
115
- with gr.Tab("📊 Coverage Heatmap"):
116
- gr.Plot(value=coverage_heatmap)
117
 
118
- with gr.Tab("🧠 Entity Graph"):
119
- gr.Plot(value=entity_graph)
120
 
121
  demo.launch()
 
1
+ import asyncio
2
  import gradio as gr
3
+ from ingest.registry import get_live_adapters
4
 
5
+ ADAPTERS = get_live_adapters()
 
 
 
 
 
 
6
 
7
+ async def live_search(query):
8
+ tasks = [a.search(query) for a in ADAPTERS]
9
+ results = await asyncio.gather(*tasks, return_exceptions=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ flat = []
12
+ for r in results:
13
+ if isinstance(r, list):
14
+ flat.extend(r)
15
 
16
+ return [
17
+ [x["agency"], x["source"], x["title"], x["url"]]
18
+ for x in flat
19
+ ]
 
 
 
 
 
 
20
 
21
+ def run_search(query):
22
+ return asyncio.run(live_search(query))
 
 
 
 
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  with gr.Blocks() as demo:
 
25
  gr.Markdown("""
26
  # 🏛️ Federal FOIA Intelligence Search
27
+ **Public Electronic Reading Rooms Only**
28
+ _Live CIA CREST & FBI Vault_
29
  """)
30
 
31
+ query = gr.Textbox(label="Search FOIA documents")
32
+ btn = gr.Button("Live Search")
 
 
 
 
 
33
 
34
+ table = gr.Dataframe(
35
+ headers=["Agency", "Source", "Title", "URL"],
36
+ interactive=False
37
+ )
 
 
 
 
38
 
39
+ btn.click(run_search, query, table)
 
40
 
41
  demo.launch()