Shreneek commited on
Commit
9a9f2ab
·
verified ·
1 Parent(s): bf8419a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -79
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # streamlit_app.py - Bolt Driver Recommendation Syste
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
- # Create map
372
- m = folium.Map(
373
- location=[59.436, 24.753], # Tallinn center
374
- zoom_start=12,
375
- tiles="CartoDB positron"
376
- )
377
-
378
- # Add driver marker if location provided
379
- if use_location:
380
- folium.Marker(
381
- location=[current_lat, current_lng],
382
- popup="Your Location",
383
- icon=folium.Icon(color="blue", icon="user", prefix="fa"),
384
- tooltip="Your Current Location"
385
- ).add_to(m)
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 number label
406
- folium.Marker(
407
- location=[rec["center_lat"], rec["center_lng"]],
408
- icon=folium.DivIcon(
409
- html=f"""
410
- <div style="
411
- font-size: 12pt;
412
- color: white;
413
- font-weight: bold;
414
- text-align: center;
415
- width: 25px;
416
- height: 25px;
417
- line-height: 25px;
418
- ">{i+1}</div>
 
419
  """
420
- )
421
- ).add_to(m)
422
-
423
- # Add heatmap if enabled
424
- if show_heatmap:
425
- # Get a larger set of predictions for the heatmap
426
- all_predictions = model.predict(day_idx, selected_hour, top_n=100)
427
- heat_data = [
428
- [pred["center_lat"], pred["center_lng"], pred["predicted_rides"]]
429
- for pred in all_predictions
430
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
 
432
- # Add heatmap layer
433
- HeatMap(
434
- heat_data,
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)