Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import threading | |
| import time | |
| import random | |
| # Data definitions for lanes | |
| lanes = [ | |
| { | |
| "src": "Dallas, TX", | |
| "dst": "Atlanta, GA", | |
| "type": "Dry Van", | |
| "rate": "$2.15/mi", | |
| "src_coords": (32.7767, -96.7970), | |
| "dst_coords": (33.7490, -84.3880), | |
| }, | |
| { | |
| "src": "Houston, TX", | |
| "dst": "Chicago, IL", | |
| "type": "Flatbed", | |
| "rate": "$2.40/mi", | |
| "src_coords": (29.7604, -95.3698), | |
| "dst_coords": (41.8781, -87.6298), | |
| }, | |
| { | |
| "src": "Savannah, GA", | |
| "dst": "Charlotte, NC", | |
| "type": "Reefer", | |
| "rate": "$2.75/mi", | |
| "src_coords": (32.0809, -81.0912), | |
| "dst_coords": (35.2271, -80.8431), | |
| }, | |
| { | |
| "src": "Memphis, TN", | |
| "dst": "Birmingham, AL", | |
| "type": "Auto Parts", | |
| "rate": "$2.10/mi", | |
| "src_coords": (35.1495, -90.0490), | |
| "dst_coords": (33.5186, -86.8104), | |
| }, | |
| { | |
| "src": "Mobile, AL", | |
| "dst": "New Orleans, LA", | |
| "type": "Tanker", | |
| "rate": "$3.15/mi", | |
| "src_coords": (30.6954, -88.0399), | |
| "dst_coords": (29.9511, -90.0715), | |
| }, | |
| ] | |
| # Initialize session state variables | |
| if 'messages' not in st.session_state: | |
| st.session_state.messages = [] | |
| if 'lane_counts' not in st.session_state: | |
| st.session_state.lane_counts = {f"{lane['src']} β {lane['dst']}": 0 for lane in lanes} | |
| if 'markers' not in st.session_state: | |
| st.session_state.markers = [] # list of dicts with lat, lon | |
| if 'running' not in st.session_state: | |
| st.session_state.running = False | |
| # Function to simulate booking loads | |
| def generate_loads(): | |
| while st.session_state.running: | |
| lane = random.choice(lanes) | |
| msg = f"FreightMinded AI: Booked load {lane['src']} β {lane['dst']} ({lane['type']}, {lane['rate']})" | |
| st.session_state.messages.append(msg) | |
| key = f"{lane['src']} β {lane['dst']}" | |
| st.session_state.lane_counts[key] += 1 | |
| # add origin and destination markers for mapping | |
| st.session_state.markers.append({"lat": lane['src_coords'][0], "lon": lane['src_coords'][1]}) | |
| st.session_state.markers.append({"lat": lane['dst_coords'][0], "lon": lane['dst_coords'][1]}) | |
| time.sleep(5) | |
| st.experimental_rerun() | |
| st.set_page_config(page_title="Freight Minded Dispatch Automation", layout="wide") | |
| st.title("π Freight Minded Dispatch Automation") | |
| st.caption("Let your truck pay like it weigh") | |
| # Control buttons | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| if st.session_state.running: | |
| if st.button("Stop Simulation"): | |
| st.session_state.running = False | |
| else: | |
| if st.button("Start Simulation"): | |
| st.session_state.running = True | |
| thread = threading.Thread(target=generate_loads) | |
| thread.start() | |
| with col2: | |
| if st.button("Reset"): | |
| st.session_state.messages = [] | |
| st.session_state.lane_counts = {f"{lane['src']} β {lane['dst']}": 0 for lane in lanes} | |
| st.session_state.markers = [] | |
| st.session_state.running = False | |
| st.experimental_rerun() | |
| # Layout: messages and sidebar | |
| left, right = st.columns([2, 1]) | |
| # Left column: message feed | |
| with left: | |
| st.subheader("Live Feed") | |
| # Display the last 20 messages | |
| for msg in st.session_state.messages[-20:][::-1]: | |
| st.markdown(f"- {msg}") | |
| # Right column: stats, chart, map, report download | |
| with right: | |
| st.subheader("Tasks") | |
| tasks = ["Demo Mode", "Live hooks", "AutoβLoop", "Branding", "Investor Mode"] | |
| for t in tasks: | |
| st.checkbox(t, value=(t == "Demo Mode"), disabled=True) | |
| st.subheader("Loads by Lane") | |
| chart_df = pd.DataFrame({ | |
| 'lane': list(st.session_state.lane_counts.keys()), | |
| 'count': list(st.session_state.lane_counts.values()) | |
| }) | |
| chart_df = chart_df.set_index('lane') | |
| st.bar_chart(chart_df) | |
| st.subheader("Route Map") | |
| if st.session_state.markers: | |
| map_df = pd.DataFrame(st.session_state.markers) | |
| st.map(map_df) | |
| else: | |
| st.info("No routes booked yet.") | |
| # Download report | |
| report_content = "\n".join(st.session_state.messages) | |
| st.download_button("Download Report", data=report_content, file_name="daily_report.txt", mime="text/plain") |