Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# streamlit_app.py - Bolt Driver Recommendation
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
@@ -368,87 +368,82 @@ def main():
|
|
368 |
with col1:
|
369 |
st.markdown('<div class="section-header">Demand Map</div>', unsafe_allow_html=True)
|
370 |
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
# Add recommendation markers
|
388 |
-
for i, rec in enumerate(recommendations):
|
389 |
-
folium.CircleMarker(
|
390 |
-
location=[rec["center_lat"], rec["center_lng"]],
|
391 |
-
radius=20,
|
392 |
-
color="red",
|
393 |
-
fill=True,
|
394 |
-
fill_color="red",
|
395 |
-
fill_opacity=0.6,
|
396 |
-
popup=f"""
|
397 |
-
<b>Recommendation {i+1}</b><br>
|
398 |
-
Expected rides: {rec['predicted_rides']:.1f}<br>
|
399 |
-
Avg value: €{rec['avg_value']:.2f}<br>
|
400 |
-
Expected value: €{rec['expected_value']:.2f}<br>
|
401 |
-
{f'Distance: {rec["distance_km"]:.2f} km' if rec["distance_km"] is not None else ''}
|
402 |
-
"""
|
403 |
-
).add_to(m)
|
404 |
|
405 |
-
# Add
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
|
|
419 |
"""
|
420 |
-
)
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
radius=15,
|
436 |
-
gradient={
|
437 |
-
0.2: 'blue',
|
438 |
-
0.4: 'lime',
|
439 |
-
0.6: 'yellow',
|
440 |
-
0.8: 'orange',
|
441 |
-
1.0: 'red'
|
442 |
-
},
|
443 |
-
name="Demand Heatmap",
|
444 |
-
show=True
|
445 |
-
).add_to(m)
|
446 |
-
|
447 |
-
# Add layer control
|
448 |
-
folium.LayerControl().add_to(m)
|
449 |
-
|
450 |
-
# Display the map
|
451 |
-
folium_static(m, width=700)
|
452 |
|
453 |
with col2:
|
454 |
st.markdown('<div class="section-header">Recommendations</div>', unsafe_allow_html=True)
|
|
|
1 |
+
# streamlit_app.py - Bolt Driver Recommendation System
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
import numpy as np
|
|
|
368 |
with col1:
|
369 |
st.markdown('<div class="section-header">Demand Map</div>', unsafe_allow_html=True)
|
370 |
|
371 |
+
try:
|
372 |
+
# Create map
|
373 |
+
m = folium.Map(
|
374 |
+
location=[59.436, 24.753], # Tallinn center
|
375 |
+
zoom_start=12,
|
376 |
+
tiles="CartoDB positron"
|
377 |
+
)
|
378 |
+
|
379 |
+
# Add driver marker if location provided
|
380 |
+
if use_location:
|
381 |
+
folium.Marker(
|
382 |
+
location=[current_lat, current_lng],
|
383 |
+
popup="Your Location",
|
384 |
+
icon=folium.Icon(color="blue", icon="user", prefix="fa"),
|
385 |
+
tooltip="Your Current Location"
|
386 |
+
).add_to(m)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
|
388 |
+
# Add recommendation markers
|
389 |
+
for i, rec in enumerate(recommendations):
|
390 |
+
folium.CircleMarker(
|
391 |
+
location=[rec["center_lat"], rec["center_lng"]],
|
392 |
+
radius=20,
|
393 |
+
color="red",
|
394 |
+
fill=True,
|
395 |
+
fill_color="red",
|
396 |
+
fill_opacity=0.6,
|
397 |
+
popup=f"""
|
398 |
+
<b>Recommendation {i+1}</b><br>
|
399 |
+
Expected rides: {rec['predicted_rides']:.1f}<br>
|
400 |
+
Avg value: €{rec['avg_value']:.2f}<br>
|
401 |
+
Expected value: €{rec['expected_value']:.2f}<br>
|
402 |
+
{f'Distance: {rec["distance_km"]:.2f} km' if rec["distance_km"] is not None else ''}
|
403 |
"""
|
404 |
+
).add_to(m)
|
405 |
+
|
406 |
+
# Add number label - using HTML directly to avoid the split error
|
407 |
+
folium.Marker(
|
408 |
+
location=[rec["center_lat"], rec["center_lng"]],
|
409 |
+
icon=folium.DivIcon(
|
410 |
+
html=f'<div style="font-size:12pt;color:white;font-weight:bold;text-align:center;width:25px;height:25px;line-height:25px;">{i+1}</div>'
|
411 |
+
)
|
412 |
+
).add_to(m)
|
413 |
+
|
414 |
+
# Add heatmap if enabled
|
415 |
+
if show_heatmap:
|
416 |
+
# Get a larger set of predictions for the heatmap
|
417 |
+
all_predictions = model.predict(day_idx, selected_hour, top_n=100)
|
418 |
+
heat_data = [
|
419 |
+
[pred["center_lat"], pred["center_lng"], pred["predicted_rides"]]
|
420 |
+
for pred in all_predictions
|
421 |
+
]
|
422 |
+
|
423 |
+
# Add heatmap layer
|
424 |
+
HeatMap(
|
425 |
+
heat_data,
|
426 |
+
radius=15,
|
427 |
+
gradient={
|
428 |
+
0.2: 'blue',
|
429 |
+
0.4: 'lime',
|
430 |
+
0.6: 'yellow',
|
431 |
+
0.8: 'orange',
|
432 |
+
1.0: 'red'
|
433 |
+
},
|
434 |
+
name="Demand Heatmap",
|
435 |
+
show=True
|
436 |
+
).add_to(m)
|
437 |
+
|
438 |
+
# Add layer control
|
439 |
+
folium.LayerControl().add_to(m)
|
440 |
+
|
441 |
+
# Display the map
|
442 |
+
folium_static(m, width=700)
|
443 |
|
444 |
+
except Exception as e:
|
445 |
+
st.error(f"Error rendering map: {e}")
|
446 |
+
st.info("Showing tabular results instead.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
|
448 |
with col2:
|
449 |
st.markdown('<div class="section-header">Recommendations</div>', unsafe_allow_html=True)
|