awacke1 commited on
Commit
db8917f
1 Parent(s): 2886e5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -25
app.py CHANGED
@@ -2,23 +2,6 @@ import os
2
  import streamlit as st
3
  import folium
4
  from streamlit_folium import folium_static
5
- import pandas as pd
6
- from streamlit.runtime.state import SessionStateProxy
7
-
8
- @st.cache_resource
9
- def load_states():
10
- return pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv")
11
-
12
- @st.cache_resource
13
- def load_cities():
14
- return pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/2014_us_cities.csv")
15
-
16
- def get_lat_lon(city, state):
17
- cities_df = load_cities()
18
- city_row = cities_df[(cities_df["City"] == city) & (cities_df["State"] == state)]
19
- if not city_row.empty:
20
- return city_row["lat"].values[0], city_row["lon"].values[0]
21
- return None
22
 
23
  # Set the page configuration
24
  st.set_page_config(page_title="Google Maps 3D", layout="wide")
@@ -26,13 +9,21 @@ st.set_page_config(page_title="Google Maps 3D", layout="wide")
26
  # Set your Google Maps API key
27
  api_key = os.getenv("GM_TOKEN")
28
 
29
- # Load states data
30
- states_df = load_states()
31
- state_codes = sorted(states_df["code"].unique())
 
 
 
 
 
 
 
 
32
 
33
  # Initialize session state
34
  if "city" not in st.session_state:
35
- st.session_state["city"] = "Mound"
36
  if "state" not in st.session_state:
37
  st.session_state["state"] = "MN"
38
 
@@ -48,16 +39,16 @@ st.session_state["state"] = state
48
 
49
  # Get the latitude and longitude of the selected city and state
50
  if search_button:
51
- lat_lon = get_lat_lon(city, state)
52
- if lat_lon:
53
- map_center = list(lat_lon)
54
  map_zoom = 12
55
  else:
56
  st.warning(f"Could not find the city '{city}' in the state '{state}'.")
57
  map_center = [37.7749, -122.4194] # Example coordinates for San Francisco
58
  map_zoom = 12
59
  else:
60
- map_center = get_lat_lon("Mound", "MN")
61
  map_zoom = 12
62
 
63
  # Create a Folium map instance
 
2
  import streamlit as st
3
  import folium
4
  from streamlit_folium import folium_static
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Set the page configuration
7
  st.set_page_config(page_title="Google Maps 3D", layout="wide")
 
9
  # Set your Google Maps API key
10
  api_key = os.getenv("GM_TOKEN")
11
 
12
+ # Define state codes
13
+ state_codes = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
14
+
15
+ # Define a dictionary of city coordinates
16
+ city_coords = {
17
+ "Mound, MN": [44.9327, -93.6663],
18
+ "San Francisco, CA": [37.7749, -122.4194],
19
+ "New York, NY": [40.7128, -74.0060],
20
+ "Chicago, IL": [41.8781, -87.6298],
21
+ # Add more cities and their coordinates as needed
22
+ }
23
 
24
  # Initialize session state
25
  if "city" not in st.session_state:
26
+ st.session_state["city"] = "Mound, MN"
27
  if "state" not in st.session_state:
28
  st.session_state["state"] = "MN"
29
 
 
39
 
40
  # Get the latitude and longitude of the selected city and state
41
  if search_button:
42
+ city_state = f"{city}, {state}"
43
+ if city_state in city_coords:
44
+ map_center = city_coords[city_state]
45
  map_zoom = 12
46
  else:
47
  st.warning(f"Could not find the city '{city}' in the state '{state}'.")
48
  map_center = [37.7749, -122.4194] # Example coordinates for San Francisco
49
  map_zoom = 12
50
  else:
51
+ map_center = city_coords["Mound, MN"]
52
  map_zoom = 12
53
 
54
  # Create a Folium map instance