Update backupapp.py
Browse files- backupapp.py +39 -1
backupapp.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):
|
@@ -31,21 +33,56 @@ 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 |
|
@@ -72,7 +109,8 @@ for i, (state, icon) in enumerate(zip(states, icons)):
|
|
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)
|
|
|
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):
|
|
|
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",
|
72 |
+
projection="mercator")
|
73 |
+
fig.update_geos(fitbounds="locations", visible=False)
|
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 🗺️')
|
88 |
|
|
|
109 |
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."
|
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)
|