bpmredacademy commited on
Commit
e5f011e
·
verified ·
1 Parent(s): 240322d

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -721
app.py DELETED
@@ -1,721 +0,0 @@
1
- import gradio as gr
2
- from datetime import datetime
3
- import json
4
- import uuid
5
-
6
-
7
- APP_TITLE = "HumAI Signal Avatar Lab"
8
- APP_VERSION = "v0.1.0-enterprise-demo"
9
-
10
- LIVE_PRODUCT_URL = "https://humai-orchestration-makerfire.vercel.app"
11
-
12
- DOMAINS = {
13
- "Urban Mobility": "urban",
14
- "Startup Scaling": "startup",
15
- "Public Systems": "public",
16
- "Finance / Compliance": "finance",
17
- }
18
-
19
- MODES = {
20
- "Decision Support": "decision",
21
- "Risk Assessment": "risk",
22
- "Optimization": "optimization",
23
- "AI Dispatcher": "dispatch",
24
- }
25
-
26
- SCENARIOS = {
27
- "Sarajevo congestion after work hours": "congestion",
28
- "Startup funding and resource allocation": "funding",
29
- "Public service coordination under pressure": "service",
30
- "Financial risk and compliance review": "compliance",
31
- }
32
-
33
- PRIORITIES = [
34
- "Speed",
35
- "Cost",
36
- "Comfort",
37
- "Sustainability",
38
- "Safety",
39
- "Urgency",
40
- "Risk control",
41
- "Investor readiness",
42
- "Transparency",
43
- "Accountability",
44
- ]
45
-
46
-
47
- def normalize_selection(value, mapping, fallback):
48
- return mapping.get(value, fallback)
49
-
50
-
51
- def clamp(value, min_value=0.52, max_value=0.96):
52
- return max(min_value, min(max_value, value))
53
-
54
-
55
- def build_avatar_intro(domain_label, mode_label, scenario_label, priority):
56
- return (
57
- "HumAI Signal Avatar online.\n\n"
58
- f"I understand that you selected **{domain_label}** with **{mode_label}** "
59
- f"for the scenario **{scenario_label}**.\n\n"
60
- f"Your stated priority is **{priority}**. "
61
- "I will now translate this into a Mission Control decision structure."
62
- )
63
-
64
-
65
- def evaluate_mission_control(domain, mode, scenario, priority, user_context):
66
- risk = "MEDIUM"
67
- score = 0.72
68
-
69
- recommendation = (
70
- "Use structured Human-AI orchestration before taking operational action."
71
- )
72
-
73
- explanation = (
74
- "HumAI structures the situation, evaluates domain context and prepares "
75
- "a transparent recommendation for human review."
76
- )
77
-
78
- impact = (
79
- "Improves clarity, reduces decision friction and creates an auditable "
80
- "decision trail."
81
- )
82
-
83
- operator_note = (
84
- "Human review remains required before real-world operational execution."
85
- )
86
-
87
- next_best_action = (
88
- "Capture the context, review the recommendation and decide whether "
89
- "additional data or human escalation is needed."
90
- )
91
-
92
- why_this_matters = (
93
- "Unstructured decisions create confusion. HumAI turns fragmented context "
94
- "into a readable operational picture."
95
- )
96
-
97
- avatar_response = (
98
- "I can support this by asking clarifying questions, structuring the "
99
- "decision and translating the output into human-readable guidance."
100
- )
101
-
102
- demo_pitch_line = (
103
- "This shows how HumAI structures decisions instead of simply generating "
104
- "chatbot-style answers."
105
- )
106
-
107
- if domain == "urban":
108
- recommendation = (
109
- "Recommend the most realistic mobility option by balancing travel "
110
- "time, congestion pressure, user priority, cost and sustainability."
111
- )
112
- explanation = (
113
- "The system treats Sarajevo congestion as a mobility decision problem, "
114
- "not as a simple navigation question. It structures user context, "
115
- "priority and constraints before recommending action."
116
- )
117
- impact = (
118
- "Supports smarter urban movement, reduced congestion pressure and "
119
- "clearer citizen guidance."
120
- )
121
- operator_note = (
122
- "Best demonstrated as a Sarajevo AI mobility dispatcher scenario."
123
- )
124
- next_best_action = (
125
- "Ask the user whether speed, cost, comfort, safety or sustainability "
126
- "is the highest priority, then route the recommendation accordingly."
127
- )
128
- why_this_matters = (
129
- "Urban mobility decisions are usually made under pressure. A structured "
130
- "AI dispatcher can reduce uncertainty and help people choose better "
131
- "options in real time."
132
- )
133
- avatar_response = (
134
- "I will act as a Sarajevo mobility dispatcher. Before recommending a "
135
- "route or option, I need to understand whether your priority is speed, "
136
- "cost, comfort, safety or sustainability."
137
- )
138
- demo_pitch_line = (
139
- "In this scenario, HumAI becomes a Sarajevo mobility dispatcher: it "
140
- "receives user context, structures the mobility problem and returns "
141
- "an explainable recommendation."
142
- )
143
-
144
- if domain == "startup":
145
- recommendation = (
146
- "Prioritize resource allocation by separating urgent survival needs "
147
- "from strategic growth activities and investor-readiness work."
148
- )
149
- explanation = (
150
- "The system structures startup uncertainty into runway, traction, "
151
- "operational focus and investor narrative."
152
- )
153
- impact = (
154
- "Improves founder focus, reduces waste, strengthens fundraising "
155
- "preparation and helps the team communicate its operating logic."
156
- )
157
- operator_note = (
158
- "Best used to show how HumAI supports founders, accelerators, mentors "
159
- "and early-stage investors."
160
- )
161
- next_best_action = (
162
- "Identify current runway, strongest traction signal and highest-risk "
163
- "assumption before committing resources."
164
- )
165
- why_this_matters = (
166
- "Startups often fail because limited capital is spent without a clear "
167
- "operating logic. HumAI helps founders structure trade-offs before acting."
168
- )
169
- avatar_response = (
170
- "I will help structure this as a founder decision. We should clarify "
171
- "runway, traction, burn rate, investor readiness and the highest-risk "
172
- "assumption before taking action."
173
- )
174
- demo_pitch_line = (
175
- "In this scenario, HumAI helps a startup move from uncertainty to an "
176
- "investor-ready decision narrative."
177
- )
178
-
179
- if domain == "public":
180
- recommendation = (
181
- "Structure the operational picture, classify incoming requests, "
182
- "identify bottlenecks and route decisions to the responsible human operator."
183
- )
184
- explanation = (
185
- "The system supports public-service coordination without claiming "
186
- "autonomous authority."
187
- )
188
- impact = (
189
- "Improves transparency, accountability, response coordination and "
190
- "communication quality in public-facing workflows."
191
- )
192
- operator_note = (
193
- "Best used to demonstrate accountable public-system coordination."
194
- )
195
- next_best_action = (
196
- "Classify requests by urgency, public impact and responsible unit, "
197
- "then escalate only the cases requiring human authority."
198
- )
199
- why_this_matters = (
200
- "Public systems need clarity, traceability and accountability. HumAI "
201
- "can support decision preparation while keeping people responsible."
202
- )
203
- avatar_response = (
204
- "I will structure this as a public-system coordination case. The goal "
205
- "is to clarify urgency, responsible unit, public impact and review boundary."
206
- )
207
- demo_pitch_line = (
208
- "In this scenario, HumAI acts as a Mission Control layer for public "
209
- "service coordination, not as an autonomous authority."
210
- )
211
-
212
- if domain == "finance":
213
- recommendation = (
214
- "Classify risk, explain key indicators, preserve auditability and "
215
- "route the case toward human compliance review."
216
- )
217
- explanation = (
218
- "The system structures compliance reasoning into risk, explanation, "
219
- "traceability and human review."
220
- )
221
- impact = (
222
- "Supports structured compliance analysis, risk visibility, decision "
223
- "traceability and safer handling of sensitive financial or procurement cases."
224
- )
225
- operator_note = (
226
- "Best used to explain FinC2E-style governance logic as a future "
227
- "specialized module."
228
- )
229
- next_best_action = (
230
- "Separate factual indicators from assumptions, assign preliminary risk "
231
- "level and require human review before final disposition."
232
- )
233
- why_this_matters = (
234
- "Financial and compliance decisions require explainability. HumAI can "
235
- "help structure the case without replacing legal, financial or institutional authority."
236
- )
237
- avatar_response = (
238
- "I will structure this as a governance and compliance review. The goal "
239
- "is not autonomous enforcement, but explainable risk classification and "
240
- "human review."
241
- )
242
- demo_pitch_line = (
243
- "In this scenario, HumAI demonstrates how compliance reasoning can be "
244
- "structured, explainable and human-reviewed."
245
- )
246
-
247
- if mode == "risk":
248
- score += 0.08
249
- recommendation += " Risk controls and documented human review should be applied."
250
- next_best_action = (
251
- "Document the main risk drivers, identify missing information and route "
252
- "the case for responsible review."
253
- )
254
-
255
- if mode == "optimization":
256
- score -= 0.06
257
- recommendation += (
258
- " Optimization should focus on time, cost, operational load and "
259
- "measurable impact."
260
- )
261
- next_best_action = (
262
- "Compare the current process with the recommended action and remove "
263
- "the highest-friction step first."
264
- )
265
-
266
- if mode == "dispatch":
267
- score += 0.03
268
- recommendation += (
269
- " The recommendation should be delivered through a conversational "
270
- "dispatcher interface."
271
- )
272
- next_best_action = (
273
- "Convert the recommendation into a short, user-facing message that a "
274
- "conversational avatar or dispatcher can deliver clearly."
275
- )
276
-
277
- if scenario == "congestion":
278
- risk = "MEDIUM"
279
- score += 0.04
280
-
281
- if scenario == "funding":
282
- risk = "HIGH"
283
- score += 0.09
284
-
285
- if scenario == "service":
286
- risk = "MEDIUM"
287
- score += 0.02
288
-
289
- if scenario == "compliance":
290
- risk = "HIGH"
291
- score += 0.10
292
-
293
- priority_lower = priority.lower()
294
-
295
- if priority_lower in ["urgency", "risk control", "accountability"]:
296
- score += 0.03
297
-
298
- if priority_lower in ["sustainability", "transparency"]:
299
- impact += (
300
- " The selected priority also strengthens the case for transparent, "
301
- "responsible and socially useful decision support."
302
- )
303
-
304
- if user_context and len(user_context.strip()) > 0:
305
- explanation += (
306
- " The user-provided context was considered as an additional narrative "
307
- "signal for the dispatcher response."
308
- )
309
- avatar_response += (
310
- f"\n\nBased on your note, I would first clarify: "
311
- f"'{user_context.strip()[:180]}'"
312
- )
313
-
314
- score = clamp(score)
315
-
316
- if score >= 0.80:
317
- risk = "HIGH"
318
-
319
- if score >= 0.90:
320
- risk = "CRITICAL"
321
-
322
- decision = {
323
- "session_id": str(uuid.uuid4()),
324
- "timestamp": datetime.utcnow().isoformat() + "Z",
325
- "engine": "HumAI Signal Avatar Lab",
326
- "version": APP_VERSION,
327
- "execution_mode": "deterministic_enterprise_fallback",
328
- "ai_assisted": False,
329
- "domain": domain,
330
- "mode": mode,
331
- "scenario": scenario,
332
- "priority": priority,
333
- "risk": risk,
334
- "confidence": round(score, 2),
335
- "human_review_required": True,
336
- "recommendation": recommendation,
337
- "explanation": explanation,
338
- "impact": impact,
339
- "operator_note": operator_note,
340
- "next_best_action": next_best_action,
341
- "why_this_matters": why_this_matters,
342
- "avatar_response": avatar_response,
343
- "demo_pitch_line": demo_pitch_line,
344
- "product_boundary": (
345
- "This is a public AI dispatcher laboratory and deterministic "
346
- "demonstrator. It is not a certified production mobility, compliance "
347
- "or public-authority system."
348
- ),
349
- }
350
-
351
- return decision
352
-
353
-
354
- def render_markdown_output(decision):
355
- risk = decision["risk"]
356
- confidence = int(decision["confidence"] * 100)
357
-
358
- return f"""
359
- # HumAI Mission Control Output
360
-
361
- **Execution Mode:** `{decision["execution_mode"]}`
362
- **Domain:** `{decision["domain"]}`
363
- **Use Case:** `{decision["mode"]}`
364
- **Scenario:** `{decision["scenario"]}`
365
- **Priority:** `{decision["priority"]}`
366
-
367
- ---
368
-
369
- ## Risk & Confidence
370
-
371
- **Risk Level:** `{risk}`
372
- **Confidence:** `{confidence}%`
373
- **Human Review Required:** `YES`
374
-
375
- ---
376
-
377
- ## Recommended Action
378
-
379
- {decision["recommendation"]}
380
-
381
- ---
382
-
383
- ## Explanation
384
-
385
- {decision["explanation"]}
386
-
387
- ---
388
-
389
- ## Avatar Dispatcher Response
390
-
391
- {decision["avatar_response"]}
392
-
393
- ---
394
-
395
- ## Next Best Action
396
-
397
- {decision["next_best_action"]}
398
-
399
- ---
400
-
401
- ## Why This Matters
402
-
403
- {decision["why_this_matters"]}
404
-
405
- ---
406
-
407
- ## Impact
408
-
409
- {decision["impact"]}
410
-
411
- ---
412
-
413
- ## Operator Note
414
-
415
- {decision["operator_note"]}
416
-
417
- ---
418
-
419
- ## Demo Pitch Line
420
-
421
- > {decision["demo_pitch_line"]}
422
-
423
- ---
424
-
425
- ## Product Boundary
426
-
427
- {decision["product_boundary"]}
428
- """
429
-
430
-
431
- def run_humai_avatar(
432
- domain_label,
433
- mode_label,
434
- scenario_label,
435
- priority,
436
- user_context,
437
- ):
438
- domain = normalize_selection(domain_label, DOMAINS, "urban")
439
- mode = normalize_selection(mode_label, MODES, "decision")
440
- scenario = normalize_selection(scenario_label, SCENARIOS, "congestion")
441
-
442
- avatar_intro = build_avatar_intro(
443
- domain_label=domain_label,
444
- mode_label=mode_label,
445
- scenario_label=scenario_label,
446
- priority=priority,
447
- )
448
-
449
- decision = evaluate_mission_control(
450
- domain=domain,
451
- mode=mode,
452
- scenario=scenario,
453
- priority=priority,
454
- user_context=user_context,
455
- )
456
-
457
- markdown_output = render_markdown_output(decision)
458
- json_output = json.dumps(decision, indent=2, ensure_ascii=False)
459
-
460
- avatar_panel = f"""
461
- ## HumAI Signal Avatar
462
-
463
- **Status:** Online
464
- **Role:** Conversational AI Dispatcher
465
- **Current priority:** {priority}
466
-
467
- {avatar_intro}
468
-
469
- ---
470
-
471
- ### Next Question
472
-
473
- **What matters most right now — speed, cost, comfort, safety, sustainability, urgency, transparency or risk control?**
474
-
475
- The answer changes how Mission Control should prioritize the recommendation.
476
- """
477
-
478
- return avatar_panel, markdown_output, json_output
479
-
480
-
481
- def clear_inputs():
482
- return (
483
- "Urban Mobility",
484
- "AI Dispatcher",
485
- "Sarajevo congestion after work hours",
486
- "Speed",
487
- "",
488
- "",
489
- "",
490
- "",
491
- )
492
-
493
-
494
- CUSTOM_CSS = """
495
- .gradio-container {
496
- background: radial-gradient(circle at top left, rgba(34, 211, 238, 0.16), transparent 28%),
497
- radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.16), transparent 30%),
498
- #020617 !important;
499
- color: #e2e8f0 !important;
500
- }
501
-
502
- #humai-hero {
503
- border: 1px solid rgba(34, 211, 238, 0.28);
504
- border-radius: 28px;
505
- padding: 28px;
506
- background: linear-gradient(135deg, rgba(8, 47, 73, 0.78), rgba(15, 23, 42, 0.94));
507
- box-shadow: 0 22px 80px rgba(8, 145, 178, 0.16);
508
- }
509
-
510
- #humai-hero h1 {
511
- font-size: 42px;
512
- line-height: 1.05;
513
- margin-bottom: 12px;
514
- }
515
-
516
- #humai-hero p {
517
- color: #cbd5e1;
518
- font-size: 16px;
519
- line-height: 1.7;
520
- }
521
-
522
- #signal-card {
523
- border: 1px solid rgba(34, 211, 238, 0.24);
524
- border-radius: 24px;
525
- padding: 20px;
526
- background: rgba(15, 23, 42, 0.82);
527
- }
528
-
529
- #signal-dot {
530
- width: 74px;
531
- height: 74px;
532
- border-radius: 999px;
533
- background: radial-gradient(circle, #67e8f9 0%, #0891b2 45%, rgba(8, 47, 73, 0.4) 100%);
534
- box-shadow: 0 0 38px rgba(103, 232, 249, 0.72);
535
- margin-bottom: 14px;
536
- }
537
-
538
- textarea, input, select {
539
- border-radius: 16px !important;
540
- }
541
-
542
- button {
543
- border-radius: 16px !important;
544
- font-weight: 800 !important;
545
- }
546
-
547
- #footer-note {
548
- color: #94a3b8;
549
- font-size: 13px;
550
- line-height: 1.7;
551
- }
552
- """
553
-
554
-
555
- with gr.Blocks(
556
- title=APP_TITLE,
557
- css=CUSTOM_CSS,
558
- theme=gr.themes.Soft(
559
- primary_hue="cyan",
560
- secondary_hue="blue",
561
- neutral_hue="slate",
562
- ),
563
- ) as demo:
564
- gr.HTML(
565
- f"""
566
- <div id="humai-hero">
567
- <p style="letter-spacing: 0.28em; text-transform: uppercase; color: #67e8f9; font-weight: 800;">
568
- BPM RED Academy / HumAI Signal Layer
569
- </p>
570
- <h1>HumAI Signal Avatar Lab</h1>
571
- <p>
572
- Enterprise Human-AI dispatcher laboratory for Mission Control decisions,
573
- urban mobility intelligence, startup support, public-system coordination
574
- and governance-native AI workflows.
575
- </p>
576
- <p>
577
- Live product interface:
578
- <a href="{LIVE_PRODUCT_URL}" target="_blank" style="color:#67e8f9; font-weight:800;">
579
- {LIVE_PRODUCT_URL}
580
- </a>
581
- </p>
582
- </div>
583
- """
584
- )
585
-
586
- with gr.Row():
587
- with gr.Column(scale=1):
588
- gr.HTML(
589
- """
590
- <div id="signal-card">
591
- <div id="signal-dot"></div>
592
- <p style="letter-spacing:0.24em; text-transform:uppercase; color:#67e8f9; font-weight:800;">
593
- HumAI Dispatcher Online
594
- </p>
595
- <h2 style="margin-top:8px;">Receive. Structure. Transmit.</h2>
596
- <p style="color:#cbd5e1; line-height:1.7;">
597
- The avatar is the human interface to Mission Control.
598
- It receives intent, asks clarifying questions, translates
599
- context into structured decisions and explains the output
600
- back to the user.
601
- </p>
602
- </div>
603
- """
604
- )
605
-
606
- domain_input = gr.Dropdown(
607
- choices=list(DOMAINS.keys()),
608
- value="Urban Mobility",
609
- label="Domain",
610
- )
611
-
612
- mode_input = gr.Dropdown(
613
- choices=list(MODES.keys()),
614
- value="AI Dispatcher",
615
- label="Use Case",
616
- )
617
-
618
- scenario_input = gr.Dropdown(
619
- choices=list(SCENARIOS.keys()),
620
- value="Sarajevo congestion after work hours",
621
- label="Scenario",
622
- )
623
-
624
- priority_input = gr.Dropdown(
625
- choices=PRIORITIES,
626
- value="Speed",
627
- label="Primary Priority",
628
- )
629
-
630
- user_context_input = gr.Textbox(
631
- label="Optional User Context",
632
- placeholder=(
633
- "Example: I am near Marijin Dvor, I need to reach Ilidža, "
634
- "traffic is heavy and I care about cost and time."
635
- ),
636
- lines=5,
637
- )
638
-
639
- with gr.Row():
640
- run_button = gr.Button(
641
- "Run HumAI Signal Avatar",
642
- variant="primary",
643
- )
644
- clear_button = gr.Button("Reset")
645
-
646
- with gr.Column(scale=1):
647
- avatar_output = gr.Markdown(
648
- label="HumAI Signal Avatar",
649
- value=(
650
- "## HumAI Signal Avatar\n\n"
651
- "**Status:** Waiting for input\n\n"
652
- "Select a domain, use case and scenario, then run the dispatcher."
653
- ),
654
- )
655
-
656
- mission_output = gr.Markdown(
657
- label="Mission Control Output",
658
- value="Mission Control output will appear here.",
659
- )
660
-
661
- with gr.Accordion("Structured JSON Output", open=False):
662
- json_output = gr.Code(
663
- label="Mission Control JSON",
664
- language="json",
665
- value="{}",
666
- )
667
-
668
- gr.HTML(
669
- """
670
- <div id="footer-note">
671
- <p>
672
- <strong>Public demonstrator note:</strong>
673
- This Hugging Face Space currently runs as a deterministic enterprise
674
- avatar laboratory. It is designed for demo safety, explainability and
675
- future integration with Gemini / Vertex AI, Firebase, Google Maps,
676
- Azure AI Foundry, Hugging Face model artifacts, NVIDIA-oriented
677
- inference infrastructure and PitchAvatar or custom avatar layers.
678
- </p>
679
- <p>
680
- Product boundary: HumAI is advisory, human-in-the-loop and
681
- demonstration-oriented in this version. It does not replace human
682
- judgment, public authority, legal review or operational command.
683
- </p>
684
- </div>
685
- """
686
- )
687
-
688
- run_button.click(
689
- fn=run_humai_avatar,
690
- inputs=[
691
- domain_input,
692
- mode_input,
693
- scenario_input,
694
- priority_input,
695
- user_context_input,
696
- ],
697
- outputs=[
698
- avatar_output,
699
- mission_output,
700
- json_output,
701
- ],
702
- )
703
-
704
- clear_button.click(
705
- fn=clear_inputs,
706
- inputs=[],
707
- outputs=[
708
- domain_input,
709
- mode_input,
710
- scenario_input,
711
- priority_input,
712
- user_context_input,
713
- avatar_output,
714
- mission_output,
715
- json_output,
716
- ],
717
- )
718
-
719
-
720
- if __name__ == "__main__":
721
- demo.launch()