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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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