bpmredacademy's picture
Create app.py
d0892c5 verified
Raw
History Blame
20 kB
import gradio as gr
from datetime import datetime
import json
import uuid
APP_TITLE = "HumAI Signal Avatar Lab"
APP_VERSION = "v0.1.0-enterprise-demo"
LIVE_PRODUCT_URL = "https://humai-orchestration-makerfire.vercel.app"
DOMAINS = {
"Urban Mobility": "urban",
"Startup Scaling": "startup",
"Public Systems": "public",
"Finance / Compliance": "finance",
}
MODES = {
"Decision Support": "decision",
"Risk Assessment": "risk",
"Optimization": "optimization",
"AI Dispatcher": "dispatch",
}
SCENARIOS = {
"Sarajevo congestion after work hours": "congestion",
"Startup funding and resource allocation": "funding",
"Public service coordination under pressure": "service",
"Financial risk and compliance review": "compliance",
}
PRIORITIES = [
"Speed",
"Cost",
"Comfort",
"Sustainability",
"Safety",
"Urgency",
"Risk control",
"Investor readiness",
"Transparency",
"Accountability",
]
def normalize_selection(value, mapping, fallback):
return mapping.get(value, fallback)
def clamp(value, min_value=0.52, max_value=0.96):
return max(min_value, min(max_value, value))
def build_avatar_intro(domain_label, mode_label, scenario_label, priority):
return (
"HumAI Signal Avatar online.\n\n"
f"I understand that you selected **{domain_label}** with **{mode_label}** "
f"for the scenario **{scenario_label}**.\n\n"
f"Your stated priority is **{priority}**. "
"I will now translate this into a Mission Control decision structure."
)
def evaluate_mission_control(domain, mode, scenario, priority, user_context):
risk = "MEDIUM"
score = 0.72
recommendation = (
"Use structured Human-AI orchestration before taking operational action."
)
explanation = (
"HumAI structures the situation, evaluates domain context and prepares "
"a transparent recommendation for human review."
)
impact = (
"Improves clarity, reduces decision friction and creates an auditable "
"decision trail."
)
operator_note = (
"Human review remains required before real-world operational execution."
)
next_best_action = (
"Capture the context, review the recommendation and decide whether "
"additional data or human escalation is needed."
)
why_this_matters = (
"Unstructured decisions create confusion. HumAI turns fragmented context "
"into a readable operational picture."
)
avatar_response = (
"I can support this by asking clarifying questions, structuring the "
"decision and translating the output into human-readable guidance."
)
demo_pitch_line = (
"This shows how HumAI structures decisions instead of simply generating "
"chatbot-style answers."
)
if domain == "urban":
recommendation = (
"Recommend the most realistic mobility option by balancing travel "
"time, congestion pressure, user priority, cost and sustainability."
)
explanation = (
"The system treats Sarajevo congestion as a mobility decision problem, "
"not as a simple navigation question. It structures user context, "
"priority and constraints before recommending action."
)
impact = (
"Supports smarter urban movement, reduced congestion pressure and "
"clearer citizen guidance."
)
operator_note = (
"Best demonstrated as a Sarajevo AI mobility dispatcher scenario."
)
next_best_action = (
"Ask the user whether speed, cost, comfort, safety or sustainability "
"is the highest priority, then route the recommendation accordingly."
)
why_this_matters = (
"Urban mobility decisions are usually made under pressure. A structured "
"AI dispatcher can reduce uncertainty and help people choose better "
"options in real time."
)
avatar_response = (
"I will act as a Sarajevo mobility dispatcher. Before recommending a "
"route or option, I need to understand whether your priority is speed, "
"cost, comfort, safety or sustainability."
)
demo_pitch_line = (
"In this scenario, HumAI becomes a Sarajevo mobility dispatcher: it "
"receives user context, structures the mobility problem and returns "
"an explainable recommendation."
)
if domain == "startup":
recommendation = (
"Prioritize resource allocation by separating urgent survival needs "
"from strategic growth activities and investor-readiness work."
)
explanation = (
"The system structures startup uncertainty into runway, traction, "
"operational focus and investor narrative."
)
impact = (
"Improves founder focus, reduces waste, strengthens fundraising "
"preparation and helps the team communicate its operating logic."
)
operator_note = (
"Best used to show how HumAI supports founders, accelerators, mentors "
"and early-stage investors."
)
next_best_action = (
"Identify current runway, strongest traction signal and highest-risk "
"assumption before committing resources."
)
why_this_matters = (
"Startups often fail because limited capital is spent without a clear "
"operating logic. HumAI helps founders structure trade-offs before acting."
)
avatar_response = (
"I will help structure this as a founder decision. We should clarify "
"runway, traction, burn rate, investor readiness and the highest-risk "
"assumption before taking action."
)
demo_pitch_line = (
"In this scenario, HumAI helps a startup move from uncertainty to an "
"investor-ready decision narrative."
)
if domain == "public":
recommendation = (
"Structure the operational picture, classify incoming requests, "
"identify bottlenecks and route decisions to the responsible human operator."
)
explanation = (
"The system supports public-service coordination without claiming "
"autonomous authority."
)
impact = (
"Improves transparency, accountability, response coordination and "
"communication quality in public-facing workflows."
)
operator_note = (
"Best used to demonstrate accountable public-system coordination."
)
next_best_action = (
"Classify requests by urgency, public impact and responsible unit, "
"then escalate only the cases requiring human authority."
)
why_this_matters = (
"Public systems need clarity, traceability and accountability. HumAI "
"can support decision preparation while keeping people responsible."
)
avatar_response = (
"I will structure this as a public-system coordination case. The goal "
"is to clarify urgency, responsible unit, public impact and review boundary."
)
demo_pitch_line = (
"In this scenario, HumAI acts as a Mission Control layer for public "
"service coordination, not as an autonomous authority."
)
if domain == "finance":
recommendation = (
"Classify risk, explain key indicators, preserve auditability and "
"route the case toward human compliance review."
)
explanation = (
"The system structures compliance reasoning into risk, explanation, "
"traceability and human review."
)
impact = (
"Supports structured compliance analysis, risk visibility, decision "
"traceability and safer handling of sensitive financial or procurement cases."
)
operator_note = (
"Best used to explain FinC2E-style governance logic as a future "
"specialized module."
)
next_best_action = (
"Separate factual indicators from assumptions, assign preliminary risk "
"level and require human review before final disposition."
)
why_this_matters = (
"Financial and compliance decisions require explainability. HumAI can "
"help structure the case without replacing legal, financial or institutional authority."
)
avatar_response = (
"I will structure this as a governance and compliance review. The goal "
"is not autonomous enforcement, but explainable risk classification and "
"human review."
)
demo_pitch_line = (
"In this scenario, HumAI demonstrates how compliance reasoning can be "
"structured, explainable and human-reviewed."
)
if mode == "risk":
score += 0.08
recommendation += " Risk controls and documented human review should be applied."
next_best_action = (
"Document the main risk drivers, identify missing information and route "
"the case for responsible review."
)
if mode == "optimization":
score -= 0.06
recommendation += (
" Optimization should focus on time, cost, operational load and "
"measurable impact."
)
next_best_action = (
"Compare the current process with the recommended action and remove "
"the highest-friction step first."
)
if mode == "dispatch":
score += 0.03
recommendation += (
" The recommendation should be delivered through a conversational "
"dispatcher interface."
)
next_best_action = (
"Convert the recommendation into a short, user-facing message that a "
"conversational avatar or dispatcher can deliver clearly."
)
if scenario == "congestion":
risk = "MEDIUM"
score += 0.04
if scenario == "funding":
risk = "HIGH"
score += 0.09
if scenario == "service":
risk = "MEDIUM"
score += 0.02
if scenario == "compliance":
risk = "HIGH"
score += 0.10
priority_lower = priority.lower()
if priority_lower in ["urgency", "risk control", "accountability"]:
score += 0.03
if priority_lower in ["sustainability", "transparency"]:
impact += (
" The selected priority also strengthens the case for transparent, "
"responsible and socially useful decision support."
)
if user_context and len(user_context.strip()) > 0:
explanation += (
" The user-provided context was considered as an additional narrative "
"signal for the dispatcher response."
)
avatar_response += (
f"\n\nBased on your note, I would first clarify: "
f"'{user_context.strip()[:180]}'"
)
score = clamp(score)
if score >= 0.80:
risk = "HIGH"
if score >= 0.90:
risk = "CRITICAL"
decision = {
"session_id": str(uuid.uuid4()),
"timestamp": datetime.utcnow().isoformat() + "Z",
"engine": "HumAI Signal Avatar Lab",
"version": APP_VERSION,
"execution_mode": "deterministic_enterprise_fallback",
"ai_assisted": False,
"domain": domain,
"mode": mode,
"scenario": scenario,
"priority": priority,
"risk": risk,
"confidence": round(score, 2),
"human_review_required": True,
"recommendation": recommendation,
"explanation": explanation,
"impact": impact,
"operator_note": operator_note,
"next_best_action": next_best_action,
"why_this_matters": why_this_matters,
"avatar_response": avatar_response,
"demo_pitch_line": demo_pitch_line,
"product_boundary": (
"This is a public AI dispatcher laboratory and deterministic "
"demonstrator. It is not a certified production mobility, compliance "
"or public-authority system."
),
}
return decision
def render_markdown_output(decision):
risk = decision["risk"]
confidence = int(decision["confidence"] * 100)
return f"""
# HumAI Mission Control Output
**Execution Mode:** `{decision["execution_mode"]}`
**Domain:** `{decision["domain"]}`
**Use Case:** `{decision["mode"]}`
**Scenario:** `{decision["scenario"]}`
**Priority:** `{decision["priority"]}`
---
## Risk & Confidence
**Risk Level:** `{risk}`
**Confidence:** `{confidence}%`
**Human Review Required:** `YES`
---
## Recommended Action
{decision["recommendation"]}
---
## Explanation
{decision["explanation"]}
---
## Avatar Dispatcher Response
{decision["avatar_response"]}
---
## Next Best Action
{decision["next_best_action"]}
---
## Why This Matters
{decision["why_this_matters"]}
---
## Impact
{decision["impact"]}
---
## Operator Note
{decision["operator_note"]}
---
## Demo Pitch Line
> {decision["demo_pitch_line"]}
---
## Product Boundary
{decision["product_boundary"]}
"""
def run_humai_avatar(
domain_label,
mode_label,
scenario_label,
priority,
user_context,
):
domain = normalize_selection(domain_label, DOMAINS, "urban")
mode = normalize_selection(mode_label, MODES, "decision")
scenario = normalize_selection(scenario_label, SCENARIOS, "congestion")
avatar_intro = build_avatar_intro(
domain_label=domain_label,
mode_label=mode_label,
scenario_label=scenario_label,
priority=priority,
)
decision = evaluate_mission_control(
domain=domain,
mode=mode,
scenario=scenario,
priority=priority,
user_context=user_context,
)
markdown_output = render_markdown_output(decision)
json_output = json.dumps(decision, indent=2, ensure_ascii=False)
avatar_panel = f"""
## HumAI Signal Avatar
**Status:** Online
**Role:** Conversational AI Dispatcher
**Current priority:** {priority}
{avatar_intro}
---
### Next Question
**What matters most right now — speed, cost, comfort, safety, sustainability, urgency, transparency or risk control?**
The answer changes how Mission Control should prioritize the recommendation.
"""
return avatar_panel, markdown_output, json_output
def clear_inputs():
return (
"Urban Mobility",
"AI Dispatcher",
"Sarajevo congestion after work hours",
"Speed",
"",
"",
"",
"",
)
CUSTOM_CSS = """
.gradio-container {
background: radial-gradient(circle at top left, rgba(34, 211, 238, 0.16), transparent 28%),
radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.16), transparent 30%),
#020617 !important;
color: #e2e8f0 !important;
}
#humai-hero {
border: 1px solid rgba(34, 211, 238, 0.28);
border-radius: 28px;
padding: 28px;
background: linear-gradient(135deg, rgba(8, 47, 73, 0.78), rgba(15, 23, 42, 0.94));
box-shadow: 0 22px 80px rgba(8, 145, 178, 0.16);
}
#humai-hero h1 {
font-size: 42px;
line-height: 1.05;
margin-bottom: 12px;
}
#humai-hero p {
color: #cbd5e1;
font-size: 16px;
line-height: 1.7;
}
#signal-card {
border: 1px solid rgba(34, 211, 238, 0.24);
border-radius: 24px;
padding: 20px;
background: rgba(15, 23, 42, 0.82);
}
#signal-dot {
width: 74px;
height: 74px;
border-radius: 999px;
background: radial-gradient(circle, #67e8f9 0%, #0891b2 45%, rgba(8, 47, 73, 0.4) 100%);
box-shadow: 0 0 38px rgba(103, 232, 249, 0.72);
margin-bottom: 14px;
}
textarea, input, select {
border-radius: 16px !important;
}
button {
border-radius: 16px !important;
font-weight: 800 !important;
}
#footer-note {
color: #94a3b8;
font-size: 13px;
line-height: 1.7;
}
"""
with gr.Blocks(
title=APP_TITLE,
css=CUSTOM_CSS,
theme=gr.themes.Soft(
primary_hue="cyan",
secondary_hue="blue",
neutral_hue="slate",
),
) as demo:
gr.HTML(
f"""
<div id="humai-hero">
<p style="letter-spacing: 0.28em; text-transform: uppercase; color: #67e8f9; font-weight: 800;">
BPM RED Academy / HumAI Signal Layer
</p>
<h1>HumAI Signal Avatar Lab</h1>
<p>
Enterprise Human-AI dispatcher laboratory for Mission Control decisions,
urban mobility intelligence, startup support, public-system coordination
and governance-native AI workflows.
</p>
<p>
Live product interface:
<a href="{LIVE_PRODUCT_URL}" target="_blank" style="color:#67e8f9; font-weight:800;">
{LIVE_PRODUCT_URL}
</a>
</p>
</div>
"""
)
with gr.Row():
with gr.Column(scale=1):
gr.HTML(
"""
<div id="signal-card">
<div id="signal-dot"></div>
<p style="letter-spacing:0.24em; text-transform:uppercase; color:#67e8f9; font-weight:800;">
HumAI Dispatcher Online
</p>
<h2 style="margin-top:8px;">Receive. Structure. Transmit.</h2>
<p style="color:#cbd5e1; line-height:1.7;">
The avatar is the human interface to Mission Control.
It receives intent, asks clarifying questions, translates
context into structured decisions and explains the output
back to the user.
</p>
</div>
"""
)
domain_input = gr.Dropdown(
choices=list(DOMAINS.keys()),
value="Urban Mobility",
label="Domain",
)
mode_input = gr.Dropdown(
choices=list(MODES.keys()),
value="AI Dispatcher",
label="Use Case",
)
scenario_input = gr.Dropdown(
choices=list(SCENARIOS.keys()),
value="Sarajevo congestion after work hours",
label="Scenario",
)
priority_input = gr.Dropdown(
choices=PRIORITIES,
value="Speed",
label="Primary Priority",
)
user_context_input = gr.Textbox(
label="Optional User Context",
placeholder=(
"Example: I am near Marijin Dvor, I need to reach Ilidža, "
"traffic is heavy and I care about cost and time."
),
lines=5,
)
with gr.Row():
run_button = gr.Button(
"Run HumAI Signal Avatar",
variant="primary",
)
clear_button = gr.Button("Reset")
with gr.Column(scale=1):
avatar_output = gr.Markdown(
label="HumAI Signal Avatar",
value=(
"## HumAI Signal Avatar\n\n"
"**Status:** Waiting for input\n\n"
"Select a domain, use case and scenario, then run the dispatcher."
),
)
mission_output = gr.Markdown(
label="Mission Control Output",
value="Mission Control output will appear here.",
)
with gr.Accordion("Structured JSON