|
import streamlit as st |
|
import streamlit.components.v1 as components |
|
import geopandas as gpd |
|
import matplotlib.pyplot as plt |
|
import plotly.express as px |
|
import json |
|
|
|
|
|
def generate_speech_textarea(text_to_speak): |
|
documentHTML5 = ''' |
|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<title>Read It Aloud</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>π Read It Aloud</h1> |
|
<textarea id="textArea" rows="10" cols="80" readonly>''' |
|
documentHTML5 = documentHTML5 + text_to_speak |
|
documentHTML5 = documentHTML5 + ''' |
|
</textarea> |
|
<br> |
|
<button onclick="readAloud()">π Read Aloud</button> |
|
</body> |
|
</html> |
|
''' |
|
components.html(documentHTML5, width=1280, height=500) |
|
|
|
|
|
def plot_state_outline(state_code): |
|
|
|
gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')) |
|
|
|
gdf_state = gdf[gdf['iso_a3'] == 'USA'] |
|
|
|
|
|
ax = gdf_state.boundary.plot() |
|
plt.title(f"{state_code} State Outline") |
|
st.pyplot(plt) |
|
|
|
|
|
geojson_path = 'gz_2010_us_040_00_500k.json' |
|
with open(geojson_path, 'r') as file: |
|
us_states_geojson = json.load(file) |
|
|
|
|
|
state_names = { |
|
'MN': 'Minnesota', |
|
'CA': 'California', |
|
'WA': 'Washington', |
|
'FL': 'Florida', |
|
'TX': 'Texas', |
|
'NY': 'New York', |
|
'NV': 'Nevada' |
|
} |
|
|
|
|
|
def plot_state_outline(state_code): |
|
state_name = state_names.get(state_code, 'Unknown') |
|
fig = px.choropleth(locations=[state_name], geojson=us_states_geojson, |
|
featureidkey="properties.NAME", |
|
projection="mercator") |
|
fig.update_geos(fitbounds="locations", visible=False) |
|
fig.update_layout(title=f"{state_name} State Outline") |
|
st.plotly_chart(fig) |
|
|
|
|
|
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV'] |
|
icons = ['π¦', 'π΄', 'π', 'π', 'π€ ', 'π½', 'π°'] |
|
|
|
|
|
for state, icon in zip(states, icons): |
|
st.write(f"{icon} {state}") |
|
plot_state_outline(state) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.title('U.S. States Trivia πΊοΈ') |
|
|
|
for i, (state, icon) in enumerate(zip(states, icons)): |
|
st.markdown(f"{i + 1}. {state} {icon}") |
|
|
|
|
|
with st.expander(f"See Fascinating Facts about {state}"): |
|
text_to_speak = "" |
|
|
|
if state == 'MN': |
|
text_to_speak = "π¦ **Minnesota** \nποΈ Known as the 'Land of 10,000 Lakes' \nπ£ Famous for its fishing \nπΆ Boundary Waters offers incredible canoeing \nπ Home to prestigious colleges \nβοΈ Cold winters but lovely summers." |
|
elif state == 'CA': |
|
text_to_speak = "π΄ **California** \nπ Home to the Golden Gate Bridge \nπ¬ Center of the American entertainment industry \nπ Famous for Napa Valley's wine \nπ² Home to Redwood National Park \nπββοΈ Excellent beaches and surf spots." |
|
elif state == 'WA': |
|
text_to_speak = "π **Washington** \nβ Known for its coffee culture \nπ» Home to Mount Rainier \nπ Leading apple-producing state \nπ Rich in seafood, especially salmon \nπ§οΈ Known for its rainy weather." |
|
elif state == 'FL': |
|
text_to_speak = "π **Florida** \nποΈ Famous for its beaches \nπ’ Home to various amusement parks like Disney World \nπ Space launches from Cape Canaveral \nπ Known for the Everglades and alligators \nπ Major orange producer." |
|
elif state == 'TX': |
|
text_to_speak = "π€ **Texas** \nπ’οΈ Known for its oil and gas industry \nπ Famous for its barbecue \nπΈ Rich musical heritage \nπ Home to many cattle ranches \nπ΅ Includes part of the Chihuahuan Desert." |
|
elif state == 'NY': |
|
text_to_speak = "π½ **New York** \nποΈ Home to New York City, the largest city in the U.S. \nπ Known as the Big Apple \nπ Major hub for arts and culture \nποΈ Adirondack Mountains offer outdoor adventures \nπ Famous for its style of pizza." |
|
elif state == 'NV': |
|
text_to_speak = "π° **Nevada** \nπ Known for Las Vegas and its casinos \nποΈ Includes part of the Mojave Desert \nπͺ Entertainment is a major industry \nπ Known for the Hoover Dam \nπ½ Area 51 is located here." |
|
|
|
st.markdown(text_to_speak) |
|
plot_state_outline(state) |
|
|
|
if st.button(f"π Read {state}'s Facts Aloud"): |
|
generate_speech_textarea(text_to_speak) |
|
|