File size: 1,765 Bytes
0e1662c
ac0345f
f8eddcb
0e1662c
f8eddcb
 
6907b9a
3b1655c
f8eddcb
 
6910cc8
f8eddcb
6907b9a
 
 
f8eddcb
6910cc8
f8eddcb
6907b9a
 
f8eddcb
814d3fc
6907b9a
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
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'))

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 = {
    'US-MN': {'name': 'Minnesota', 'trivia': '1️⃣ Home to over 10,000 lakes 🌊\n2️⃣ Boundary Waters Canoe Area 🛶', 'largest_company': 'UnitedHealth Group', 'revenue': 257.1},
    'US-CA': {'name': 'California', 'trivia': '1️⃣ Known for Hollywood 🎬\n2️⃣ Golden Gate Bridge 🌉', 'largest_company': 'Apple', 'revenue': 365.8},
    # ... (your other states)
}

usa = load_usa_map()
usa = usa[usa['iso_a2'].str.startswith('US', na=False)]  # Filter only US states

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['iso_a2'] == 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}.")