import requests import os import gradio as gr from datetime import datetime import json import uuid APP_TITLE = "HumAI Midfielder Avatar" APP_VERSION = "v0.2.0-enterprise-demo" INFERENCE_URL = os.getenv("INFERENCE_URL", "") INFERENCE_API_KEY = os.getenv("INFERENCE_API_KEY", "") LIVE_PRODUCT_URL = "https://humai-orchestration-makerfire.vercel.app" BRAND_LAYER = "BPM RED Academy / MightHub HumAI Layer" PRODUCT_NAME = "HumAI Midfielder Avatar" DOA_NAME = "MightHub DOA" DOA_FULL_NAME = "MightHub DOA — Duty Officer Avatar" 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", "Duty Officer Support": "duty", } 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", "Operational continuity", "Human review", ] 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 call_real_inference(prompt): if not INFERENCE_URL: return { "success": False, "fallback": True, "content": "Inference endpoint not configured." } headers = { "Authorization": f"Bearer {INFERENCE_API_KEY}", "Content-Type": "application/json" } payload = { "model": "FinC2E", "messages": [ { "role": "system", "content": "You are FinC2E governance runtime." }, { "role": "user", "content": prompt } ], "temperature": 0.1, "max_tokens": 400 } try: response = requests.post( INFERENCE_URL, headers=headers, json=payload, timeout=60 ) data = response.json() content = ( data.get("choices", [{}])[0] .get("message", {}) .get("content", "") ) return { "success": True, "fallback": False, "content": content, "raw": data } except Exception as e: return { "success": False, "fallback": True, "content": str(e) } def build_avatar_intro(domain_label, mode_label, scenario_label, priority): return ( f"{PRODUCT_NAME} online.\n\n" f"**{DOA_FULL_NAME}** is active as the human-facing dispatcher layer of MightHub.\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 receive the intent, read the operational situation, route it through " "Mission Control, and return explainable decision support." ) def evaluate_mission_control(domain, mode, scenario, priority, user_context): risk = "MEDIUM" score = 0.72 real_runtime = call_real_inference(user_context) 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. MightHub turns fragmented context into " "a readable operational picture." ) avatar_response = ( "I can support this as the Duty Officer Avatar by asking clarifying questions, " "structuring the decision and translating the output into human-readable guidance." ) demo_pitch_line = ( "This shows how HumAI Midfielder Avatar routes human intent into MightHub " "Mission Control instead of simply generating chatbot-style answers." ) duty_officer_assessment = ( "Initial watch-floor assessment: the situation is suitable for structured decision " "support with human review before action." ) 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 Duty Officer Avatar. Before recommending a route " "or option, I need to understand whether your priority is speed, cost, comfort, safety " "or sustainability." ) duty_officer_assessment = ( "Mobility watch assessment: the user requires route-oriented guidance, but the " "recommendation should remain explainable and priority-aware." ) demo_pitch_line = ( "In this scenario, HumAI Midfielder Avatar becomes a Sarajevo mobility dispatcher: " "it receives user context, reads the mobility field and routes an explainable " "recommendation through MightHub Mission Control." ) 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." ) duty_officer_assessment = ( "Startup watch assessment: the critical question is whether the team should protect " "runway, accelerate traction or prepare investor-facing evidence." ) demo_pitch_line = ( "In this scenario, HumAI Midfielder Avatar 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." 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." ) duty_officer_assessment = ( "Public systems watch assessment: preserve accountability, classify requests and route " "only authority-dependent cases to human decision-makers." ) demo_pitch_line = ( "In this scenario, HumAI Midfielder Avatar acts as a Duty Officer 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." ) duty_officer_assessment = ( "Compliance watch assessment: maintain advisory-only boundaries, preserve auditability " "and route final disposition to human review." ) demo_pitch_line = ( "In this scenario, HumAI Midfielder Avatar 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 mode == "duty": score += 0.05 recommendation += ( " The Duty Officer Avatar should maintain the operational picture, ask clarifying questions " "and route the case to the correct decision boundary." ) next_best_action = ( "Summarize the situation, identify the missing field information, and route the case to " "the responsible human decision point." ) 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", "operational continuity", "human review"]: score += 0.03 if priority_lower in ["sustainability", "transparency", "accountability"]: impact += " The selected priority also strengthens 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: '{user_context.strip()[:180]}'" score = clamp(score) if score >= 0.80: risk = "HIGH" if score >= 0.90: risk = "CRITICAL" return { "session_id": str(uuid.uuid4()), "timestamp": datetime.utcnow().isoformat() + "Z", "engine": PRODUCT_NAME, "doa_layer": DOA_FULL_NAME, "version": APP_VERSION, "execution_mode": "deterministic_enterprise_fallback", "ai_assisted": real_runtime["success"], "inference_fallback": real_runtime["fallback"], "runtime_output": real_runtime["content"], "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, "duty_officer_assessment": duty_officer_assessment, "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 MightHub DOA laboratory and deterministic demonstrator. " "It is not a certified production mobility, compliance or public-authority system." ), } def render_markdown_output(decision): confidence = int(decision["confidence"] * 100) return f""" # MightHub Mission Control Output **Engine:** `{decision["engine"]}` **DOA Layer:** `{decision["doa_layer"]}` **Execution Mode:** `{decision["execution_mode"]}` **Domain:** `{decision["domain"]}` **Use Case:** `{decision["mode"]}` **Scenario:** `{decision["scenario"]}` **Priority:** `{decision["priority"]}` --- ## Risk & Confidence **Risk Level:** `{decision["risk"]}` **Confidence:** `{confidence}%` **Human Review Required:** `YES` --- ## Duty Officer Assessment {decision["duty_officer_assessment"]} --- ## 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, "dispatch") scenario = normalize_selection(scenario_label, SCENARIOS, "congestion") avatar_intro = build_avatar_intro(domain_label, mode_label, scenario_label, priority) decision = evaluate_mission_control(domain, mode, scenario, priority, user_context) avatar_panel = f""" ## {PRODUCT_NAME} **Status:** Online **Role:** {DOA_FULL_NAME} **Current priority:** {priority} {avatar_intro} --- ### Midfielder Doctrine **Receive the intent. Read the field. Route the context. Support the human decision.** --- ### Next Question **What matters most right now — speed, cost, comfort, safety, sustainability, urgency, operational continuity, transparency or risk control?** The answer changes how MightHub Mission Control should prioritize the recommendation. """ return avatar_panel, render_markdown_output(decision), json.dumps(decision, indent=2, ensure_ascii=False) def clear_inputs(): return ( "Urban Mobility", "AI Dispatcher", "Sarajevo congestion after work hours", "Speed", "", f"## {PRODUCT_NAME}\n\n**Status:** Waiting for input\n\n**Role:** {DOA_FULL_NAME}\n\nSelect a domain, use case and scenario, then run the dispatcher.", "Mission Control output will appear here.", "{}", ) 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(139, 92, 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; } #doa-badge { display: inline-block; padding: 8px 12px; border-radius: 999px; border: 1px solid rgba(167, 139, 250, 0.45); background: rgba(91, 33, 182, 0.24); color: #ddd6fe; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; font-size: 12px; margin-bottom: 12px; } 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="violet", neutral_hue="slate"), ) as demo: gr.HTML( f"""
{BRAND_LAYER}
MightHub Human-AI dispatcher layer for Mission Control decisions, urban mobility intelligence, startup support, public-system coordination and governance-native AI workflows.
Operating doctrine: Receive the intent. Read the field. Route the context. Support the human decision.
Live product interface: {LIVE_PRODUCT_URL}
HumAI Midfielder Online
The Midfielder Avatar is the human interface to MightHub Mission Control. It receives intent, reads the situation, routes context into structured decisions and explains the output back to the user.
{DOA_FULL_NAME}
MightHub DOA System Card
MightHub DOA is designed as a human-facing dispatcher layer. It receives intent, reads the operational field, routes context into Mission Control and returns explainable decision support.
What it does
What it does not do
Current mode
Future integrations