awacke1 commited on
Commit
9dd240d
·
1 Parent(s): 4d69474

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -59
app.py CHANGED
@@ -1,73 +1,72 @@
1
  import streamlit as st
 
 
 
2
 
3
- # Function to parse the data for a specific state using its two-letter code
4
- def parse_state_data(data, state_code):
5
- state_data = {}
6
- current_category = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- for line in data:
9
- line = line.strip()
10
- if line.startswith(state_code + ":"):
11
- state_data["Name"] = line[len(state_code) + 1:]
12
- elif line.startswith("# Large Companies"):
13
- current_category = "Large Companies"
14
- state_data[current_category] = []
15
- elif line.startswith("# Cities"):
16
- current_category = "Cities"
17
- state_data[current_category] = []
18
- elif line.startswith("# Hospitals"):
19
- current_category = "Hospitals"
20
- state_data[current_category] = []
21
- elif line.startswith("#"):
22
- current_category = None
23
- elif current_category:
24
- state_data[current_category].append(line)
25
 
26
- return state_data
 
27
 
28
- # Function to create a search URL for Wikipedia:
29
- def create_search_url_wikipedia(query):
30
- base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
31
- return base_url + query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
32
 
33
- # Function to create a search URL for YouTube:
34
- def create_search_url_youtube(query):
35
- base_url = "https://www.youtube.com/results?search_query="
36
- return base_url + query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
37
 
38
- # Read and parse the data from the text file
39
- with open("states_data.txt", "r") as file:
40
- data = file.readlines()
 
 
 
 
41
 
42
- # Streamlit page configuration
43
- st.set_page_config(page_title="State Data", layout="wide")
44
-
45
- # Main title
46
- st.title("Top Five Lists for Different States 🏙️")
47
 
48
- # Select a state using a two-letter code
49
- selected_state = st.selectbox("Select a State:", ["MA: Massachusetts", "CA: California", "WA: Washington"])
 
50
 
51
- # Parse the data for the selected state
52
- state_code = selected_state.split(":")[0]
53
- state_data = parse_state_data(data, state_code)
 
54
 
55
- # Display the state name
56
- st.header(f"{state_data['Name']} 🏆")
 
 
57
 
58
- # Display the top five lists
59
- for category, nominees in state_data.items():
60
- if category != "Name":
61
- st.subheader(f"{category}")
62
- with st.expander(f"View {category} Nominees"):
63
- for nominee in nominees[:5]: # Show only the top five
64
- col1, col2, col3 = st.columns([4, 1, 1])
65
- with col1:
66
- st.markdown(f"* {nominee}")
67
- with col2:
68
- st.markdown(f"[Wikipedia]({create_search_url_wikipedia(nominee)})")
69
- with col3:
70
- st.markdown(f"[YouTube]({create_search_url_youtube(nominee)})")
71
 
72
  # Footer
73
- st.caption("Source: Wikipedia and YouTube")
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import folium
4
+ from streamlit_folium import st_folium
5
 
6
+ # Data for each state
7
+ data = {
8
+ "MA": {
9
+ "Companies": [
10
+ {"Name": "Amazon (MA)", "Employees": 7000, "City": "Boston"},
11
+ {"Name": "MIT (Cambridge, MA)", "Employees": 6300, "City": "Cambridge"},
12
+ {"Name": "Fidelity Investments (Boston, MA)", "Employees": 5000, "City": "Boston"},
13
+ {"Name": "State Street Corporation (Boston, MA)", "Employees": 4000, "City": "Boston"},
14
+ {"Name": "Partners Healthcare System (Boston, MA)", "Employees": 3500, "City": "Boston"}
15
+ ],
16
+ "Cities": [
17
+ {"Name": "Boston", "Population": 700000, "Income": 75000, "Latitude": 42.3601, "Longitude": -71.0589},
18
+ {"Name": "Cambridge", "Population": 120000, "Income": 85000, "Latitude": 42.3736, "Longitude": -71.1097},
19
+ # Add other cities...
20
+ ],
21
+ "Hospitals": [
22
+ {"Name": "Massachusetts General Hospital", "Beds": 1000, "City": "Boston"},
23
+ # Add other hospitals...
24
+ ]
25
+ },
26
+ # Add data for CA and WA...
27
+ }
28
 
29
+ # Streamlit page configuration
30
+ st.set_page_config(page_title="State Data", layout="wide")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ # Main title
33
+ st.title("State Information Dashboard")
34
 
35
+ # Select a state
36
+ selected_state = st.selectbox("Select a State:", ["MA", "CA", "WA"])
 
 
37
 
38
+ # Process selected state data
39
+ companies_df = pd.DataFrame(data[selected_state]["Companies"])
40
+ cities_df = pd.DataFrame(data[selected_state]["Cities"])
41
+ hospitals_df = pd.DataFrame(data[selected_state]["Hospitals"])
42
 
43
+ # Display DataFrames
44
+ st.write("Companies:")
45
+ st.dataframe(companies_df)
46
+ st.write("Cities:")
47
+ st.dataframe(cities_df)
48
+ st.write("Hospitals:")
49
+ st.dataframe(hospitals_df)
50
 
51
+ # Create a Folium map for the selected state
52
+ m = folium.Map(location=[cities_df["Latitude"].mean(), cities_df["Longitude"].mean()], zoom_start=7)
 
 
 
53
 
54
+ # Add markers for cities, companies, and hospitals
55
+ for _, city in cities_df.iterrows():
56
+ folium.Marker([city["Latitude"], city["Longitude"]], tooltip=f"{city['Name']}").add_to(m)
57
 
58
+ for _, company in companies_df.iterrows():
59
+ # Find the city's coordinates
60
+ city = cities_df[cities_df["Name"] == company["City"]].iloc[0]
61
+ folium.Marker([city["Latitude"], city["Longitude"]], tooltip=f"{company['Name']}").add_to(m)
62
 
63
+ for _, hospital in hospitals_df.iterrows():
64
+ # Find the city's coordinates
65
+ city = cities_df[cities_df["Name"] == hospital["City"]].iloc[0]
66
+ folium.Marker([city["Latitude"], city["Longitude"]], tooltip=f"{hospital['Name']}").add_to(m)
67
 
68
+ # Display the map
69
+ st_folium(m, width=700, height=500)
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  # Footer
72
+ st.caption("Data source: User provided")