awacke1 commited on
Commit
225e12e
·
1 Parent(s): f12f2a6

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +22 -35
backupapp.py CHANGED
@@ -33,39 +33,13 @@ def generate_speech_textarea(text_to_speak):
33
  '''
34
  components.html(documentHTML5, width=1280, height=500)
35
 
 
 
 
 
 
36
 
37
-
38
-
39
- # Function to display the state outline
40
- def plot_state_outline(state_code):
41
- # Read U.S. geometries file
42
- gdf = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
43
- # Filter data for the given state
44
- gdf_state = gdf[gdf['iso_a3'] == 'USA']
45
- #gdf_state = gdf[gdf['iso_a3'] == 'state_code']
46
- # Plot the geometry
47
- ax = gdf_state.boundary.plot()
48
- plt.title(f"{state_code} State Outline")
49
- st.pyplot(plt)
50
-
51
- # Load the GeoJSON file
52
- geojson_path = 'gz_2010_us_040_00_500k.json'
53
- with open(geojson_path, 'r') as file:
54
- us_states_geojson = json.load(file)
55
-
56
- # Mapping of state codes to state names
57
- state_names = {
58
- 'MN': 'Minnesota',
59
- 'CA': 'California',
60
- 'WA': 'Washington',
61
- 'FL': 'Florida',
62
- 'TX': 'Texas',
63
- 'NY': 'New York',
64
- 'NV': 'Nevada'
65
- }
66
-
67
- # Function to display the state outline
68
- def plot_state_outline(state_code):
69
  state_name = state_names.get(state_code, 'Unknown')
70
  fig = px.choropleth(locations=[state_name], geojson=us_states_geojson,
71
  featureidkey="properties.NAME",
@@ -74,14 +48,27 @@ def plot_state_outline(state_code):
74
  fig.update_layout(title=f"{state_name} State Outline")
75
  st.plotly_chart(fig)
76
 
77
- # States list and associated icons
 
 
 
 
 
 
 
 
78
  states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
79
  icons = ['🦆', '🌴', '🍎', '🌞', '🤠', '🗽', '🎰']
80
 
 
 
 
 
 
81
  # Display maps for each state
82
  for state, icon in zip(states, icons):
83
  st.write(f"{icon} {state}")
84
- plot_state_outline(state)
85
 
86
  # Main code
87
  st.title('U.S. States Trivia 🗺️')
@@ -110,7 +97,7 @@ for i, (state, icon) in enumerate(zip(states, icons)):
110
 
111
  st.markdown(text_to_speak)
112
 
113
- plot_state_outline(state)
114
 
115
  if st.button(f"🔊 Read {state}'s Facts Aloud"):
116
  generate_speech_textarea(text_to_speak)
 
33
  '''
34
  components.html(documentHTML5, width=1280, height=500)
35
 
36
+ import geopandas as gpd
37
+ import matplotlib.pyplot as plt
38
+ import streamlit as st
39
+ import json
40
+ import plotly.express as px
41
 
42
+ def plot_state_outline(state_code, us_states_geojson, state_names):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  state_name = state_names.get(state_code, 'Unknown')
44
  fig = px.choropleth(locations=[state_name], geojson=us_states_geojson,
45
  featureidkey="properties.NAME",
 
48
  fig.update_layout(title=f"{state_name} State Outline")
49
  st.plotly_chart(fig)
50
 
51
+ geojson_path = 'gz_2010_us_040_00_500k.json'
52
+ with open(geojson_path, 'r') as file:
53
+ us_states_geojson = json.load(file)
54
+
55
+ state_names = {
56
+ 'MN': 'Minnesota', 'CA': 'California', 'WA': 'Washington',
57
+ 'FL': 'Florida', 'TX': 'Texas', 'NY': 'New York', 'NV': 'Nevada'
58
+ }
59
+
60
  states = ['MN', 'CA', 'WA', 'FL', 'TX', 'NY', 'NV']
61
  icons = ['🦆', '🌴', '🍎', '🌞', '🤠', '🗽', '🎰']
62
 
63
+ for state, icon in zip(states, icons):
64
+ st.write(f"{icon} {state}")
65
+ plot_state_outline(state, us_states_geojson, state_names)
66
+
67
+
68
  # Display maps for each state
69
  for state, icon in zip(states, icons):
70
  st.write(f"{icon} {state}")
71
+ plot_state_outline(state, us_states_geojson, state_names)
72
 
73
  # Main code
74
  st.title('U.S. States Trivia 🗺️')
 
97
 
98
  st.markdown(text_to_speak)
99
 
100
+ plot_state_outline(state, us_states_geojson, state_names)
101
 
102
  if st.button(f"🔊 Read {state}'s Facts Aloud"):
103
  generate_speech_textarea(text_to_speak)