File size: 2,885 Bytes
0e1662c
ac0345f
f8eddcb
0e1662c
f8eddcb
 
 
3b1655c
f8eddcb
 
6910cc8
f8eddcb
 
 
 
 
 
 
 
 
 
 
 
6910cc8
f8eddcb
 
814d3fc
f8eddcb
 
 
 
 
 
3b1655c
f8eddcb
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import streamlit as st
import geopandas as gpd
import plotly.express as px

@st.cache
def load_usa_map():
    return gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))[lambda df: df.abbrev.isin(state_data.keys())]

def generate_speech_textarea(text):
    st.markdown(f'<p id="speech" hidden>{text}</p><button onclick="speechSynthesis.speak(new SpeechSynthesisUtterance(document.getElementById(\'speech\').textContent))">🔊 Speak</button>', unsafe_allow_html=True)

state_data = {
    'MN': {'name': 'Minnesota', 'trivia': '1️⃣ Home to over 10,000 lakes\n2️⃣ Boundary Waters Canoe Area', 'largest_company': 'UnitedHealth Group', 'revenue': 257.1},
    'CA': {'name': 'California', 'trivia': '1️⃣ Known for Hollywood\n2️⃣ Golden Gate Bridge', 'largest_company': 'Apple', 'revenue': 365.8},
    'WA': {'name': 'Washington', 'trivia': '1️⃣ Origin of Starbucks\n2️⃣ Mount Rainier', 'largest_company': 'Amazon', 'revenue': 386.1},
    'FL': {'name': 'Florida', 'trivia': '1️⃣ Home to Walt Disney World\n2️⃣ Florida Keys', 'largest_company': 'World Fuel Services', 'revenue': 27.0},
    'TX': {'name': 'Texas', 'trivia': '1️⃣ Birthplace of Texas Country Music\n2️⃣ Tex-Mex Cuisine', 'largest_company': 'ExxonMobil', 'revenue': 265.7},
    'NY': {'name': 'New York', 'trivia': '1️⃣ Home of Wall Street\n2️⃣ The Big Apple', 'largest_company': 'JPMorgan Chase', 'revenue': 119.5},
    'NV': {'name': 'Nevada', 'trivia': '1️⃣ Las Vegas Strip\n2️⃣ Area 51', 'largest_company': 'Las Vegas Sands', 'revenue': 13.7},
    'TN': {'name': 'Tennessee', 'trivia': '1️⃣ Home of Country Music\n2️⃣ Tennessee Whiskey', 'largest_company': 'FedEx', 'revenue': 69.2},
    'HI': {'name': 'Hawaii', 'trivia': '1️⃣ Aloha Spirit\n2️⃣ Surfing Paradise', 'largest_company': 'Hawaiian Electric Industries', 'revenue': 2.9},
    'SD': {'name': 'South Dakota', 'trivia': '1️⃣ Mount Rushmore\n2️⃣ Badlands National Park', 'largest_company': 'Sanford Health', 'revenue': 4.5}
}

usa = load_usa_map()
selected_state = st.selectbox("📍 Choose a state:", list(state_data.keys()), format_func=lambda x: f"{state_data[x]['name']} ({x})")

state_geom_df = usa[usa.abbrev == selected_state]
if not state_geom_df.empty:
    geom = state_geom_df.geometry.iloc[0]
    fig = px.choropleth(usa, geojson=usa.geometry, locations=usa.index, scope="usa")
    fig.add_trace(px.scatter_geo(lat=[geom.centroid.y], lon=[geom.centroid.x]).data[0])
    st.plotly_chart(fig)

    data = state_data[selected_state]
    text = f"🔍 Trivia:\n{data['trivia']}\n🏢 Largest Company: {data['largest_company']}\n💵 Revenue: {data['revenue']}B"
    with st.expander(f"{state_data[selected_state]['name']} ({selected_state}) 😃"):
        generate_speech_textarea(text)
        st.markdown(text)
else:
    st.error(f"🚫 No data for {selected_state}.")