File size: 27,457 Bytes
ed1bd98
 
5037407
 
 
 
 
 
 
ed1bd98
 
5037407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c1f8bb
ed1bd98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5037407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed1bd98
5037407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed1bd98
 
 
5037407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54babe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0b8ed4
 
5037407
a0b8ed4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5037407
 
a0b8ed4
5037407
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
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"""
        <div id="humai-hero">
            <p style="letter-spacing: 0.28em; text-transform: uppercase; color: #67e8f9; font-weight: 800;">{BRAND_LAYER}</p>
            <div id="doa-badge">{DOA_NAME} / Duty Officer Avatar</div>
            <h1>{PRODUCT_NAME}</h1>
            <p>MightHub Human-AI dispatcher layer for Mission Control decisions, urban mobility intelligence, startup support, public-system coordination and governance-native AI workflows.</p>
            <p><strong>Operating doctrine:</strong> Receive the intent. Read the field. Route the context. Support the human decision.</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(
                f"""
                <div id="signal-card">
                    <div id="signal-dot"></div>
                    <p style="letter-spacing:0.24em; text-transform:uppercase; color:#67e8f9; font-weight:800;">HumAI Midfielder Online</p>
                    <h2 style="margin-top:8px;">Receive. Read. Route.</h2>
                    <p style="color:#cbd5e1; line-height:1.7;">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.</p>
                    <p style="color:#ddd6fe; line-height:1.7; font-weight:700;">{DOA_FULL_NAME}</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 MightHub DOA", variant="primary")
                clear_button = gr.Button("Reset")

        with gr.Column(scale=1):
            avatar_output = gr.Markdown(
                label=PRODUCT_NAME,
                value=(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_output = gr.Markdown(label="MightHub Mission Control Output", value="Mission Control output will appear here.")

    with gr.Accordion("Structured JSON Output", open=False):
        json_output = gr.Code(label="Mission Control JSON", language="json", value="{}")

    gr.HTML(
        """
        <div id="humai-hero" style="margin-top: 24px;">
            <p style="letter-spacing: 0.28em; text-transform: uppercase; color: #a78bfa; font-weight: 800;">
                MightHub DOA System Card
            </p>

            <h2 style="font-size: 32px; line-height: 1.12; margin-bottom: 16px;">
                Duty Officer Avatar — Operational Boundary
            </h2>

            <p>
                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.
            </p>

            <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 22px;">
                <div id="signal-card">
                    <p style="letter-spacing:0.18em; text-transform:uppercase; color:#67e8f9; font-weight:800;">
                        What it does
                    </p>
                    <ul style="color:#cbd5e1; line-height:1.8;">
                        <li>Receives user intent</li>
                        <li>Reads domain and scenario context</li>
                        <li>Routes input into Mission Control</li>
                        <li>Produces structured recommendations</li>
                        <li>Explains next best action</li>
                    </ul>
                </div>

                <div id="signal-card">
                    <p style="letter-spacing:0.18em; text-transform:uppercase; color:#fbbf24; font-weight:800;">
                        What it does not do
                    </p>
                    <ul style="color:#cbd5e1; line-height:1.8;">
                        <li>Does not replace human judgment</li>
                        <li>Does not act autonomously</li>
                        <li>Does not issue public-authority decisions</li>
                        <li>Does not perform certified compliance review</li>
                        <li>Does not command real-world operations</li>
                    </ul>
                </div>

                <div id="signal-card">
                    <p style="letter-spacing:0.18em; text-transform:uppercase; color:#34d399; font-weight:800;">
                        Current mode
                    </p>
                    <ul style="color:#cbd5e1; line-height:1.8;">
                        <li>Deterministic enterprise fallback</li>
                        <li>Demo-safe behavior</li>
                        <li>Structured JSON output</li>
                        <li>Human review required</li>
                        <li>Public demonstrator boundary</li>
                    </ul>
                </div>

                <div id="signal-card">
                    <p style="letter-spacing:0.18em; text-transform:uppercase; color:#c084fc; font-weight:800;">
                        Future integrations
                    </p>
                    <ul style="color:#cbd5e1; line-height:1.8;">
                        <li>Gemini / Vertex AI reasoning</li>
                        <li>Firebase session memory</li>
                        <li>Google Maps mobility context</li>
                        <li>Azure AI Foundry evaluation</li>
                        <li>PitchAvatar or custom avatar layer</li>
                    </ul>
                </div>
            </div>
        </div>
        """
    )
gr.HTML(
        """
        <div id="footer-note">
            <p>
                <strong>Public demonstrator note:</strong>
                This Hugging Face Space currently runs as a deterministic enterprise
                MightHub DOA laboratory. It is designed for demo safety, explainability
                and future integration with Gemini / Vertex AI, Firebase, Google Maps,
                Azure AI Foundry, Hugging Face model artifacts, NVIDIA-oriented
                inference infrastructure and PitchAvatar or custom avatar layers.
            </p>

            <p>
                <strong>Product boundary:</strong>
                HumAI is advisory, human-in-the-loop and demonstration-oriented in this version.
                It does not replace human judgment, public authority, legal review or
                operational command.
            </p>
        </div>
        """
)


if __name__ == "__main__":
    demo.launch()