Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,78 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import geopandas as gpd
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
def
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# ... (your other states)
|
16 |
-
}
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
8 |
+
documentHTML5 = '''
|
9 |
+
<!DOCTYPE html>
|
10 |
+
<html>
|
11 |
+
<head>
|
12 |
+
<title>Read It Aloud</title>
|
13 |
+
<script type="text/javascript">
|
14 |
+
function readAloud() {{
|
15 |
+
const text = document.getElementById("textArea").value;
|
16 |
+
const speech = new SpeechSynthesisUtterance(text);
|
17 |
+
window.speechSynthesis.speak(speech);
|
18 |
+
}}
|
19 |
+
</script>
|
20 |
+
</head>
|
21 |
+
<body>
|
22 |
+
<h1>π Read It Aloud</h1>
|
23 |
+
<textarea id="textArea" rows="10" cols="80" readonly>'''
|
24 |
+
documentHTML5 = documentHTML5 + text_to_speak
|
25 |
+
documentHTML5 = documentHTML5 + '''
|
26 |
+
</textarea>
|
27 |
+
<br>
|
28 |
+
<button onclick="readAloud()">π Read Aloud</button>
|
29 |
+
</body>
|
30 |
+
</html>
|
31 |
+
'''
|
32 |
+
components.html(documentHTML5, width=1280, height=500)
|
33 |
|
34 |
+
# Function to display the state outline
|
35 |
+
def plot_state_outline(state_code):
|
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 |
+
# States list and associated icons
|
46 |
+
states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
|
47 |
+
icons = ['π¦', 'π΄', 'π', 'π', 'π€ ', 'π½', 'π°']
|
|
|
|
|
48 |
|
49 |
+
# Main code
|
50 |
+
st.title('U.S. States Trivia πΊοΈ')
|
51 |
|
52 |
+
for i, (state, icon) in enumerate(zip(states, icons)):
|
53 |
+
st.markdown(f"{i + 1}. {state} {icon}")
|
54 |
|
55 |
+
# Expanders for each state to outline fascinating facts
|
56 |
+
with st.expander(f"See Fascinating Facts about {state}"):
|
57 |
+
text_to_speak = ""
|
58 |
+
|
59 |
+
if state == 'MN':
|
60 |
+
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."
|
61 |
+
elif state == 'CA':
|
62 |
+
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."
|
63 |
+
elif state == 'WA':
|
64 |
+
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."
|
65 |
+
elif state == 'FL':
|
66 |
+
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."
|
67 |
+
elif state == 'TX':
|
68 |
+
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."
|
69 |
+
elif state == 'NY':
|
70 |
+
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."
|
71 |
+
elif state == 'NV':
|
72 |
+
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."
|
73 |
+
|
74 |
+
st.markdown(text_to_speak)
|
75 |
+
plot_state_outline(state)
|
76 |
+
|
77 |
+
if st.button(f"π Read {state}'s Facts Aloud"):
|
78 |
+
generate_speech_textarea(text_to_speak)
|