awacke1 commited on
Commit
aaa6696
Β·
verified Β·
1 Parent(s): 093d703

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +149 -33
src/streamlit_app.py CHANGED
@@ -1,40 +1,156 @@
1
- import altair as alt
2
- import numpy as np
3
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import streamlit as st
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
 
 
 
 
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
 
12
 
13
- In the meantime, below is an example of what you can do with just a few lines of code:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
1
+ import streamlit as st
 
2
  import pandas as pd
3
+ import folium
4
+ from streamlit_folium import st_folium
5
+ import base64
6
+
7
+ # --- Base64 Encoded Assets ---
8
+ map_marker_icon_b64 = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" # Placeholder - replace with a fun map marker!
9
+
10
+ # --- NPI State and Country Codes (Simplified for Demo) ---
11
+ state_codes = {"Minnesota": "MN", "California": "CA", "Colorado": "CO"} # Add more as needed
12
+ country_codes = {"United States": "US", "Peru": "PE", "Scotland": "GB"} # Add more as needed
13
+
14
+ # --- Introduction and Instructions ---
15
+ st.title("πŸ—ΊοΈ Samantha's Epic Birthday Adventure Map! πŸŽ‰")
16
+ st.markdown("Get ready to chart Samantha's legendary travels! This super-duper app will help you create a mega-map signed by all her favorite people. Let's get this party on the road! (Pun intended πŸ˜‰)")
17
+
18
+ st.header("Step 1: Unleash the Location Data! πŸš€")
19
+ st.markdown("We need to wrangle those precious location crumbs from your digital breadcrumbs... I mean, photos and travel history! Don't worry, it's easier than parallel parking a minivan.")
20
+
21
+ st.subheader("πŸ“Έ From Google Photos (Operation: Picture This!):")
22
+ st.markdown(
23
+ """
24
+ Your mission, should you choose to accept it (and you should!), is to grab the location data from your amazing Google Photos. Here are a couple of ways to do it:
25
+
26
+ * **Option 1 (For the Techy Trekkie):** Consider using a tool to export the metadata of your photos. One popular option is [exiftool](https://exiftool.org/). You can then use Python to parse this metadata and extract the latitude and longitude.
27
+ * **Option 2 (The Slightly Less Techy Tourist):** While Google Photos doesn't directly offer a bulk export of just location data, you can:
28
+ 1. **Download Your Photos:** Go to [Google Takeout](https://takeout.google.com/) and select "Photos". You can choose to download photos from the last four years. Be warned, this might be a BIG download, like, 'watched all of Lord of the Rings extended editions in one sitting' big.
29
+ 2. **Extract Metadata Locally:** Once downloaded, you can use Python libraries like `Pillow` or `ExifRead` to peek inside each photo's metadata and find the GPS coordinates. It's like being a digital archaeologist!
30
+ """
31
+ )
32
+
33
+ st.subheader("πŸ“ From Google Maps Location History (Operation: Map Quest!):")
34
+ st.markdown(
35
+ """
36
+ Ah, the treasure trove of your wanderings! Let's snag that sweet location history:
37
+
38
+ 1. Head over to [Google Takeout](https://takeout.google.com/).
39
+ 2. Select "Location History".
40
+ 3. Choose your desired timeframe (the last four years of epicness!).
41
+ 4. Pick your preferred format (JSON is generally easier to work with in Python).
42
+ 5. Click 'Export' and prepare for a file that knows you better than your own GPS sometimes!
43
+ """
44
+ )
45
+
46
+ st.subheader("πŸ‘¨β€πŸ‘¦ From Family Sharing (Operation: Sharing is Caring!):")
47
+ st.markdown(
48
+ """
49
+ If your Family Sharing location history with Tyler holds clues to your adventures with Samantha, see if you can export that data from your Google account settings. Every little location point helps paint the picture of your incredible journeys!
50
+ """
51
+ )
52
+
53
+ # --- Location Data Processing and Map Display ---
54
+ st.header("Step 2: Let's Get This Data on the Map! πŸ—ΊοΈ")
55
+ st.markdown("Time to unleash the power of Python and Streamlit! Copy and paste the code below into a file named `app.py` (because, you know, it's a *python app*!).")
56
+
57
+ map_code = f"""
58
  import streamlit as st
59
+ import pandas as pd
60
+ import folium
61
+ from streamlit_folium import st_folium
62
+ import base64
63
 
64
+ # --- Your Base64 Encoded Map Marker (Replace the placeholder!) ---
65
+ map_marker_icon_b64 = "{map_marker_icon_b64}"
66
+ decoded_marker = base64.b64decode(map_marker_icon_b64)
67
+
68
+ st.title("Samantha & [Your Name]'s Amazing Adventures! 🌍")
69
+ st.markdown("A map of all the places we've explored together over the last four years. Sign this poster and let's reminisce!")
70
 
71
+ # --- Instructions for Loading Your Data ---
72
+ st.sidebar.header("Data Input")
73
+ photo_data_file = st.sidebar.file_uploader("Upload Google Photos Location CSV (if you extracted metadata)", type=["csv"])
74
+ location_history_file = st.sidebar.file_uploader("Upload Google Maps Location History JSON", type=["json"])
75
 
76
+ locations = []
77
+
78
+ if photo_data_file is not None:
79
+ try:
80
+ photo_df = pd.read_csv(photo_data_file)
81
+ # Assuming your CSV has 'latitude' and 'longitude' columns
82
+ if 'latitude' in photo_df.columns and 'longitude' in photo_df.columns:
83
+ for index, row in photo_df.iterrows():
84
+ locations.append((row['latitude'], row['longitude'], "Photo Location")) # Add labels if you want
85
+ st.sidebar.success("Google Photos data loaded!")
86
+ else:
87
+ st.sidebar.error("CSV file missing 'latitude' or 'longitude' columns.")
88
+ except Exception as e:
89
+ st.sidebar.error(f"Error loading Photos CSV: {e}")
90
+
91
+ if location_history_file is not None:
92
+ try:
93
+ import json
94
+ location_data = json.load(location_history_file)
95
+ for record in location_data.get('locations', []):
96
+ if 'latitude' in record and 'longitude' in record:
97
+ lat = record['latitudeE7'] / 1e7
98
+ lon = record['longitudeE7'] / 1e7
99
+ locations.append((lat, lon, "Map History")) # Add labels if you want
100
+ st.sidebar.success("Google Maps Location History loaded!")
101
+ except Exception as e:
102
+ st.sidebar.error(f"Error loading Location History JSON: {e}")
103
+
104
+ if locations:
105
+ latitudes = [loc[0] for loc in locations]
106
+ longitudes = [loc[1] for loc in locations]
107
+
108
+ # Calculate the center of your travels
109
+ center_lat = sum(latitudes) / len(latitudes)
110
+ center_lon = sum(longitudes) / len(longitudes)
111
+
112
+ # Create a Folium map centered around your travel midpoint
113
+ m = folium.Map(location=[center_lat, center_lon], zoom_start=2)
114
+
115
+ # Add markers for each location
116
+ for lat, lon, label in locations:
117
+ folium.Marker(location=[lat, lon], popup=label, icon=folium.DivIcon(html=f'<div style="background-color: transparent; border: none;"><img src="data:image/png;base64,{map_marker_icon_b64}" style="width: 20px; height: 20px;"></div>')).add_to(m)
118
+
119
+ # Display the map in Streamlit
120
+ st_folium(m, width='100%', height=700)
121
+
122
+ else:
123
+ st.info("⬆️ Upload your Google Photos location data (CSV if extracted) and/or your Google Maps Location History (JSON) in the sidebar to see your adventures on the map!")
124
  """
