Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import folium
|
3 |
+
from streamlit_folium import folium_static
|
4 |
+
from folium.plugins import MarkerCluster
|
5 |
+
import time
|
6 |
+
|
7 |
+
# Define California medical centers data
|
8 |
+
california_med_centers = [
|
9 |
+
('UCSF Medical Center', 37.7631, -122.4576, 'General medical and surgical', 'San Francisco'),
|
10 |
+
('Cedars-Sinai Medical Center', 34.0762, -118.3790, 'Heart specialty', 'Los Angeles'),
|
11 |
+
('Stanford Health Care', 37.4331, -122.1750, 'Teaching hospital', 'Stanford'),
|
12 |
+
('UCLA Medical Center', 34.0659, -118.4466, 'Research and teaching', 'Los Angeles'),
|
13 |
+
('Scripps La Jolla Hospitals', 32.8851, -117.2255, 'Multiple specialties', 'La Jolla'),
|
14 |
+
('Sharp Memorial Hospital', 32.7992, -117.1542, 'Trauma center', 'San Diego'),
|
15 |
+
('Huntington Hospital', 34.1330, -118.1475, 'Non-profit hospital', 'Pasadena'),
|
16 |
+
('Hoag Memorial Hospital', 33.6045, -117.8664, 'Community hospital', 'Newport Beach'),
|
17 |
+
('UCSD Medical Center', 32.7554, -117.1682, 'Academic health center', 'San Diego'),
|
18 |
+
('UC Davis Medical Center', 38.5539, -121.4554, 'Public academic health', 'Sacramento'),
|
19 |
+
('John Muir Medical Center', 37.9192, -122.0426, 'Heart care', 'Walnut Creek'),
|
20 |
+
('Santa Clara Valley Medical Center', 37.3121, -121.9769, 'County hospital', 'San Jose'),
|
21 |
+
('Kaiser Permanente San Francisco', 37.7741, -122.4179, 'Health maintenance organization', 'San Francisco'),
|
22 |
+
('City of Hope', 34.1285, -117.9665, 'Cancer center', 'Duarte'),
|
23 |
+
('UCI Medical Center', 33.7886, -117.8572, 'University hospital', 'Orange'),
|
24 |
+
('Good Samaritan Hospital', 34.0506, -118.2831, 'Private hospital', 'Los Angeles'),
|
25 |
+
('Los Angeles County General', 34.0581, -118.2917, 'Public hospital', 'Los Angeles'),
|
26 |
+
('California Pacific Medical Center', 37.7864, -122.4357, 'Private non-profit', 'San Francisco'),
|
27 |
+
('Sutter Roseville Medical Center', 38.7521, -121.2760, 'General medical and surgical', 'Roseville'),
|
28 |
+
('St. Joseph Hospital', 33.7821, -117.9188, 'Faith-based care', 'Orange')
|
29 |
+
]
|
30 |
+
|
31 |
+
# Initialize session state for car position and movement
|
32 |
+
if 'car_position' not in st.session_state:
|
33 |
+
st.session_state.car_position = [37.7631, -122.4576] # Starting at UCSF Medical Center
|
34 |
+
if 'is_moving' not in st.session_state:
|
35 |
+
st.session_state.is_moving = False
|
36 |
+
|
37 |
+
# Create a map centered on the car's initial position
|
38 |
+
def create_map():
|
39 |
+
m = folium.Map(location=st.session_state.car_position, zoom_start=13)
|
40 |
+
|
41 |
+
# Add medical center markers to a MarkerCluster
|
42 |
+
marker_cluster = MarkerCluster().add_to(m)
|
43 |
+
for center in california_med_centers:
|
44 |
+
folium.Marker(
|
45 |
+
location=[center[1], center[2]],
|
46 |
+
popup=f'<b>{center[0]}</b><br>Description: {center[3]}<br>City: {center[4]}',
|
47 |
+
icon=folium.Icon(color='red')
|
48 |
+
).add_to(marker_cluster)
|
49 |
+
|
50 |
+
# Add car marker
|
51 |
+
folium.Marker(
|
52 |
+
location=st.session_state.car_position,
|
53 |
+
popup='Car',
|
54 |
+
icon=folium.Icon(color='blue', icon='car', prefix='fa')
|
55 |
+
).add_to(m)
|
56 |
+
|
57 |
+
return m
|
58 |
+
|
59 |
+
# Function to move the car (simple simulation: moves toward a target)
|
60 |
+
def move_car():
|
61 |
+
target = [34.0762, -118.3790] # Example: Moving toward Cedars-Sinai
|
62 |
+
lat_step = (target[0] - st.session_state.car_position[0]) / 50 # Smooth transition
|
63 |
+
lon_step = (target[1] - st.session_state.car_position[1]) / 50
|
64 |
+
st.session_state.car_position[0] += lat_step
|
65 |
+
st.session_state.car_position[1] += lon_step
|
66 |
+
|
67 |
+
# Display the map
|
68 |
+
m = create_map()
|
69 |
+
folium_static(m)
|
70 |
+
|
71 |
+
st.markdown("""
|
72 |
+
# 🏥 California Medical Centers 🌆
|
73 |
+
The map above shows medical centers in California with a blue car marker. Use the controls below to move the car!
|
74 |
+
""")
|
75 |
+
|
76 |
+
# Car movement controls
|
77 |
+
col1, col2 = st.columns(2)
|
78 |
+
with col1:
|
79 |
+
if st.button("Start Driving"):
|
80 |
+
st.session_state.is_moving = True
|
81 |
+
with col2:
|
82 |
+
if st.button("Stop Driving"):
|
83 |
+
st.session_state.is_moving = False
|
84 |
+
|
85 |
+
# Simulate car movement if active
|
86 |
+
if st.session_state.is_moving:
|
87 |
+
move_car()
|
88 |
+
st.rerun() # Rerun the app to update the map
|
89 |
+
|
90 |
+
# Buttons to jump to medical centers
|
91 |
+
for i in range(0, len(california_med_centers), 4):
|
92 |
+
cols = st.columns(4)
|
93 |
+
for j in range(4):
|
94 |
+
if i + j < len(california_med_centers):
|
95 |
+
with cols[j]:
|
96 |
+
if st.button(california_med_centers[i + j][0]):
|
97 |
+
st.session_state.car_position = [california_med_centers[i + j][1], california_med_centers[i + j][2]]
|
98 |
+
st.rerun()
|