Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
import streamlit.components.v1 as components
|
|
|
|
|
3 |
import geopandas as gpd
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
|
6 |
# Function to generate HTML with textarea for speech synthesis
|
7 |
def generate_speech_textarea(text_to_speak):
|
@@ -9,7 +10,7 @@ def generate_speech_textarea(text_to_speak):
|
|
9 |
<!DOCTYPE html>
|
10 |
<html>
|
11 |
<head>
|
12 |
-
<title>
|
13 |
<script type="text/javascript">
|
14 |
function readAloud() {{
|
15 |
const text = document.getElementById("textArea").value;
|
@@ -19,7 +20,7 @@ def generate_speech_textarea(text_to_speak):
|
|
19 |
</script>
|
20 |
</head>
|
21 |
<body>
|
22 |
-
<h1>🔊
|
23 |
<textarea id="textArea" rows="10" cols="80" readonly>'''
|
24 |
documentHTML5 = documentHTML5 + text_to_speak
|
25 |
documentHTML5 = documentHTML5 + '''
|
@@ -31,48 +32,51 @@ def generate_speech_textarea(text_to_speak):
|
|
31 |
'''
|
32 |
components.html(documentHTML5, width=1280, height=500)
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
# Read U.S. geometries file
|
37 |
-
gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
|
38 |
-
# Filter data for the given state
|
39 |
-
gdf_state = gdf[gdf['iso_a3'] == 'USA']
|
40 |
-
# Plot the geometry
|
41 |
-
ax = gdf_state.boundary.plot()
|
42 |
-
plt.title(f"{state_code} State Outline")
|
43 |
-
st.pyplot(plt)
|
44 |
|
45 |
-
#
|
46 |
-
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
|
47 |
-
icons = ['
|
48 |
|
49 |
-
#
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
if st.button(f"🔊 Read {state}'s Facts Aloud"):
|
78 |
-
generate_speech_textarea(text_to_speak)
|
|
|
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):
|
|
|
10 |
<!DOCTYPE html>
|
11 |
<html>
|
12 |
<head>
|
13 |
+
<title>State Trivia</title>
|
14 |
<script type="text/javascript">
|
15 |
function readAloud() {{
|
16 |
const text = document.getElementById("textArea").value;
|
|
|
20 |
</script>
|
21 |
</head>
|
22 |
<body>
|
23 |
+
<h1>🔊 State Trivia</h1>
|
24 |
<textarea id="textArea" rows="10" cols="80" readonly>'''
|
25 |
documentHTML5 = documentHTML5 + text_to_speak
|
26 |
documentHTML5 = documentHTML5 + '''
|
|
|
32 |
'''
|
33 |
components.html(documentHTML5, width=1280, height=500)
|
34 |
|
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:", states)
|
48 |
+
|
49 |
+
# Find the selected state's geometry
|
50 |
+
selected_state_geom = usa[usa.postal == selected_state].geometry.iloc[0]
|
51 |
|
52 |
+
# Plot the selected state using Plotly
|
53 |
+
fig = px.choropleth(usa,
|
54 |
+
geojson=usa.geometry,
|
55 |
+
locations=usa.index,
|
56 |
+
scope="usa")
|
57 |
+
fig.update_geos(fitbounds="locations")
|
58 |
+
fig.add_trace(px.scatter_geo(lat=[selected_state_geom.centroid.y],
|
59 |
+
lon=[selected_state_geom.centroid.x]).data[0])
|
60 |
+
st.plotly_chart(fig)
|
61 |
|
62 |
+
# Show fascinating facts based on selected state
|
63 |
+
if selected_state == 'MN':
|
64 |
+
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")
|
65 |
+
elif selected_state == 'CA':
|
66 |
+
generate_speech_textarea("California (CA) \n1️⃣ Home of Hollywood \n2️⃣ Golden Gate Bridge \n3️⃣ Largest Company: Apple, Revenue: $365.8B")
|
67 |
+
elif selected_state == 'WA':
|
68 |
+
generate_speech_textarea("Washington (WA) \n1️⃣ Origin of Starbucks \n2️⃣ Mount Rainier \n3️⃣ Largest Company: Amazon, Revenue: $386B")
|
69 |
+
elif selected_state == 'FL':
|
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")
|
|
|
|
|
|