125
+ st.code(map_code, language="python")
126
+
127
+ st.markdown("πŸ’Ύ **Download this code!** Right-click on the code box above and choose 'Save as...' to save it as `app.py`.")
128
+
129
+ # --- Trivia Game ---
130
+ st.header("Step 3: Samantha Trivia Time! πŸ€”")
131
+ st.markdown("Let's see who knows Samantha's travel history best! Prepare for some brainy fun!")
132
+
133
+ with st.expander("🌍 Countries Visited in the Last 10 Years (Guess 'Em All!)"):
134
+ st.markdown("On the party game card, we'll have a list of country names. Circle the ones you think Samantha visited in the last ten years! (NPI Country Codes for extra credit!)")
135
+ st.code(f"Example Country Codes:\n{country_codes}", language="python")
136
+
137
+ with st.expander("πŸ‡ΊπŸ‡Έ States Visited in the Last 10 Years (Name Those States!)"):
138
+ st.markdown("Similar to the countries, we'll have a list of US states. Circle the ones you believe Samantha has graced with her presence in the last decade! (NPI State Codes for super extra credit!)")
139
+ st.code(f"Example State Codes:\n{state_codes}", language="python")
140
+
141
+ # --- Future AI-Powered Awesomeness ---
142
+ st.header("Step 4: The AI Revolution is Coming! πŸ€–")
143
+ st.markdown(
144
+ """
145
+ This simple app is just the beginning! With your army of 1500+ AI apps, you can totally supercharge this for future trips and parties! Imagine:
146
+
147
+ * **Automatic Data Extraction:** AI that intelligently parses your photos and location history without manual file uploads!
148
+ * **Trip Summaries:** AI generating witty summaries of each location based on your photos and notes!
149
+ * **Personalized Recommendations:** AI suggesting future destinations based on your past adventures!
150
+ * **Interactive Storytelling:** An AI-powered map that tells the story of your travels with photos and videos triggered by clicks!
151
+
152
+ The possibilities are as vast as the places you've been! Keep exploring, keep coding, and keep the AI adventures coming! πŸ˜‰
153
+ """
154
+ )
155
 
156
+ st.balloons() # Because every awesome app deserves balloons!