Samanthas50ThBirthday / src /streamlit_app.py
awacke1's picture
Update src/streamlit_app.py
d385586 verified
import streamlit as st
import pandas as pd
import folium
from streamlit_folium import st_folium
import base64
# --- Base64 Encoded Assets ---
map_marker_icon_b64 = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" # Placeholder - replace with a fun map marker!
# --- NPI State and Country Codes (Simplified for Demo) ---
state_codes = {"Minnesota": "MN", "California": "CA", "Colorado": "CO"} # Add more as needed
country_codes = {"United States": "US", "Peru": "PE", "Scotland": "GB"} # Add more as needed
# --- Introduction and Instructions ---
st.title("πŸ—ΊοΈ Samantha's Epic Birthday Adventure Map! πŸŽ‰")
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 πŸ˜‰)")
st.header("Step 1: Unleash the Location Data! πŸš€")
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.")
st.subheader("πŸ“Έ From Google Photos (Operation: Picture This!):")
st.markdown(
"""
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:
* **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.
* **Option 2 (The Slightly Less Techy Tourist):** While Google Photos doesn't directly offer a bulk export of just location data, you can:
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.
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!
"""
)
st.subheader("πŸ“ From Google Maps Location History (Operation: Map Quest!):")
st.markdown(
"""
Ah, the treasure trove of your wanderings! Let's snag that sweet location history:
1. Head over to [Google Takeout](https://takeout.google.com/).
2. Select "Location History".
3. Choose your desired timeframe (the last four years of epicness!).
4. Pick your preferred format (JSON is generally easier to work with in Python).
5. Click 'Export' and prepare for a file that knows you better than your own GPS sometimes!
"""
)
st.subheader("πŸ‘¨β€πŸ‘¦ From Family Sharing (Operation: Sharing is Caring!):")
st.markdown(
"""
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!
"""
)
# --- Location Data Processing and Map Display ---
st.header("Step 2: Let's Get This Data on the Map! πŸ—ΊοΈ")
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*!).")
map_code = f"""
import streamlit as st
import pandas as pd
import folium
from streamlit_folium import st_folium
import base64
# --- Your Base64 Encoded Map Marker (Replace the placeholder!) ---
map_marker_icon_b64 = "{map_marker_icon_b64}"
decoded_marker = base64.b64decode(map_marker_icon_b64)
st.title("Samantha & [Your Name]'s Amazing Adventures! 🌍")
st.markdown("A map of all the places we've explored together over the last four years. Sign this poster and let's reminisce!")
# --- Instructions for Loading Your Data ---
st.sidebar.header("Data Input")
photo_data_file = st.sidebar.file_uploader("Upload Google Photos Location CSV (if you extracted metadata)", type=["csv"])
location_history_file = st.sidebar.file_uploader("Upload Google Maps Location History JSON", type=["json"])
locations = []
if photo_data_file is not None:
try:
photo_df = pd.read_csv(photo_data_file)
# Assuming your CSV has 'latitude' and 'longitude' columns
if 'latitude' in photo_df.columns and 'longitude' in photo_df.columns:
for index, row in photo_df.iterrows():
locations.append((row['latitude'], row['longitude'], "Photo Location")) # Add labels if you want
st.sidebar.success("Google Photos data loaded!")
else:
st.sidebar.error("CSV file missing 'latitude' or 'longitude' columns.")
except Exception as e:
st.sidebar.error(f"Error loading Photos CSV: {e}") # This line should be correct
if location_history_file is not None:
try:
import json
location_data = json.load(location_history_file)
for record in location_data.get('locations', []):
if 'latitude' in record and 'longitude' in record:
lat = record['latitudeE7'] / 1e7
lon = record['longitudeE7'] / 1e7
locations.append((lat, lon, "Map History")) # Add labels if you want
st.sidebar.success("Google Maps Location History loaded!")
except Exception as e:
st.sidebar.error(f"Error loading Location History JSON: {e}")
if locations:
latitudes = [loc[0] for loc in locations]
longitudes = [loc[1] for loc in locations]
# Calculate the center of your travels
center_lat = sum(latitudes) / len(latitudes)
center_lon = sum(longitudes) / len(longitudes)
# Create a Folium map centered around your travel midpoint
m = folium.Map(location=[center_lat, center_lon], zoom_start=2)
# Add markers for each location
for lat, lon, label in locations:
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)
# Display the map in Streamlit
st_folium(m, width='100%', height=700)
else:
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!")
"""
st.code(map_code, language="python")
st.markdown("πŸ’Ύ **Download this code!** Right-click on the code box above and choose 'Save as...' to save it as `app.py`.")
# --- Trivia Game ---
st.header("Step 3: Samantha Trivia Time! πŸ€”")
st.markdown("Let's see who knows Samantha's travel history best! Prepare for some brainy fun!")
with st.expander("🌍 Countries Visited in the Last 10 Years (Guess 'Em All!)"):
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!)")
st.code(f"Example Country Codes:\n{country_codes}", language="python")
with st.expander("πŸ‡ΊπŸ‡Έ States Visited in the Last 10 Years (Name Those States!)"):
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!)")
st.code(f"Example State Codes:\n{state_codes}", language="python")
# --- Future AI-Powered Awesomeness ---
st.header("Step 4: The AI Revolution is Coming! πŸ€–")
st.markdown(
"""
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:
* **Automatic Data Extraction:** AI that intelligently parses your photos and location history without manual file uploads!
* **Trip Summaries:** AI generating witty summaries of each location based on your photos and notes!
* **Personalized Recommendations:** AI suggesting future destinations based on your past adventures!
* **Interactive Storytelling:** An AI-powered map that tells the story of your travels with photos and videos triggered by clicks!
The possibilities are as vast as the places you've been! Keep exploring, keep coding, and keep the AI adventures coming! πŸ˜‰
"""
)
st.balloons() # Because every awesome app deserves balloons!