Spaces:
Sleeping
Sleeping
cassiebuhler
commited on
Commit
·
45d9637
1
Parent(s):
2059c4a
added parties for counties/cities pre-2000.
Browse files- app.py +32 -30
- preprocess.ipynb +4 -3
app.py
CHANGED
@@ -38,30 +38,6 @@ llm = OpenAI(api_token=st.secrets["OPENAI_API_KEY"])
|
|
38 |
df1 = pd.read_csv("data.csv")
|
39 |
agent = Agent([df1], config={"verbose": True, "response_parser": StreamlitResponse, "llm": llm})
|
40 |
|
41 |
-
with st.sidebar:
|
42 |
-
|
43 |
-
|
44 |
-
'''
|
45 |
-
## Data Assistant (experimental)
|
46 |
-
|
47 |
-
Ask questions about the landvote data, like:
|
48 |
-
|
49 |
-
- What are the top states for approved conservation funds?
|
50 |
-
- Plot the total funds spent in conservation each year.
|
51 |
-
- What city has approved the most funds in a single measure? What was the description of that vote?
|
52 |
-
- Which state has had largest number measures fail? What is that as a fraction of it's total measures?
|
53 |
-
'''
|
54 |
-
|
55 |
-
prompt = st.chat_input("Ask about the data")
|
56 |
-
if prompt:
|
57 |
-
with st.spinner():
|
58 |
-
resp = agent.chat(prompt)
|
59 |
-
if os.path.isfile('exports/charts/temp_chart.png'):
|
60 |
-
im = plt.imread('exports/charts/temp_chart.png')
|
61 |
-
st.image(im)
|
62 |
-
os.remove('exports/charts/temp_chart.png')
|
63 |
-
st.write(resp)
|
64 |
-
|
65 |
year = st.slider("Select a year", 1988, 2024, 2022, 1)
|
66 |
|
67 |
|
@@ -96,7 +72,7 @@ def create_chart(df, y_column, ylab, title, color):
|
|
96 |
# percentage of measures passing, per party
|
97 |
def get_passes(votes):
|
98 |
return (votes
|
99 |
-
.filter(_.year >= 2000)
|
100 |
.group_by("year", "party")
|
101 |
.aggregate(total=_.count(), passes=_.Status.isin(["Pass", "Pass*"]).sum())
|
102 |
.mutate(percent_passed=(_.passes / _.total).round(2),
|
@@ -107,7 +83,7 @@ def get_passes(votes):
|
|
107 |
# cumulative funding over time
|
108 |
def funding_chart(votes):
|
109 |
return (votes
|
110 |
-
.filter(_.year >= 2000)
|
111 |
.mutate(amount=_.amount.replace('$', '')
|
112 |
.replace(',', '')
|
113 |
.cast('float64'))
|
@@ -243,7 +219,7 @@ sv_style = {
|
|
243 |
]
|
244 |
}
|
245 |
|
246 |
-
party_pmtiles = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/
|
247 |
|
248 |
recent_election_year = year - year%4
|
249 |
party_style = {
|
@@ -271,12 +247,38 @@ party_style = {
|
|
271 |
}
|
272 |
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
|
275 |
m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
|
276 |
|
277 |
-
color_choice = st.radio("Color by:", ["Measure Status", "Political Party"])
|
278 |
-
social_toggle = st.toggle("Social Vulnerability Index")
|
279 |
-
party_toggle = st.toggle("Political Parties")
|
280 |
|
281 |
if social_toggle:
|
282 |
m.add_pmtiles(sv_pmtiles, style = sv_style ,visible=True, opacity=0.3, tooltip=True)
|
|
|
38 |
df1 = pd.read_csv("data.csv")
|
39 |
agent = Agent([df1], config={"verbose": True, "response_parser": StreamlitResponse, "llm": llm})
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
year = st.slider("Select a year", 1988, 2024, 2022, 1)
|
42 |
|
43 |
|
|
|
72 |
# percentage of measures passing, per party
|
73 |
def get_passes(votes):
|
74 |
return (votes
|
75 |
+
# .filter(_.year >= 2000)
|
76 |
.group_by("year", "party")
|
77 |
.aggregate(total=_.count(), passes=_.Status.isin(["Pass", "Pass*"]).sum())
|
78 |
.mutate(percent_passed=(_.passes / _.total).round(2),
|
|
|
83 |
# cumulative funding over time
|
84 |
def funding_chart(votes):
|
85 |
return (votes
|
86 |
+
# .filter(_.year >= 2000)
|
87 |
.mutate(amount=_.amount.replace('$', '')
|
88 |
.replace(',', '')
|
89 |
.cast('float64'))
|
|
|
219 |
]
|
220 |
}
|
221 |
|
222 |
+
party_pmtiles = "https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/party_polygons_all.pmtiles"
|
223 |
|
224 |
recent_election_year = year - year%4
|
225 |
party_style = {
|
|
|
247 |
}
|
248 |
|
249 |
|
250 |
+
with st.sidebar:
|
251 |
+
color_choice = st.radio("Color by:", ["Measure Status", "Political Party"])
|
252 |
+
st.divider()
|
253 |
+
|
254 |
+
social_toggle = st.toggle("Social Vulnerability Index")
|
255 |
+
party_toggle = st.toggle("Political Parties")
|
256 |
+
st.divider()
|
257 |
+
|
258 |
+
'''
|
259 |
+
## Data Assistant (experimental)
|
260 |
+
|
261 |
+
Ask questions about the landvote data, like:
|
262 |
+
|
263 |
+
- What are the top states for approved conservation funds?
|
264 |
+
- Plot the total funds spent in conservation each year.
|
265 |
+
- What city has approved the most funds in a single measure? What was the description of that vote?
|
266 |
+
- Which state has had largest number measures fail? What is that as a fraction of it's total measures?
|
267 |
+
'''
|
268 |
+
|
269 |
+
prompt = st.chat_input("Ask about the data")
|
270 |
+
if prompt:
|
271 |
+
with st.spinner():
|
272 |
+
resp = agent.chat(prompt)
|
273 |
+
if os.path.isfile('exports/charts/temp_chart.png'):
|
274 |
+
im = plt.imread('exports/charts/temp_chart.png')
|
275 |
+
st.image(im)
|
276 |
+
os.remove('exports/charts/temp_chart.png')
|
277 |
+
st.write(resp)
|
278 |
+
|
279 |
|
280 |
m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
|
281 |
|
|
|
|
|
|
|
282 |
|
283 |
if social_toggle:
|
284 |
m.add_pmtiles(sv_pmtiles, style = sv_style ,visible=True, opacity=0.3, tooltip=True)
|
preprocess.ipynb
CHANGED
@@ -24,7 +24,8 @@
|
|
24 |
"conn = ibis.duckdb.connect(extensions=[\"spatial\"])\n",
|
25 |
"\n",
|
26 |
"landvote_url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/landvote_polygons.parquet\"\n",
|
27 |
-
"party_url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/party_polygons.parquet\"\n",
|
|
|
28 |
"\n"
|
29 |
]
|
30 |
},
|
@@ -58,7 +59,7 @@
|
|
58 |
"\n",
|
59 |
"party = (conn\n",
|
60 |
" .read_parquet(party_url)\n",
|
61 |
-
" .cast({\"geometry\": \"geometry\"})\n",
|
62 |
" .mutate(municipal=ibis.case()\n",
|
63 |
" .when(_.jurisdiction.isin(['State','County']), ibis.literal(\"-\")) \n",
|
64 |
" .else_(_.municipal) \n",
|
@@ -201,7 +202,7 @@
|
|
201 |
"name": "python",
|
202 |
"nbconvert_exporter": "python",
|
203 |
"pygments_lexer": "ipython3",
|
204 |
-
"version": "3.
|
205 |
}
|
206 |
},
|
207 |
"nbformat": 4,
|
|
|
24 |
"conn = ibis.duckdb.connect(extensions=[\"spatial\"])\n",
|
25 |
"\n",
|
26 |
"landvote_url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/landvote_polygons.parquet\"\n",
|
27 |
+
"# party_url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/party_polygons.parquet\"\n",
|
28 |
+
"party_url = \"https://huggingface.co/datasets/boettiger-lab/landvote/resolve/main/party_polygons_all.parquet\"\n",
|
29 |
"\n"
|
30 |
]
|
31 |
},
|
|
|
59 |
"\n",
|
60 |
"party = (conn\n",
|
61 |
" .read_parquet(party_url)\n",
|
62 |
+
" .cast({\"geometry\": \"geometry\",\"municipal\":\"string\"})\n",
|
63 |
" .mutate(municipal=ibis.case()\n",
|
64 |
" .when(_.jurisdiction.isin(['State','County']), ibis.literal(\"-\")) \n",
|
65 |
" .else_(_.municipal) \n",
|
|
|
202 |
"name": "python",
|
203 |
"nbconvert_exporter": "python",
|
204 |
"pygments_lexer": "ipython3",
|
205 |
+
"version": "3.12.7"
|
206 |
}
|
207 |
},
|
208 |
"nbformat": 4,
|