import streamlit as st import folium from streamlit_folium import folium_static import pandas as pd # Sample data extracted from the notebook's Leaflet map data = { "grid_id": ["11897_2485", "11902_2482", "11904_2481", "11901_2483", "11902_2483"], "lat_min": [59.504766, 59.509923, 59.519881, 59.505209, 59.510654], "lon_min": [24.810962, 24.820996, 24.809146, 24.826864, 24.827830], "lat_max": [59.509766, 59.514923, 59.524881, 59.510209, 59.515654], "lon_max": [24.820962, 24.830996, 24.819146, 24.836864, 24.837830], "time": ["early_morning", "evening_rush", "evening_rush", "morning_rush", "early_morning"], "value": [2.46, 2.45, 2.44, 2.44, 2.44], "rides": [15, 21, 16, 16, 36], "color": ["blue", "red", "red", "green", "blue"] } # Convert to DataFrame df = pd.DataFrame(data) # Simple prediction function (simulating the model) def get_predictions(time_period): # Filter data by selected time period filtered_df = df[df["time"] == time_period] return filtered_df # Streamlit app st.title("Ride Value Prediction App") st.write("Select a time period to see predicted ride values on the map.") # Time period selector time_options = ["early_morning", "morning_rush", "evening_rush"] selected_time = st.selectbox("Choose Time Period", time_options) # Get predictions predictions = get_predictions(selected_time) # Create Folium map centered on Tallinn m = folium.Map(location=[59.4370, 24.7535], zoom_start=12) # Add rectangles to the map for _, row in predictions.iterrows(): folium.Rectangle( bounds=[[row["lat_min"], row["lon_min"]], [row["lat_max"], row["lon_max"]]], color=row["color"], fill=True, fill_opacity=0.4, popup=f"Grid: {row['grid_id']}
Time: {row['time']}
Value: €{row['value']}
Rides: {row['rides']}" ).add_to(m) # Display the map folium_static(m) # Show raw predictions below the map st.write("Predicted Ride Values:") st.dataframe(predictions[["grid_id", "time", "value", "rides"]])