File size: 4,031 Bytes
0e1662c e8345f0 ac0345f 0e1662c 3b1655c e8345f0 814d3fc 917b8ba 7b2dd92 814d3fc d9a15ca 0e1662c ac0345f 3b1655c ac0345f 3b1655c ac0345f 814d3fc ac0345f 3b1655c ac0345f |
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 |
import streamlit as st
import streamlit.components.v1 as components
import geopandas as gpd
import matplotlib.pyplot as plt
# Function to generate HTML with textarea for speech synthesis
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)
# Function to display the state outline
def plot_state_outline(state_code):
# Read U.S. geometries file
gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
# Filter data for the given state
gdf_state = gdf[gdf['iso_a3'] == 'USA']
# Plot the geometry
ax = gdf_state.boundary.plot()
plt.title(f"{state_code} State Outline")
st.pyplot(plt)
# States list and associated icons
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
icons = ['๐ฆ', '๐ด', '๐', '๐', '๐ค ', '๐ฝ', '๐ฐ']
# Main code
st.title('U.S. States Trivia ๐บ๏ธ')
for i, (state, icon) in enumerate(zip(states, icons)):
st.markdown(f"{i + 1}. {state} {icon}")
# Expanders for each state to outline fascinating facts
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)
|