Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
3 |
import plotly.express as px
|
|
|
4 |
import geopandas as gpd
|
5 |
|
6 |
-
# State trivia and facts stored in a centralized Python dictionary
|
7 |
-
state_data = {
|
8 |
-
'Minnesota': {'abbreviation': 'MN', 'trivia': '1️⃣ Home to over 10,000 lakes\n2️⃣ Boundary Waters Canoe Area', 'largest_company': 'UnitedHealth Group', 'revenue': 257.1},
|
9 |
-
'California': {'abbreviation': 'CA', 'trivia': '1️⃣ Known for Hollywood\n2️⃣ Tech Hub: Silicon Valley', 'largest_company': 'Apple', 'revenue': 365.8},
|
10 |
-
'Washington': {'abbreviation': 'WA', 'trivia': '1️⃣ Home to Microsoft\n2️⃣ Known for Coffee Shops', 'largest_company': 'Amazon', 'revenue': 386.1},
|
11 |
-
'Tennessee': {'abbreviation': 'TN', 'trivia': '1️⃣ Home to Country Music\n2️⃣ Famous for BBQ', 'largest_company': 'FedEx', 'revenue': 84.2},
|
12 |
-
'Hawaii': {'abbreviation': 'HI', 'trivia': '1️⃣ Known for Beautiful Beaches\n2️⃣ Unique Culture', 'largest_company': 'Hawaiian Electric Industries', 'revenue': 2.7},
|
13 |
-
'South Dakota': {'abbreviation': 'SD', 'trivia': '1️⃣ Home to Mount Rushmore\n2️⃣ Known for the Badlands', 'largest_company': 'Sanford Health', 'revenue': 5.1},
|
14 |
-
}
|
15 |
-
|
16 |
# Function to generate HTML with textarea for speech synthesis
|
17 |
def generate_speech_textarea(text_to_speak):
|
18 |
documentHTML5 = '''
|
@@ -31,8 +22,8 @@ def generate_speech_textarea(text_to_speak):
|
|
31 |
<body>
|
32 |
<h1>🔊 State Trivia</h1>
|
33 |
<textarea id="textArea" rows="10" cols="80" readonly>'''
|
34 |
-
documentHTML5
|
35 |
-
documentHTML5
|
36 |
</textarea>
|
37 |
<br>
|
38 |
<button onclick="readAloud()">🔊 Read Aloud</button>
|
@@ -44,15 +35,17 @@ def generate_speech_textarea(text_to_speak):
|
|
44 |
# Main code
|
45 |
st.title('United States Trivia 🇺🇸')
|
46 |
|
47 |
-
#
|
48 |
usa = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
|
49 |
usa = usa[usa.continent == 'North America']
|
|
|
50 |
|
51 |
# Generate dropdown menu to select a state
|
52 |
-
|
|
|
53 |
|
54 |
# Find the selected state's geometry
|
55 |
-
selected_state_geom = usa[usa.
|
56 |
|
57 |
# Plot the selected state using Plotly
|
58 |
fig = px.choropleth(usa,
|
@@ -65,10 +58,23 @@ fig.add_trace(px.scatter_geo(lat=[selected_state_geom.centroid.y],
|
|
65 |
st.plotly_chart(fig)
|
66 |
|
67 |
# Show fascinating facts based on selected state
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
3 |
import plotly.express as px
|
4 |
+
import pandas as pd
|
5 |
import geopandas as gpd
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Function to generate HTML with textarea for speech synthesis
|
8 |
def generate_speech_textarea(text_to_speak):
|
9 |
documentHTML5 = '''
|
|
|
22 |
<body>
|
23 |
<h1>🔊 State Trivia</h1>
|
24 |
<textarea id="textArea" rows="10" cols="80" readonly>'''
|
25 |
+
documentHTML5 += text_to_speak
|
26 |
+
documentHTML5 += '''
|
27 |
</textarea>
|
28 |
<br>
|
29 |
<button onclick="readAloud()">🔊 Read Aloud</button>
|
|
|
35 |
# Main code
|
36 |
st.title('United States Trivia 🇺🇸')
|
37 |
|
38 |
+
# Manually adding the state abbreviations to the GeoDataFrame
|
39 |
usa = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
|
40 |
usa = usa[usa.continent == 'North America']
|
41 |
+
usa['postal'] = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
|
42 |
|
43 |
# Generate dropdown menu to select a state
|
44 |
+
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV', 'TN', 'HI', 'SD']
|
45 |
+
selected_state = st.selectbox("Choose a state:", states)
|
46 |
|
47 |
# Find the selected state's geometry
|
48 |
+
selected_state_geom = usa[usa.postal == selected_state].geometry.iloc[0]
|
49 |
|
50 |
# Plot the selected state using Plotly
|
51 |
fig = px.choropleth(usa,
|
|
|
58 |
st.plotly_chart(fig)
|
59 |
|
60 |
# Show fascinating facts based on selected state
|
61 |
+
if selected_state == 'MN':
|
62 |
+
generate_speech_textarea("Minnesota (MN) ❄️\n1️⃣ Home to over 10,000 lakes 🌊\n2️⃣ Boundary Waters Canoe Area 🛶\n3️⃣ Largest Company: UnitedHealth Group, Revenue: $257.1B 💼")
|
63 |
+
elif selected_state == 'CA':
|
64 |
+
generate_speech_textarea("California (CA) 🌞\n1️⃣ Home of Hollywood 🎬\n2️⃣ Golden Gate Bridge 🌉\n3️⃣ Largest Company: Apple, Revenue: $365.8B 🍎")
|
65 |
+
elif selected_state == 'WA':
|
66 |
+
generate_speech_textarea("Washington (WA) 🌲\n1️⃣ Origin of Starbucks ☕\n2️⃣ Mount Rainier 🗻\n3️⃣ Largest Company: Amazon, Revenue: $386B 📦")
|
67 |
+
elif selected_state == 'FL':
|
68 |
+
generate_speech_textarea("Florida (FL) 🌴\n1️⃣ Home to Walt Disney World 🏰\n2️⃣ Florida Keys 🐠\n3️⃣ Largest Company: World Fuel Services, Revenue: $27.0B ⛽")
|
69 |
+
elif selected_state == 'TX':
|
70 |
+
generate_speech_textarea("Texas (TX) 🤠\n1️⃣ Birthplace of Texas Country Music 🎶\n2️⃣ Tex-Mex Cuisine 🌮\n3️⃣ Largest Company: ExxonMobil, Revenue: $265.7B 🛢️")
|
71 |
+
elif selected_state == 'NY':
|
72 |
+
generate_speech_textarea("New York (NY) 🗽\n1️⃣ Home of Wall Street 💵\n2️⃣ The Big Apple 🍎\n3️⃣ Largest Company: JPMorgan Chase, Revenue: $119.5B 🏦")
|
73 |
+
elif selected_state == 'NV':
|
74 |
+
generate_speech_textarea("Nevada (NV) 🎲\n1️⃣ Las Vegas Strip 🎰\n2️⃣ Area 51 👽\n3️⃣ Largest Company: Las Vegas Sands, Revenue: $13.7B 🏨")
|
75 |
+
elif selected_state == 'TN':
|
76 |
+
generate_speech_textarea("Tennessee (TN) 🎵\n1️⃣ Home of Country Music 🎸\n2️⃣ Tennessee Whiskey 🥃\n3️⃣ Largest Company: FedEx, Revenue: $69.2B ✈️")
|
77 |
+
elif selected_state == 'HI':
|
78 |
+
generate_speech_textarea("Hawaii (HI) 🏝️\n1️⃣ Aloha Spirit 🌺\n2️⃣ Surfing Paradise 🏄♀️\n3️⃣ Largest Company: Hawaiian Electric Industries, Revenue: $2.9B ⚡")
|
79 |
+
elif selected_state == 'SD':
|
80 |
+
generate_speech_textarea("South Dakota (SD) 🌾\n1️⃣ Mount Rushmore 🗿\n2️⃣ Badlands National Park 🏞️\n3️⃣ Largest Company: Sanford Health, Revenue: $4.5B 🏥")
|