File size: 4,390 Bytes
0e1662c e8345f0 6910cc8 8c0c3a8 ac0345f 0e1662c 3b1655c e8345f0 814d3fc 6910cc8 814d3fc 6910cc8 917b8ba 8c0c3a8 814d3fc d9a15ca 0e1662c 6910cc8 3b1655c 8c0c3a8 6910cc8 8c0c3a8 6910cc8 8c0c3a8 6910cc8 8c0c3a8 814d3fc 6910cc8 3b1655c 6910cc8 8c0c3a8 |
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 43 44 45 46 47 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 78 79 80 81 |
import streamlit as st
import streamlit.components.v1 as components
import plotly.express as px
import pandas as pd
import geopandas as gpd
# Function to generate HTML with textarea for speech synthesis
def generate_speech_textarea(text_to_speak):
documentHTML5 = '''
<!DOCTYPE html>
<html>
<head>
<title>State Trivia</title>
<script type="text/javascript">
function readAloud() {{
const text = document.getElementById("textArea").value;
const speech = new SpeechSynthesisUtterance(text);
window.speechSynthesis.speak(speech);
}}
</script>
</head>
<body>
<h1>🔊 State Trivia</h1>
<textarea id="textArea" rows="10" cols="80" readonly>'''
documentHTML5 += text_to_speak
documentHTML5 += '''
</textarea>
<br>
<button onclick="readAloud()">🔊 Read Aloud</button>
</body>
</html>
'''
components.html(documentHTML5, width=1280, height=500)
# Main code
st.title('United States Trivia 🇺🇸')
# Manually adding the state abbreviations to the GeoDataFrame
usa = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
usa = usa[usa.continent == 'North America']
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']
# Generate dropdown menu to select a state
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV', 'TN', 'HI', 'SD']
selected_state = st.selectbox("Choose a state:", states)
# Find the selected state's geometry
selected_state_geom = usa[usa.postal == selected_state].geometry.iloc[0]
# Plot the selected state using Plotly
fig = px.choropleth(usa,
geojson=usa.geometry,
locations=usa.index,
scope="usa")
fig.update_geos(fitbounds="locations")
fig.add_trace(px.scatter_geo(lat=[selected_state_geom.centroid.y],
lon=[selected_state_geom.centroid.x]).data[0])
st.plotly_chart(fig)
# Show fascinating facts based on selected state
if selected_state == 'MN':
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 💼")
elif selected_state == 'CA':
generate_speech_textarea("California (CA) 🌞\n1️⃣ Home of Hollywood 🎬\n2️⃣ Golden Gate Bridge 🌉\n3️⃣ Largest Company: Apple, Revenue: $365.8B 🍎")
elif selected_state == 'WA':
generate_speech_textarea("Washington (WA) 🌲\n1️⃣ Origin of Starbucks ☕\n2️⃣ Mount Rainier 🗻\n3️⃣ Largest Company: Amazon, Revenue: $386B 📦")
elif selected_state == 'FL':
generate_speech_textarea("Florida (FL) 🌴\n1️⃣ Home to Walt Disney World 🏰\n2️⃣ Florida Keys 🐠\n3️⃣ Largest Company: World Fuel Services, Revenue: $27.0B ⛽")
elif selected_state == 'TX':
generate_speech_textarea("Texas (TX) 🤠\n1️⃣ Birthplace of Texas Country Music 🎶\n2️⃣ Tex-Mex Cuisine 🌮\n3️⃣ Largest Company: ExxonMobil, Revenue: $265.7B 🛢️")
elif selected_state == 'NY':
generate_speech_textarea("New York (NY) 🗽\n1️⃣ Home of Wall Street 💵\n2️⃣ The Big Apple 🍎\n3️⃣ Largest Company: JPMorgan Chase, Revenue: $119.5B 🏦")
elif selected_state == 'NV':
generate_speech_textarea("Nevada (NV) 🎲\n1️⃣ Las Vegas Strip 🎰\n2️⃣ Area 51 👽\n3️⃣ Largest Company: Las Vegas Sands, Revenue: $13.7B 🏨")
elif selected_state == 'TN':
generate_speech_textarea("Tennessee (TN) 🎵\n1️⃣ Home of Country Music 🎸\n2️⃣ Tennessee Whiskey 🥃\n3️⃣ Largest Company: FedEx, Revenue: $69.2B ✈️")
elif selected_state == 'HI':
generate_speech_textarea("Hawaii (HI) 🏝️\n1️⃣ Aloha Spirit 🌺\n2️⃣ Surfing Paradise 🏄♀️\n3️⃣ Largest Company: Hawaiian Electric Industries, Revenue: $2.9B ⚡")
elif selected_state == 'SD':
generate_speech_textarea("South Dakota (SD) 🌾\n1️⃣ Mount Rushmore 🗿\n2️⃣ Badlands National Park 🏞️\n3️⃣ Largest Company: Sanford Health, Revenue: $4.5B 🏥")
|