Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import os
import pandas as pd
import matplotlib.pyplot as plt
from pandasai.llm.openai import OpenAI
from pandasai import Agent
from pandasai.responses.streamlit_response import StreamlitResponse
# from pandasai.llm.openai import OpenAI
# from pandasai import Agent
# from pandasai.responses.streamlit_response import StreamlitResponse
import leafmap.maplibregl as leafmap

st.set_page_config(layout="wide",
Expand Down Expand Up @@ -41,9 +41,9 @@


## chatbot
llm = OpenAI(api_token=st.secrets["OPENAI_API_KEY"])
df1 = pd.read_csv("data.csv")
agent = Agent([df1], config={"verbose": True, "response_parser": StreamlitResponse, "llm": llm})
# llm = OpenAI(api_token=st.secrets["OPENAI_API_KEY"])
# df1 = pd.read_csv("data.csv")
# agent = Agent([df1], config={"verbose": True, "response_parser": StreamlitResponse, "llm": llm})

year = st.slider("Select a year", 1988, 2024, 2022, 1)

Expand Down Expand Up @@ -86,6 +86,7 @@ def get_passes(votes):
.mutate(percent_passed=(_.passes / _.total).round(2),
color=ibis.case().when(_.party == "DEMOCRAT", COLORS["dem_blue"]).else_(COLORS["rep_red"]).end())
.to_pandas())



# cumulative funding over time
Expand Down Expand Up @@ -294,31 +295,31 @@ def get_style_party(jurisdiction):
justice_toggle = st.toggle("Climate and Economic Justice")
party_toggle = st.toggle("Political Parties")

st.divider()
# st.divider()

'''
## Data Assistant (experimental)
# '''
# ## Data Assistant (experimental)

Ask questions about the LandVote data, like:
# Ask questions about the LandVote data, like:

- What are the top states for approved conservation funds?
- Plot the total funds spent in conservation each year.
- What city has approved the most funds in a single measure? What was the description of that vote?
- Which state has had largest number measures fail? What is that as a fraction of it's total measures?
'''
# - What are the top states for approved conservation funds?
# - Plot the total funds spent in conservation each year.
# - What city has approved the most funds in a single measure? What was the description of that vote?
# - Which state has had largest number measures fail? What is that as a fraction of it's total measures?
# '''

prompt = st.chat_input("Ask about the data")
if prompt:
with st.spinner():
resp = agent.chat(prompt)
if os.path.isfile('exports/charts/temp_chart.png'):
im = plt.imread('exports/charts/temp_chart.png')
st.image(im)
os.remove('exports/charts/temp_chart.png')
st.write(resp)
# prompt = st.chat_input("Ask about the data")
# if prompt:
# with st.spinner():
# resp = agent.chat(prompt)
# if os.path.isfile('exports/charts/temp_chart.png'):
# im = plt.imread('exports/charts/temp_chart.png')
# st.image(im)
# os.remove('exports/charts/temp_chart.png')
# st.write(resp)


m = leafmap.Map(style="positron", center=(-100, 40), zoom=3)
m = leafmap.Map(style="positron", center=(-100, 40), zoom=3, use_message_queue=True)


if social_toggle:
Expand All @@ -335,13 +336,13 @@ def get_style_party(jurisdiction):
#compute percentage passed in given year
passed_year = votes.filter(_.year == year).filter(_.Status.isin(["Pass","Pass*"])).count().execute()
total_year= votes.filter(_.year == year).count().execute()
year_passed = (passed_year/total_year*100).round(2)
year_passed = round(passed_year/total_year*100,2)
f"{year_passed}% Measures Passed in {year}"

#compute percentage passed over entire dataset
passed = votes.filter(_.Status.isin(["Pass","Pass*"])).count().execute()
total = votes.count().execute()
overall_passed = (passed/total*100).round(2)
overall_passed = round(passed/total*100,2)
f"{overall_passed}% Measures Passed from 1988 - 2024 \n"


Expand All @@ -363,8 +364,8 @@ def get_style_party(jurisdiction):


# display charts
df_passes = get_passes(votes)
st.altair_chart(create_chart(df_passes, "percent_passed", "Percent Passed","% of Measures Passed", [COLORS["dem_blue"], COLORS["rep_red"]], chart_type="line"), use_container_width=True)
# df_passes = get_passes(votes)
# st.altair_chart(create_chart(df_passes, "percent_passed", "Percent Passed","% of Measures Passed", [COLORS["dem_blue"], COLORS["rep_red"]], chart_type="line"), use_container_width=True)

