Arghadee commited on
Commit
3a4f128
ยท
verified ยท
1 Parent(s): 348780e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -109
app.py CHANGED
@@ -6,9 +6,33 @@ import matplotlib.pyplot as plt
6
  import matplotlib.patches as mpatches
7
  import numpy as np
8
  from datetime import datetime
9
- from flask import Flask, request, jsonify
10
- from environment import CloudCostEnv # Assuming your environment.py has this class
11
- import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
14
  # COLOR SYSTEM
@@ -279,7 +303,7 @@ XAI = {
279
  }
280
 
281
  def get_decision(user_load, spot_avail, chaos_monkey, budget_on, latency):
282
- if chaos_monkey and latency > 120: key = "chaos_resp"
283
  elif user_load > 80 and latency > 80: key = "scale_up"
284
  elif user_load < 35: key = "scale_down"
285
  elif budget_on and spot_avail > 50: key = "spot_switch"
@@ -296,7 +320,7 @@ def health_badge(latency, load, drisk):
296
  return "๐ŸŸข HEALTHY โ€” All Systems Nominal", "green"
297
 
298
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
299
- # MAIN SIMULATION โ€” returns exactly 23 values, matching outputs
300
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
301
  _tick = 0
302
 
@@ -323,48 +347,21 @@ def run_simulation(scenario, user_load, spot_avail,
323
  user_load, spot_avail, chaos_monkey, budget_on, latency)
324
  health_txt, _ = health_badge(latency, load, drisk)
325
 
326
- decision_md = f"""### ๐Ÿง  AI Decision
327
- **โ†’ {action}**
328
-
329
- | | |
330
- |---|---|
331
- | Confidence | `{conf}%` |
332
- | Reason | {reason} |
333
- | Scenario | {scenario.split(':')[0]} |
334
- | Time | `{t}` |
335
- """
336
- xai_md = "### ๐Ÿ’ก Why did AI decide this?\n" + "".join(f"- โœ” {r}\n" for r in xai)
337
- health_md = f"""### {health_txt}
338
-
339
- | Metric | Value |
340
- |---|---|
341
- | Latency | `{latency} ms` |
342
- | Load | `{load} req/s` |
343
- | Downtime risk | `{drisk}` |
344
- | Agent score | `{score} / 1.0` |
345
- """
346
- pred_cost = round(burn * (user_load / 48), 2)
347
- pred_lat = round(latency * (user_load / 58), 1)
348
- risk_lbl = ("๐Ÿ”ด HIGH" if pred_lat > 100 or pred_cost > 0.65
349
- else "๐ŸŸก MEDIUM" if pred_lat > 60
350
- else "๐ŸŸข LOW")
351
- whatif_md = f"""### ๐Ÿ”ฎ What-If Simulation
352
- *If Load = {int(user_load)}% continues...*
353
-
354
- | Prediction | Value |
355
- |---|---|
356
- | Predicted cost | `${pred_cost}/hr` |
357
- | Predicted latency | `{pred_lat} ms` |
358
- | Risk level | {risk_lbl} |
359
- | Estimated savings | `{savings}` |
360
- """
361
  log = f"[{t}] {scenario}\n"
362
  log += f"[{t}] Load: {load} req/s | Servers: {servers} | Burn: ${burn}/hr\n"
363
  log += f"[{t}] Latency: {latency} ms | Risk: {drisk}\n"
364
  log += f"[{t}] DECISION: {action} (conf {conf}%)\n"
365
  log += f"[{t}] Score: {score} / 1.0 | Savings: {savings}"
366
 
367
- # โ”€โ”€ charts โ”€โ”€
368
  gauge_fig = make_gauge_chart(int(user_load), "User Load", C["cyan"], seed)
369
  burst_fig = make_radial_burst(load, "req/s", C["purple"], seed)
370
  burst2_fig = make_radial_burst(int(score*100), "Scoreร—100", C["green"], seed+1)
