|
import streamlit as st |
|
import streamlit.components.v1 as components |
|
import plotly.express as px |
|
import pandas as pd |
|
import geopandas as gpd |
|
|
|
|
|
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) |
|
|
|
|
|
st.title('United States Trivia 🇺🇸') |
|
|
|
|
|
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'] |
|
|
|
|
|
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV', 'TN', 'HI', 'SD'] |
|
selected_state = st.selectbox("Choose a state:", states) |
|
|
|
|
|
selected_state_geom = usa[usa.postal == selected_state].geometry.iloc[0] |
|
|
|
|
|
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) |
|
|
|
|
|
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 🏥") |
|
|