Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,18 @@
|
|
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 = '''
|
@@ -35,19 +44,15 @@ def generate_speech_textarea(text_to_speak):
|
|
35 |
# Main code
|
36 |
st.title('United States Trivia 🇺🇸')
|
37 |
|
38 |
-
# List of states and associated icons
|
39 |
-
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV', 'TN', 'HI', 'SD']
|
40 |
-
icons = ['❄️', '🌞', '🌲', '🌴', '🤠', '🗽', '🎲', '🎵', '🏝️', '🌾']
|
41 |
-
|
42 |
# Load the USA shapefile using GeoPandas
|
43 |
usa = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
|
44 |
usa = usa[usa.continent == 'North America']
|
45 |
|
46 |
# Generate dropdown menu to select a state
|
47 |
-
selected_state = st.selectbox("Choose a state:",
|
48 |
|
49 |
# Find the selected state's geometry
|
50 |
-
selected_state_geom = usa[usa.
|
51 |
|
52 |
# Plot the selected state using Plotly
|
53 |
fig = px.choropleth(usa,
|
@@ -60,23 +65,10 @@ fig.add_trace(px.scatter_geo(lat=[selected_state_geom.centroid.y],
|
|
60 |
st.plotly_chart(fig)
|
61 |
|
62 |
# Show fascinating facts based on selected state
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
generate_speech_textarea("Florida (FL) \n1️⃣ Home to Walt Disney World \n2️⃣ Florida Keys \n3️⃣ Largest Company: World Fuel Services, Revenue: $27.0B")
|
71 |
-
elif selected_state == 'TX':
|
72 |
-
generate_speech_textarea("Texas (TX) \n1️⃣ Birthplace of Texas Country Music \n2️⃣ Tex-Mex Cuisine \n3️⃣ Largest Company: ExxonMobil, Revenue: $265.7B")
|
73 |
-
elif selected_state == 'NY':
|
74 |
-
generate_speech_textarea("New York (NY) \n1️⃣ Home of Wall Street \n2️⃣ The Big Apple \n3️⃣ Largest Company: JPMorgan Chase, Revenue: $119.5B")
|
75 |
-
elif selected_state == 'NV':
|
76 |
-
generate_speech_textarea("Nevada (NV) \n1️⃣ Las Vegas Strip \n2️⃣ Area 51 \n3️⃣ Largest Company: Las Vegas Sands, Revenue: $13.7B")
|
77 |
-
elif selected_state == 'TN':
|
78 |
-
generate_speech_textarea("Tennessee (TN) \n1️⃣ Home of Country Music \n2️⃣ Tennessee Whiskey \n3️⃣ Largest Company: FedEx, Revenue: $69.2B")
|
79 |
-
elif selected_state == 'HI':
|
80 |
-
generate_speech_textarea("Hawaii (HI) \n1️⃣ Aloha Spirit \n2️⃣ Surfing Paradise \n3️⃣ Largest Company: Hawaiian Electric Industries, Revenue: $2.9B")
|
81 |
-
elif selected_state == 'SD':
|
82 |
-
generate_speech_textarea("South Dakota (SD) \n1️⃣ Mount Rushmore \n2️⃣ Badlands National Park \n3️⃣ Largest Company: Sanford Health, Revenue: $4.5B")
|
|
|
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 = '''
|
|
|
44 |
# Main code
|
45 |
st.title('United States Trivia 🇺🇸')
|
46 |
|
|
|
|
|
|
|
|
|
47 |
# Load the USA shapefile using GeoPandas
|
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 |
+
selected_state = st.selectbox("Choose a state:", list(state_data.keys()))
|
53 |
|
54 |
# Find the selected state's geometry
|
55 |
+
selected_state_geom = usa[usa.name == selected_state].geometry.iloc[0]
|
56 |
|
57 |
# Plot the selected state using Plotly
|
58 |
fig = px.choropleth(usa,
|
|
|
65 |
st.plotly_chart(fig)
|
66 |
|
67 |
# Show fascinating facts based on selected state
|
68 |
+
with st.expander(f"Show Trivia for {selected_state} 😃"):
|
69 |
+
trivia_text = state_data[selected_state]['trivia']
|
70 |
+
trivia_text += f"\n🏢 Largest Company: {state_data[selected_state]['largest_company']}\n💵 Revenue: ${state_data[selected_state]['revenue']}B"
|
71 |
+
|
72 |
+
if st.button('Read Aloud 📢'):
|
73 |
+
generate_speech_textarea(trivia_text)
|
74 |
+
st.markdown(trivia_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|