@@ -376,40 +373,37 @@ def run_simulation(scenario, user_load, spot_avail,
376
  before_fig = make_before_after(auto_scaling)
377
  whatif_fig = make_whatif(int(user_load), int(spot_avail))
378
 
379
- # โ”€โ”€ 23 return values โ€” perfectly matches outputs list below โ”€โ”€
380
  return (
381
- f"๐Ÿš€ {load} req/s", # load_out
382
- f"๐Ÿ–ฅ๏ธ {servers} instances", # server_out
383
- f"๐Ÿ’ธ ${burn}/hr", # burn_out
384
- f"โšก {latency} ms", # latency_out
385
- f"๐Ÿ’ฐ {savings} saved", # savings_out
386
- f"๐Ÿ† {score} / 1.0", # score_out
387
- decision_md, # decision_out
388
- xai_md, # xai_out
389
- health_md, # health_out
390
- whatif_md, # whatif_out
391
- log, # log_out
392
- spend_str, # spend_out2
393
- drisk, # risk_out
394
- score, # score_num โ† raw float, fixes the Error bug
395
- gauge_fig, # gauge_plot
396
- burst_fig, # burst_plot
397
- burst2_fig, # burst2_plot
398
- area_fig, # area_plot
399
- bar_fig, # bar_plot
400
- wave_fig, # wave_plot
401
- lat_fig, # lat_plot
402
- reward_fig, # reward_plot
403
- before_fig, # before_plot
404
- whatif_fig, # whatif_plot โ† 24 total
405
  )
406
 
407
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
408
  # CSS
409
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
410
  CSS = """
411
- @import url('https://fonts.googleapis.com/css2?family=Space+Mono&family=Inter:wght@400;600;700;800&display=swap');
412
-
413
  body, .gradio-container {
414
  background: #06091a !important;
415
  color: #e2eeff !important;
@@ -419,55 +413,28 @@ body, .gradio-container {
419
  background: rgba(11,17,32,0.85) !important;
420
  border: 0.5px solid #1e3a5f !important;
421
  border-radius: 14px !important;
422
- backdrop-filter: blur(12px) !important;
423
  }
424
  .hero-metric textarea, .hero-metric input {
425
  font-size: 22px !important; font-weight: 800 !important;
426
  color: #00e5ff !important; text-align: center !important;
427
- background: rgba(0,229,255,0.06) !important;
428
- border: 1px solid rgba(0,229,255,0.25) !important;
429
- border-radius: 12px !important; padding: 18px 10px !important;
430
- }
431
- .sec-metric textarea, .sec-metric input {
432
- font-size: 17px !important; font-weight: 700 !important;
433
- color: #a78bfa !important; text-align: center !important;
434
- background: rgba(167,139,250,0.06) !important;
435
- border: 0.5px solid rgba(167,139,250,0.22) !important;
436
- border-radius: 10px !important; padding: 12px 8px !important;
437
  }
438
  .card-decision { background: rgba(255,61,90,0.07) !important; border: 1px solid rgba(255,61,90,0.35) !important; border-radius: 14px !important; padding: 6px 10px !important; }
439
- .card-decision h3 { color: #ff3d5a !important; }
440
  .card-xai { background: rgba(0,229,255,0.05) !important; border: 1px solid rgba(0,229,255,0.25) !important; border-radius: 14px !important; padding: 6px 10px !important; }
441
- .card-xai h3 { color: #00e5ff !important; }
442
  .card-health { background: rgba(0,255,157,0.06) !important; border: 1px solid rgba(0,255,157,0.28) !important; border-radius: 14px !important; padding: 6px 10px !important; }
443
- .card-health h3 { color: #00ff9d !important; }
444
  .card-whatif { background: rgba(192,132,252,0.06) !important; border: 1px solid rgba(192,132,252,0.28) !important; border-radius: 14px !important; padding: 6px 10px !important; }
445
- .card-whatif h3 { color: #c084fc !important; }
446
  .gr-button-primary {
447
  background: linear-gradient(135deg, rgba(0,229,255,0.15), rgba(0,255,157,0.10)) !important;
448
  border: 1.5px solid #00e5ff !important; color: #00e5ff !important;
449
  font-size: 15px !important; font-weight: 700 !important;
450
- letter-spacing: 2px !important; border-radius: 12px !important;
451
- padding: 14px 0 !important; text-transform: uppercase !important;
452
  }
453
- .gr-button-primary:hover { background: rgba(0,229,255,0.22) !important; border-color: #00ff9d !important; color: #00ff9d !important; }
454
- label, .gr-input-label { color: #4a6080 !important; font-size: 11px !important; letter-spacing: 1.5px !important; text-transform: uppercase !important; }
455
- input, select, textarea { background: #0a1020 !important; color: #e2eeff !important; border: 0.5px solid #1e3a5f !important; border-radius: 8px !important; font-family: 'Inter', sans-serif !important; }
456
- .log-panel textarea { font-family: 'Space Mono', monospace !important; font-size: 11.5px !important; color: #7ab0d0 !important; background: #050810 !important; border: 0.5px solid #1e3a5f !important; border-radius: 10px !important; line-height: 1.9 !important; }
457
- .score-box input { font-size: 30px !important; font-weight: 900 !important; color: #00ff9d !important; text-align: center !important; background: rgba(0,255,157,0.07) !important; border: 1px solid rgba(0,255,157,0.30) !important; border-radius: 12px !important; }
458
- .gr-plot { background: rgba(11,17,32,0.90) !important; border: 0.5px solid #1e3a5f !important; border-radius: 12px !important; padding: 6px !important; }
459
- .gr-markdown table { font-size: 13px !important; width: 100% !important; }
460
- .gr-markdown td, .gr-markdown th { padding: 5px 8px !important; border-color: #1e3a5f !important; }
461
- .gr-markdown h3 { font-size: 14px !important; margin-bottom: 8px !important; }
462
- .gr-markdown code { background: rgba(0,229,255,0.10) !important; color: #00e5ff !important; border-radius: 4px !important; padding: 1px 6px !important; font-family: 'Space Mono', monospace !important; font-size: 12px !important; }
463
- hr { border-color: #1e3a5f !important; margin: 14px 0 !important; }
464
- .gr-markdown h2 { color: #00e5ff !important; letter-spacing: 1px !important; border-bottom: 1px solid #1e3a5f !important; padding-bottom: 6px !important; }
465
  """
466
 
467
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
468
- # UI
469
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
470
- with gr.Blocks(css=CSS, title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
471
 
472
  gr.Markdown("# โ˜๏ธ Cloud-Cost Guardian AI\n#### RL-Powered Autonomous Infrastructure โ€” Live Intelligence Dashboard\n---")
473
 
@@ -478,9 +445,9 @@ with gr.Blocks(css=CSS, title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
478
  score_out = gr.Textbox(label="๐Ÿ† Agent Score", interactive=False, elem_classes="hero-metric")
479
 
480
  with gr.Row(equal_height=True):
481
- server_out = gr.Textbox(label="๐Ÿ–ฅ๏ธ Servers", interactive=False, elem_classes="sec-metric")
482
- burn_out = gr.Textbox(label="๐Ÿ’ธ Burn Rate", interactive=False, elem_classes="sec-metric")
483
- latency_out = gr.Textbox(label="โšก Latency", interactive=False, elem_classes="sec-metric")
484
 
485
  gr.Markdown("---")
486
 
@@ -504,7 +471,7 @@ with gr.Blocks(css=CSS, title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
504
  xai_out = gr.Markdown("### ๐Ÿ’ก Explainable AI\n*Waiting...*", elem_classes="card-xai")
505
 
506
  with gr.Column(scale=1, min_width=260):
507
- health_out = gr.Markdown("### ๐ŸŸข Health Status\n*Click Run...*", elem_classes="card-health")
508
  whatif_out = gr.Markdown("### ๐Ÿ”ฎ What-If Simulation\n*Adjust sliders...*",elem_classes="card-whatif")
509
 
510
  gr.Markdown("---")
@@ -513,9 +480,9 @@ with gr.Blocks(css=CSS, title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
513
  with gr.Column(scale=3):
514
  log_out = gr.Textbox(lines=5, label="๐Ÿ“‹ Agent Action Log", interactive=False, elem_classes="log-panel")
515
  with gr.Column(scale=1):
516
- spend_out2 = gr.Textbox(label="Total Spend", interactive=False)
517
- risk_out = gr.Textbox(label="Downtime Risk", interactive=False)
518
- score_num = gr.Number( label="Agent Score / 1.0", interactive=False, elem_classes="score-box")
519
 
520
  gr.Markdown("---")
521
  gr.Markdown("## ๐ŸŽฏ Radial Intelligence โ€” Live Gauges")
@@ -545,7 +512,6 @@ with gr.Blocks(css=CSS, title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
545
 
546
  gr.Markdown("> ๐Ÿ’ก **Pro tip:** Turn on **Chaos Monkey** + set Load to **90%** for maximum drama!")
547
 
548
- # โ”€โ”€ wire โ€” outputs count must equal return tuple length (24) โ”€โ”€
549
  run_btn.click(
550
  fn=run_simulation,
551
  inputs=[scenario, user_load, spot_avail, chaos_monkey, budget_constr, auto_scaling],
@@ -553,7 +519,7 @@ with gr.Blocks(css=CSS, title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
553
  load_out, server_out, burn_out, latency_out, savings_out, score_out,
554
  decision_out, xai_out, health_out, whatif_out,
555
  log_out, spend_out2, risk_out,
556
- score_num, # gr.Number โ† now receives raw float from return tuple
557
  gauge_plot, burst_plot, burst2_plot,
558
  area_plot, bar_plot,
559
  wave_plot, lat_plot,
@@ -561,5 +527,11 @@ with gr.Blocks(css=CSS, title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
561
  ]
562
  )
563
 
 
 
 
 
 
 
564
  if __name__ == "__main__":
565
- demo.launch(share=True)
 
6
  import matplotlib.patches as mpatches
7
  import numpy as np
8
  from datetime import datetime
9
+ from fastapi import FastAPI
10
+ from pydantic import BaseModel
11
+ import uvicorn
12
+ from environment import CloudCostEnv
13
+
14
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
15
+ # FASTAPI โ€” Checker endpoints (DO NOT REMOVE)
16
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
17
+ fapp = FastAPI()
18
+ _env = CloudCostEnv()
19
+
20
+ class StepRequest(BaseModel):
21
+ action: int
22
+
23
+ @fapp.post("/reset")
24
+ async def api_reset():
25
+ state = await _env.reset()
26
+ return state
27
+
28
+ @fapp.post("/step")
29
+ async def api_step(req: StepRequest):
30
+ state, reward, done = await _env.step(req.action)
31
+ return {"state": state, "reward": reward, "done": done}
32
+
33
+ @fapp.get("/state")
34
+ async def api_state():
35
+ return await _env.state()
36
 
37
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
38
  # COLOR SYSTEM
 
303
  }
304
 
305
  def get_decision(user_load, spot_avail, chaos_monkey, budget_on, latency):
306
+ if chaos_monkey and latency > 120: key = "chaos_resp"
307
  elif user_load > 80 and latency > 80: key = "scale_up"
308
  elif user_load < 35: key = "scale_down"
309
  elif budget_on and spot_avail > 50: key = "spot_switch"
 
320
  return "๐ŸŸข HEALTHY โ€” All Systems Nominal", "green"
321
 
322
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
323
+ # MAIN SIMULATION
324
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
325
  _tick = 0
326
 
 
347
  user_load, spot_avail, chaos_monkey, budget_on, latency)
348
  health_txt, _ = health_badge(latency, load, drisk)
349
 
350
+ decision_md = f"""### ๐Ÿง  AI Decision\n**โ†’ {action}**\n\n| | |\n|---|---|\n| Confidence | `{conf}%` |\n| Reason | {reason} |\n| Scenario | {scenario.split(':')[0]} |\n| Time | `{t}` |\n"""
351
+ xai_md = "### ๐Ÿ’ก Why did AI decide this?\n" + "".join(f"- โœ” {r}\n" for r in xai)
352
+ health_md = f"""### {health_txt}\n\n| Metric | Value |\n|---|---|\n| Latency | `{latency} ms` |\n| Load | `{load} req/s` |\n| Downtime risk | `{drisk}` |\n| Agent score | `{score} / 1.0` |\n"""
353
+ pred_cost = round(burn * (user_load / 48), 2)
354
+ pred_lat = round(latency * (user_load / 58), 1)
355
+ risk_lbl = ("๐Ÿ”ด HIGH" if pred_lat > 100 or pred_cost > 0.65
356
+ else "๐ŸŸก MEDIUM" if pred_lat > 60
357
+ else "๐ŸŸข LOW")
358
+ whatif_md = f"""### ๐Ÿ”ฎ What-If Simulation\n*If Load = {int(user_load)}% continues...*\n\n| Prediction | Value |\n|---|---|\n| Predicted cost | `${pred_cost}/hr` |\n| Predicted latency | `{pred_lat} ms` |\n| Risk level | {risk_lbl} |\n| Estimated savings | `{savings}` |\n"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  log = f"[{t}] {scenario}\n"
360
  log += f"[{t}] Load: {load} req/s | Servers: {servers} | Burn: ${burn}/hr\n"
361
  log += f"[{t}] Latency: {latency} ms | Risk: {drisk}\n"
362
  log += f"[{t}] DECISION: {action} (conf {conf}%)\n"
363
  log += f"[{t}] Score: {score} / 1.0 | Savings: {savings}"
364
 
 
365
  gauge_fig = make_gauge_chart(int(user_load), "User Load", C["cyan"], seed)
366
  burst_fig = make_radial_burst(load, "req/s", C["purple"], seed)
367
  burst2_fig = make_radial_burst(int(score*100), "Scoreร—100", C["green"], seed+1)
 
373
  before_fig = make_before_after(auto_scaling)
374
  whatif_fig = make_whatif(int(user_load), int(spot_avail))
375
 
 
376
  return (
377
+ f"๐Ÿš€ {load} req/s",
378
+ f"๐Ÿ–ฅ๏ธ {servers} instances",
379
+ f"๐Ÿ’ธ ${burn}/hr",
380
+ f"โšก {latency} ms",
381
+ f"๐Ÿ’ฐ {savings} saved",
382
+ f"๐Ÿ† {score} / 1.0",
383
+ decision_md,
384
+ xai_md,
385
+ health_md,
386
+ whatif_md,
387
+ log,
388
+ spend_str,
389
+ drisk,
390
+ score,
391
+ gauge_fig,
392
+ burst_fig,
393
+ burst2_fig,
394
+ area_fig,
395
+ bar_fig,
396
+ wave_fig,
397
+ lat_fig,
398
+ reward_fig,
399
+ before_fig,
400
+ whatif_fig,
401
  )
402
 
403
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
404
  # CSS
405
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
406
  CSS = """
 
 
407
  body, .gradio-container {
408
  background: #06091a !important;
409
  color: #e2eeff !important;
 
413
  background: rgba(11,17,32,0.85) !important;
414
  border: 0.5px solid #1e3a5f !important;
415
  border-radius: 14px !important;
 
416
  }
417
  .hero-metric textarea, .hero-metric input {
418
  font-size: 22px !important; font-weight: 800 !important;
419
  color: #00e5ff !important; text-align: center !important;
 
 
 
 
 
 
 
 
 
 
420
  }
421
  .card-decision { background: rgba(255,61,90,0.07) !important; border: 1px solid rgba(255,61,90,0.35) !important; border-radius: 14px !important; padding: 6px 10px !important; }
 
422
  .card-xai { background: rgba(0,229,255,0.05) !important; border: 1px solid rgba(0,229,255,0.25) !important; border-radius: 14px !important; padding: 6px 10px !important; }
 
423
  .card-health { background: rgba(0,255,157,0.06) !important; border: 1px solid rgba(0,255,157,0.28) !important; border-radius: 14px !important; padding: 6px 10px !important; }
 
424
  .card-whatif { background: rgba(192,132,252,0.06) !important; border: 1px solid rgba(192,132,252,0.28) !important; border-radius: 14px !important; padding: 6px 10px !important; }
 
425
  .gr-button-primary {
426
  background: linear-gradient(135deg, rgba(0,229,255,0.15), rgba(0,255,157,0.10)) !important;
427
  border: 1.5px solid #00e5ff !important; color: #00e5ff !important;
428
  font-size: 15px !important; font-weight: 700 !important;
429
+ border-radius: 12px !important; padding: 14px 0 !important;
 
430
  }
431
+ .log-panel textarea { font-family: monospace !important; font-size: 11.5px !important; color: #7ab0d0 !important; background: #050810 !important; }
 
 
 
 
 
 
 
 
 
 
 
432
  """
433
 
434
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
435
+ # GRADIO UI
436
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
437
+ with gr.Blocks(title="โ˜๏ธ Cloud-Cost Guardian AI") as demo:
438
 
439
  gr.Markdown("# โ˜๏ธ Cloud-Cost Guardian AI\n#### RL-Powered Autonomous Infrastructure โ€” Live Intelligence Dashboard\n---")
440
 
 
445
  score_out = gr.Textbox(label="๐Ÿ† Agent Score", interactive=False, elem_classes="hero-metric")
446
 
447
  with gr.Row(equal_height=True):
448
+ server_out = gr.Textbox(label="๐Ÿ–ฅ๏ธ Servers", interactive=False)
449
+ burn_out = gr.Textbox(label="๐Ÿ’ธ Burn Rate", interactive=False)
450
+ latency_out = gr.Textbox(label="โšก Latency", interactive=False)
451
 
452
  gr.Markdown("---")
453
 
 
471
  xai_out = gr.Markdown("### ๐Ÿ’ก Explainable AI\n*Waiting...*", elem_classes="card-xai")
472
 
473
  with gr.Column(scale=1, min_width=260):
474
+ health_out = gr.Markdown("### ๐ŸŸข Health Status\n*Click Run...*", elem_classes="card-health")
475
  whatif_out = gr.Markdown("### ๐Ÿ”ฎ What-If Simulation\n*Adjust sliders...*",elem_classes="card-whatif")
476
 
477
  gr.Markdown("---")
 
480
  with gr.Column(scale=3):
481
  log_out = gr.Textbox(lines=5, label="๐Ÿ“‹ Agent Action Log", interactive=False, elem_classes="log-panel")
482
  with gr.Column(scale=1):
483
+ spend_out2 = gr.Textbox(label="Total Spend", interactive=False)
484
+ risk_out = gr.Textbox(label="Downtime Risk", interactive=False)
485
+ score_num = gr.Number( label="Agent Score / 1.0", interactive=False)
486
 
487
  gr.Markdown("---")
488
  gr.Markdown("## ๐ŸŽฏ Radial Intelligence โ€” Live Gauges")
 
512
 
513
  gr.Markdown("> ๐Ÿ’ก **Pro tip:** Turn on **Chaos Monkey** + set Load to **90%** for maximum drama!")
514
 
 
515
  run_btn.click(
516
  fn=run_simulation,
517
  inputs=[scenario, user_load, spot_avail, chaos_monkey, budget_constr, auto_scaling],
 
519
  load_out, server_out, burn_out, latency_out, savings_out, score_out,
520
  decision_out, xai_out, health_out, whatif_out,
521
  log_out, spend_out2, risk_out,
522
+ score_num,
523
  gauge_plot, burst_plot, burst2_plot,
524
  area_plot, bar_plot,
525
  wave_plot, lat_plot,
 
527
  ]
528
  )
529
 
530
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
531
+ # MOUNT GRADIO INTO FASTAPI โ€” checker gets /reset /step /state
532
+ # Dashboard available at /ui
533
+ # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
534
+ app = gr.mount_gradio_app(fapp, demo, path="/ui")
535
+
536
  if __name__ == "__main__":
537
+ uvicorn.run(app, host="0.0.0.0", port=7860)