AiDispatch / app.py
Bugstarzmedia's picture
Create app.py
dcb88fc verified
Raw History Blame Contribute Delete
9.33 kB
# app.py – Prince Haul Intelligence (Gradio on Hugging Face Spaces)
# Drop this file into a HF Space (Python / Gradio template) and run.
import gradio as gr
import datetime
import random
# -----------------------------
# MOCK BACKEND / PLACEHOLDERS
# -----------------------------
def mock_find_loads(origin, destination, truck_type, date):
# In production: call DAT / Truckstop / 123Loadboard APIs here.
sample_loads = [
{
"origin": origin or "Phoenix, AZ",
"destination": destination or "Los Angeles, CA",
"rate": f"${random.randint(1200, 2600)}",
"miles": random.randint(250, 420),
"pickup_date": date or str(datetime.date.today()),
"equipment": truck_type or "Dry Van",
}
for _ in range(5)
]
table = [
[
l["origin"],
l["destination"],
l["equipment"],
l["miles"],
l["rate"],
l["pickup_date"],
]
for l in sample_loads
]
return table
def mock_optimize_route(origin, destination, fuel_price):
# In production: call Google Maps / routing API here.
miles = random.randint(250, 2200)
mpg = 7.0
fuel_cost = round((miles / mpg) * (fuel_price or 4.0), 2)
eta_hours = round(miles / 55, 1)
summary = (
f"Optimized Route\n"
f"- Origin: {origin}\n"
f"- Destination: {destination}\n"
f"- Distance: {miles} miles\n"
f"- Estimated Time: {eta_hours} hours\n"
f"- Estimated Fuel Cost: ${fuel_cost}"
)
return summary
def mock_profit_report(revenue, fuel, maintenance, insurance, other):
# In production: pull from QuickBooks / Plaid / DB.
revenue = revenue or 0
fuel = fuel or 0
maintenance = maintenance or 0
insurance = insurance or 0
other = other or 0
total_expenses = fuel + maintenance + insurance + other
net = revenue - total_expenses
margin = 0 if revenue == 0 else round((net / revenue) * 100, 2)
report = (
f"Profit Report\n"
f"- Revenue: ${revenue:,.2f}\n"
f"- Fuel: ${fuel:,.2f}\n"
f"- Maintenance: ${maintenance:,.2f}\n"
f"- Insurance: ${insurance:,.2f}\n"
f"- Other: ${other:,.2f}\n"
f"- Total Expenses: ${total_expenses:,.2f}\n"
f"- Net Profit: ${net:,.2f}\n"
f"- Margin: {margin}%"
)
return report
def mock_ai_task_agent(task_description):
# In production: call your LLM / Manus / HappyFace agent here.
return (
"AI Agent Plan\n"
f"Task: {task_description}\n\n"
"- Step 1: Analyze current data and constraints.\n"
"- Step 2: Call relevant APIs (load boards, maps, accounting).\n"
"- Step 3: Generate recommendations and actions.\n"
"- Step 4: Log results to CEO dashboard.\n"
"- Step 5: Notify user via app / SMS / email."
)
def mock_social_media_plan(niche, platform):
ideas = [
f"{niche}: 3 tips to increase profit per mile",
f"{niche}: How AI dispatch beats manual dispatch",
f"{niche}: Before/after automation case study",
f"{niche}: Fuel savings hacks using route optimization",
]
return "\n".join([f"- {platform} Post Idea: {idea}" for idea in ideas])
def mock_youtube_workflow(niche):
return (
f"Faceless YouTube Workflow for niche: {niche}\n\n"
"1. Research 3 trending topics using YouTube search + Google Trends.\n"
"2. Write a 6–8 minute script focused on retention (hook, story, payoff).\n"
"3. Generate voiceover with ElevenLabs.\n"
"4. Create B‑roll + stock footage editor brief.\n"
"5. Design thumbnail (big face / big truck / big number).\n"
"6. Upload with SEO title, description, and tags.\n"
"7. Repeat 3–5x per week."
)
# -----------------------------
# DRIVER APP UI
# -----------------------------
with gr.Blocks(title="Prince Haul Intelligence – Driver App") as driver_app:
gr.Markdown(
"# 🚚 Prince Haul Intelligence – Driver App\n"
"Find loads, optimize routes, and track your money."
)
with gr.Tab("Find Loads"):
with gr.Row():
origin = gr.Textbox(label="Origin", placeholder="Phoenix, AZ")
destination = gr.Textbox(label="Destination", placeholder="Los Angeles, CA")
with gr.Row():
truck_type = gr.Dropdown(
["Dry Van", "Reefer", "Flatbed", "Power Only"],
value="Dry Van",
label="Truck Type",
)
pickup_date = gr.Textbox(
label="Pickup Date (YYYY-MM-DD)",
placeholder=str(datetime.date.today()),
)
find_button = gr.Button("Search Loads")
loads_table = gr.Dataframe(
headers=["Origin", "Destination", "Equipment", "Miles", "Rate", "Pickup Date"],
label="Matching Loads",
)
find_button.click(
fn=mock_find_loads,
inputs=[origin, destination, truck_type, pickup_date],
outputs=loads_table,
)
with gr.Tab("Route Optimizer"):
with gr.Row():
r_origin = gr.Textbox(label="Origin", placeholder="Phoenix, AZ")
r_destination = gr.Textbox(label="Destination", placeholder="Dallas, TX")
fuel_price = gr.Number(label="Fuel Price per Gallon (USD)", value=4.0)
route_button = gr.Button("Optimize Route")
route_output = gr.Textbox(label="Route Summary", lines=8)
route_button.click(
fn=mock_optimize_route,
inputs=[r_origin, r_destination, fuel_price],
outputs=route_output,
)
# -----------------------------
# CEO DASHBOARD UI
# -----------------------------
with gr.Blocks(title="Prince Haul Intelligence – CEO Dashboard") as ceo_dashboard:
gr.Markdown(
"# πŸ‘‘ Prince Haul Intelligence – CEO Dashboard\n"
"Monitor profit, fleet performance, and AI agents."
)
with gr.Tab("Profit Analytics"):
revenue = gr.Number(label="Total Revenue (period)", value=15000)
fuel = gr.Number(label="Fuel Cost", value=4500)
maintenance = gr.Number(label="Maintenance", value=1200)
insurance = gr.Number(label="Insurance", value=800)
other = gr.Number(label="Other Expenses", value=500)
profit_button = gr.Button("Generate Profit Report")
profit_output = gr.Textbox(label="Profit Report", lines=10)
profit_button.click(
fn=mock_profit_report,
inputs=[revenue, fuel, maintenance, insurance, other],
outputs=profit_output,
)
with gr.Tab("AI Task Agents"):
task_description = gr.Textbox(
label="Describe the task for your AI agents",
placeholder="Example: Scan all loads from Phoenix to Dallas tomorrow and pick the top 3 by RPM.",
lines=4,
)
task_button = gr.Button("Generate AI Agent Plan")
task_output = gr.Textbox(label="AI Agent Plan", lines=10)
task_button.click(
fn=mock_ai_task_agent,
inputs=task_description,
outputs=task_output,
)
# -----------------------------
# MARKETING / YOUTUBE / SOCIAL
# -----------------------------
with gr.Blocks(title="Prince Haul Intelligence – Growth Engine") as growth_engine:
gr.Markdown(
"# πŸ“ˆ PHI Growth Engine\n"
"Faceless YouTube + Social Media Automation."
)
with gr.Tab("Social Media Manager"):
niche = gr.Textbox(
label="Niche / Angle",
value="AI for Truckers",
placeholder="AI for Truckers, Fleet Automation, Dispatch Hacks, etc.",
)
platform = gr.Dropdown(
["Instagram", "Facebook", "LinkedIn", "TikTok"],
value="Instagram",
label="Platform",
)
social_button = gr.Button("Generate 4 Post Ideas")
social_output = gr.Textbox(label="Post Ideas", lines=8)
social_button.click(
fn=mock_social_media_plan,
inputs=[niche, platform],
outputs=social_output,
)
with gr.Tab("Faceless YouTube System"):
yt_niche = gr.Textbox(
label="YouTube Niche",
value="AI + Trucking Automation",
placeholder="AI + Trucking Automation",
)
yt_button = gr.Button("Generate Weekly Workflow")
yt_output = gr.Textbox(label="YouTube Workflow", lines=14)
yt_button.click(
fn=mock_youtube_workflow,
inputs=yt_niche,
outputs=yt_output,
)
# -----------------------------
# MASTER APP (TABS FOR ALL)
# -----------------------------
with gr.Blocks(title="Prince Haul Intelligence – Super App") as demo:
gr.Markdown(
"# πŸ‘‘ Prince Haul Intelligence – Super App\n"
"Driver App β€’ CEO Dashboard β€’ Growth Engine\n\n"
"_Prototype running on Hugging Face Spaces (Gradio)._"
)
with gr.Tab("Driver App"):
demo.render(driver_app)
with gr.Tab("CEO Dashboard"):
demo.render(ceo_dashboard)
with gr.Tab("Growth Engine"):
demo.render(growth_engine)
# For Hugging Face Spaces
if __name__ == "__main__":
demo.launch()