Spaces:
Sleeping
Sleeping
File size: 2,019 Bytes
31d66bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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']}<br>Time: {row['time']}<br>Value: €{row['value']}<br>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"]]) |