Shreneek commited on
Commit
31d66bc
·
verified ·
1 Parent(s): f1bdd93

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import folium
3
+ from streamlit_folium import folium_static
4
+ import pandas as pd
5
+
6
+ # Sample data extracted from the notebook's Leaflet map
7
+ data = {
8
+ "grid_id": ["11897_2485", "11902_2482", "11904_2481", "11901_2483", "11902_2483"],
9
+ "lat_min": [59.504766, 59.509923, 59.519881, 59.505209, 59.510654],
10
+ "lon_min": [24.810962, 24.820996, 24.809146, 24.826864, 24.827830],
11
+ "lat_max": [59.509766, 59.514923, 59.524881, 59.510209, 59.515654],
12
+ "lon_max": [24.820962, 24.830996, 24.819146, 24.836864, 24.837830],
13
+ "time": ["early_morning", "evening_rush", "evening_rush", "morning_rush", "early_morning"],
14
+ "value": [2.46, 2.45, 2.44, 2.44, 2.44],
15
+ "rides": [15, 21, 16, 16, 36],
16
+ "color": ["blue", "red", "red", "green", "blue"]
17
+ }
18
+
19
+ # Convert to DataFrame
20
+ df = pd.DataFrame(data)
21
+
22
+ # Simple prediction function (simulating the model)
23
+ def get_predictions(time_period):
24
+ # Filter data by selected time period
25
+ filtered_df = df[df["time"] == time_period]
26
+ return filtered_df
27
+
28
+ # Streamlit app
29
+ st.title("Ride Value Prediction App")
30
+ st.write("Select a time period to see predicted ride values on the map.")
31
+
32
+ # Time period selector
33
+ time_options = ["early_morning", "morning_rush", "evening_rush"]
34
+ selected_time = st.selectbox("Choose Time Period", time_options)
35
+
36
+ # Get predictions
37
+ predictions = get_predictions(selected_time)
38
+
39
+ # Create Folium map centered on Tallinn
40
+ m = folium.Map(location=[59.4370, 24.7535], zoom_start=12)
41
+
42
+ # Add rectangles to the map
43
+ for _, row in predictions.iterrows():
44
+ folium.Rectangle(
45
+ bounds=[[row["lat_min"], row["lon_min"]], [row["lat_max"], row["lon_max"]]],
46
+ color=row["color"],
47
+ fill=True,
48
+ fill_opacity=0.4,
49
+ popup=f"Grid: {row['grid_id']}<br>Time: {row['time']}<br>Value: €{row['value']}<br>Rides: {row['rides']}"
50
+ ).add_to(m)
51
+
52
+ # Display the map
53
+ folium_static(m)
54
+
55
+ # Show raw predictions below the map
56
+ st.write("Predicted Ride Values:")
57
+ st.dataframe(predictions[["grid_id", "time", "value", "rides"]])