df_funding = funding_chart(votes)
st.altair_chart(create_chart(df_funding, "cumulative_funding", "Billions of Dollars", "Cumulative Funding", COLORS["dark_green"], chart_type="bar"), use_container_width=True)
Expand Down
File renamed without changes.
File renamed without changes.
181 changes: 19 additions & 162 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,162 +1,19 @@
aiohappyeyeballs==2.4.0
aiohttp==3.10.5
aiosignal==1.3.1
altair==5.4.1
annotated-types==0.7.0
anyio==4.4.0
anywidget==0.9.13
appdirs==1.4.4
asgiref==3.8.1
asttokens==2.4.1
async-timeout==4.0.3
atpublic==5.0
attrs==24.2.0
beautifulsoup4==4.12.3
blinker==1.8.2
branca==0.7.2
cachetools==5.5.0
certifi==2024.8.30
charset-normalizer==3.3.2
click==8.1.7
colour==0.1.5
comm==0.2.2
contourpy==1.3.0
cycler==0.12.1
dataclasses-json==0.6.7
decorator==5.1.1
distro==1.9.0
duckdb==1.0.0
duckdb_engine==0.13.1
exceptiongroup==1.2.2
executing==2.0.1
filelock==3.15.4
folium==0.17.0
fonttools==4.53.1
frozenlist==1.4.1
gdown==5.2.0
geojson==3.1.0
geopandas==1.0.1
gitdb==4.0.11
GitPython==3.1.43
greenlet==3.0.3
h11==0.14.0
htmltools==0.5.3
httpcore==1.0.5
httpx==0.27.2
ibis-framework==9.4.0
idna==3.8
ipyevents==2.0.2
ipyfilechooser==0.6.0
ipyleaflet==0.19.2
ipython==8.18.0
ipytree==0.2.2
ipyvue==1.11.1
ipyvuetify==1.10.0
ipywidgets==8.1.5
jedi==0.19.1
Jinja2==3.1.4
jiter==0.5.0
jsonpatch==1.33
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jupyter-leaflet==0.19.2
jupyterlab_widgets==3.0.13
kiwisolver==1.4.6
langchain==0.2.16
langchain-community==0.2.16
langchain-core==0.2.38
langchain-openai==0.1.23
langchain-text-splitters==0.2.4
langsmith==0.1.110
linkify-it-py==2.0.3
maplibre @ git+https://github.com/eodaGmbH/py-maplibregl@f7a514d4db1d7df06f70c293be9e4f9f1bc23c12
markdown-it-py==3.0.0
MarkupSafe==2.1.5
marshmallow==3.22.0
matplotlib==3.9.2
matplotlib-inline==0.1.7
mdit-py-plugins==0.4.1
mdurl==0.1.2
multidict==6.0.5
mypy-extensions==1.0.0
narwhals==1.6.2
openai==1.43.0
orjson==3.10.7
packaging==24.1
parso==0.8.4
parsy==2.1
pexpect==4.9.0
pillow==10.4.0
plotly==5.24.0
prompt-toolkit==3.0.36
protobuf==5.28.0
psygnal==0.11.1
ptyprocess==0.7.0
pure_eval==0.2.3
pyarrow==17.0.0
pyarrow-hotfix==0.6
pydantic==2.8.2
pydantic_core==2.20.1
pydeck==0.9.1
Pygments==2.18.0
pyogrio==0.9.0
pyparsing==3.1.4
pyproj==3.6.1
pyshp==2.3.1
PySocks==1.7.1
pystac==1.10.1
pystac-client==0.8.3
python-box==7.2.0
python-dateutil==2.9.0.post0
python-multipart==0.0.9
pytz==2024.1
PyYAML==6.0.2
questionary==2.0.1
referencing==0.35.1
regex==2024.7.24
requests==2.32.3
rich==13.8.0
rpds-py==0.20.0
scooby==0.10.0
shapely==2.0.6
shiny==1.0.0
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
soupsieve==2.6
SQLAlchemy==2.0.33
sqlglot==25.18.0
stack-data==0.6.3
starlette==0.38.2
streamlit==1.38.0
tenacity==8.5.0
tiktoken==0.7.0
toml==0.10.2
toolz==0.12.1
tornado==6.4.1
tqdm==4.66.5
traitlets==5.14.3
traittypes==0.2.1
typing-inspect==0.9.0
typing_extensions==4.12.2
tzdata==2024.1
uc-micro-py==1.0.3
urllib3==2.2.2
uvicorn==0.30.6
watchdog==4.0.2
watchfiles==0.24.0
wcwidth==0.2.13
websockets==13.0.1
whitebox==2.3.5
whiteboxgui==2.3.0
widgetsnbextension==4.0.13
xyzservices==2024.9.0
yarl==1.9.7
overturemaps
tippecanoe
pandasai==2.3.0
seaborn
numpy==1.26.4
leafmap
pandas
git+https://github.com/boettiger-lab/cng-python
leafmap==0.53.3
ibis-framework[duckdb]==10.3.1
lonboard==0.10.4
altair==5.3.0
rasterio==1.3.10
shapely==2.0.4
shiny==0.10.2
geoarrow-types==0.2.0
geoarrow-pandas==0.1.1
SQLAlchemy==2.0.35
duckdb_engine== 0.15.0
langchain==0.2.17
langchain-community==0.2.19
langchain-core==0.2.43
langchain-openai==0.1.25
streamlit==1.50.0
minio==7.2.15
duckdb==1.2.2