awacke1 commited on
Commit
6910cc8
·
1 Parent(s): a8422d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -44
app.py CHANGED
@@ -1,7 +1,8 @@
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):
@@ -9,7 +10,7 @@ def generate_speech_textarea(text_to_speak):
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;
@@ -19,7 +20,7 @@ def generate_speech_textarea(text_to_speak):
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 + '''
@@ -31,48 +32,51 @@ def generate_speech_textarea(text_to_speak):
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)
 
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
+ import plotly.express as px
4
+ import pandas as pd
5
  import geopandas as gpd
 
6
 
7
  # Function to generate HTML with textarea for speech synthesis
8
  def generate_speech_textarea(text_to_speak):
 
10
  <!DOCTYPE html>
11
  <html>
12
  <head>
13
+ <title>State Trivia</title>
14
  <script type="text/javascript">
15
  function readAloud() {{
16
  const text = document.getElementById("textArea").value;
 
20
  </script>
21
  </head>
22
  <body>
23
+ <h1>🔊 State Trivia</h1>
24
  <textarea id="textArea" rows="10" cols="80" readonly>'''
25
  documentHTML5 = documentHTML5 + text_to_speak
26
  documentHTML5 = documentHTML5 + '''
 
32
  '''
33
  components.html(documentHTML5, width=1280, height=500)
34
 
35
+ # Main code
36
+ st.title('United States Trivia 🇺🇸')
 
 
 
 
 
 
 
 
37
 
38
+ # List of states and associated icons
39
+ states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV', 'TN', 'HI', 'SD']
40
+ icons = ['❄️', '🌞', '🌲', '🌴', '🤠', '🗽', '🎲', '🎵', '🏝️', '🌾']
41
 
42
+ # Load the USA shapefile using GeoPandas
43
+ usa = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
44
+ usa = usa[usa.continent == 'North America']
45
+
46
+ # Generate dropdown menu to select a state
47
+ selected_state = st.selectbox("Choose a state:", states)
48
+
49
+ # Find the selected state's geometry
50
+ selected_state_geom = usa[usa.postal == selected_state].geometry.iloc[0]
51
 
52
+ # Plot the selected state using Plotly
53
+ fig = px.choropleth(usa,
54
+ geojson=usa.geometry,
55
+ locations=usa.index,
56
+ scope="usa")
57
+ fig.update_geos(fitbounds="locations")
58
+ fig.add_trace(px.scatter_geo(lat=[selected_state_geom.centroid.y],
59
+ lon=[selected_state_geom.centroid.x]).data[0])
60
+ st.plotly_chart(fig)
61
 
62
+ # Show fascinating facts based on selected state
63
+ if selected_state == 'MN':
64
+ 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")
65
+ elif selected_state == 'CA':
66
+ generate_speech_textarea("California (CA) \n1️⃣ Home of Hollywood \n2️⃣ Golden Gate Bridge \n3️⃣ Largest Company: Apple, Revenue: $365.8B")
67
+ elif selected_state == 'WA':
68
+ generate_speech_textarea("Washington (WA) \n1️⃣ Origin of Starbucks \n2️⃣ Mount Rainier \n3️⃣ Largest Company: Amazon, Revenue: $386B")
69
+ elif selected_state == 'FL':
70
+ generate_speech_textarea("Florida (FL) \n1️⃣ Home to Walt Disney World \n2️⃣ Florida Keys \n3️⃣ Largest Company: World Fuel Services, Revenue: $27.0B")
71
+ elif selected_state == 'TX':
72
+ generate_speech_textarea("Texas (TX) \n1️⃣ Birthplace of Texas Country Music \n2️⃣ Tex-Mex Cuisine \n3️⃣ Largest Company: ExxonMobil, Revenue: $265.7B")
73
+ elif selected_state == 'NY':
74
+ generate_speech_textarea("New York (NY) \n1️⃣ Home of Wall Street \n2️⃣ The Big Apple \n3️⃣ Largest Company: JPMorgan Chase, Revenue: $119.5B")
75
+ elif selected_state == 'NV':
76
+ generate_speech_textarea("Nevada (NV) \n1️⃣ Las Vegas Strip \n2️⃣ Area 51 \n3️⃣ Largest Company: Las Vegas Sands, Revenue: $13.7B")
77
+ elif selected_state == 'TN':
78
+ generate_speech_textarea("Tennessee (TN) \n1️⃣ Home of Country Music \n2️⃣ Tennessee Whiskey \n3️⃣ Largest Company: FedEx, Revenue: $69.2B")
79
+ elif selected_state == 'HI':
80
+ generate_speech_textarea("Hawaii (HI) \n1️⃣ Aloha Spirit \n2️⃣ Surfing Paradise \n3️⃣ Largest Company: Hawaiian Electric Industries, Revenue: $2.9B")
81
+ elif selected_state == 'SD':
82
+ generate_speech_textarea("South Dakota (SD) \n1️⃣ Mount Rushmore \n2️⃣ Badlands National Park \n3️⃣ Largest Company: Sanford Health, Revenue: $4.5B")