|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
import threading |
|
|
import time |
|
|
import random |
|
|
from streamlit_autorefresh import st_autorefresh |
|
|
|
|
|
|
|
|
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)}, |
|
|
] |
|
|
|
|
|
|
|
|
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"{l['src']} β {l['dst']}": 0 for l in lanes} |
|
|
if "markers" not in st.session_state: |
|
|
st.session_state.markers = [] |
|
|
if "running" not in st.session_state: |
|
|
st.session_state.running = False |
|
|
|
|
|
|
|
|
def generate_loads(): |
|
|
while st.session_state.running: |
|
|
lane = random.choice(lanes) |
|
|
key = f"{lane['src']} β {lane['dst']}" |
|
|
|
|
|
msg = f"FreightMinded AI: Booked load {key} ({lane['type']}, {lane['rate']})" |
|
|
st.session_state.messages.append(msg) |
|
|
st.session_state.lane_counts[key] += 1 |
|
|
st.session_state.markers.extend([ |
|
|
{"lat": lane['src_coords'][0], "lon": lane['src_coords'][1]}, |
|
|
{"lat": lane['dst_coords'][0], "lon": lane['dst_coords'][1]}, |
|
|
]) |
|
|
time.sleep(5) |
|
|
|
|
|
|
|
|
stad = st_autorefresh(interval=2000, limit=None, key="auto") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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 |
|
|
threading.Thread(target=generate_loads, daemon=True).start() |
|
|
with col2: |
|
|
if st.button("Reset"): |
|
|
st.session_state.running = False |
|
|
st.session_state.messages.clear() |
|
|
st.session_state.lane_counts = {f"{l['src']} β {l['dst']}": 0 for l in lanes} |
|
|
st.session_state.markers.clear() |
|
|
|
|
|
|
|
|
left, right = st.columns([2, 1]) |
|
|
with left: |
|
|
st.subheader("Live Feed") |
|
|
feed = st.empty() |
|
|
recent = st.session_state.messages[-20:][::-1] |
|
|
feed.markdown("\n".join(f"- {m}" for m in recent)) |
|
|
|
|
|
with right: |
|
|
st.subheader("π Key Metrics") |
|
|
total = len(st.session_state.messages) |
|
|
avg_rate = None |
|
|
|
|
|
if total > 0: |
|
|
|
|
|
rates = [float(m.split("$")[1].split("/")[0]) for m in st.session_state.messages] |
|
|
avg_rate = sum(rates) / len(rates) |
|
|
st.metric("Total Loads", total) |
|
|
if avg_rate: |
|
|
st.metric("Avg Rate ($/mi)", f"{avg_rate:.2f}") |
|
|
|
|
|
st.subheader("Loads by Lane") |
|
|
df = pd.DataFrame({ |
|
|
"Lane": list(st.session_state.lane_counts.keys()), |
|
|
"Count": list(st.session_state.lane_counts.values()) |
|
|
}).set_index("Lane") |
|
|
st.bar_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.") |
|
|
|
|
|
st.download_button("Download Report", |
|
|
data="\n".join(st.session_state.messages), |
|
|
file_name="daily_report.txt", |
|
|
mime="text/plain") |
|
|
|