awacke1 commited on
Commit
957aadb
·
1 Parent(s): 20b8116

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -2,6 +2,8 @@ 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):
@@ -43,10 +45,46 @@ def plot_state_outline(state_code):
43
  plt.title(f"{state_code} State Outline")
44
  st.pyplot(plt)
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  # States list and associated icons
47
  states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
48
  icons = ['🦆', '🌴', '🍎', '🌞', '🤠', '🗽', '🎰']
49
 
 
 
 
 
 
 
 
 
 
 
50
  # Main code
51
  st.title('U.S. States Trivia 🗺️')
52
 
 
2
  import streamlit.components.v1 as components
3
  import geopandas as gpd
4
  import matplotlib.pyplot as plt
5
+ import plotly.express as px
6
+ import json
7
 
8
  # Function to generate HTML with textarea for speech synthesis
9
  def generate_speech_textarea(text_to_speak):
 
45
  plt.title(f"{state_code} State Outline")
46
  st.pyplot(plt)
47
 
48
+ # Load the GeoJSON file
49
+ geojson_path = 'gz_2010_us_040_00_500k.json'
50
+ with open(geojson_path, 'r') as file:
51
+ us_states_geojson = json.load(file)
52
+
53
+ # Mapping of state codes to state names
54
+ state_names = {
55
+ 'MN': 'Minnesota',
56
+ 'CA': 'California',
57
+ 'WA': 'Washington',
58
+ 'FL': 'Florida',
59
+ 'TX': 'Texas',
60
+ 'NY': 'New York',
61
+ 'NV': 'Nevada'
62
+ }
63
+
64
+ # Function to display the state outline
65
+ def plot_state_outline(state_code):
66
+ state_name = state_names.get(state_code, 'Unknown')
67
+ fig = px.choropleth(locations=[state_name], geojson=us_states_geojson,
68
+ featureidkey="properties.NAME",
69
+ projection="mercator")
70
+ fig.update_geos(fitbounds="locations", visible=False)
71
+ fig.update_layout(title=f"{state_name} State Outline")
72
+ st.plotly_chart(fig)
73
+
74
  # States list and associated icons
75
  states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
76
  icons = ['🦆', '🌴', '🍎', '🌞', '🤠', '🗽', '🎰']
77
 
78
+ # Display maps for each state
79
+ for state, icon in zip(states, icons):
80
+ st.write(f"{icon} {state}")
81
+ plot_state_outline(state)
82
+
83
+
84
+ # States list and associated icons
85
+ # states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
86
+ # icons = ['🦆', '🌴', '🍎', '🌞', '🤠', '🗽', '🎰']
87
+
88
  # Main code
89
  st.title('U.S. States Trivia 🗺️')
90