Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 10 |
-
from
|
| 11 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|
| 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
|
| 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 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
| 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",
|
| 382 |
-
f"๐ฅ๏ธ {servers} instances",
|
| 383 |
-
f"๐ธ ${burn}/hr",
|
| 384 |
-
f"โก {latency} ms",
|
| 385 |
-
f"๐ฐ {savings} saved",
|
| 386 |
-
f"๐ {score} / 1.0",
|
| 387 |
-
decision_md,
|
| 388 |
-
xai_md,
|
| 389 |
-
health_md,
|
| 390 |
-
whatif_md,
|
| 391 |
-
log,
|
| 392 |
-
spend_str,
|
| 393 |
-
drisk,
|
| 394 |
-
score,
|
| 395 |
-
gauge_fig,
|
| 396 |
-
burst_fig,
|
| 397 |
-
burst2_fig,
|
| 398 |
-
area_fig,
|
| 399 |
-
bar_fig,
|
| 400 |
-
wave_fig,
|
| 401 |
-
lat_fig,
|
| 402 |
-
reward_fig,
|
| 403 |
-
before_fig,
|
| 404 |
-
whatif_fig,
|
| 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 |
-
|
| 451 |
-
padding: 14px 0 !important; text-transform: uppercase !important;
|
| 452 |
}
|
| 453 |
-
.
|
| 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(
|
| 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
|
| 482 |
-
burn_out = gr.Textbox(label="๐ธ Burn Rate", interactive=False
|
| 483 |
-
latency_out = gr.Textbox(label="โก Latency", interactive=False
|
| 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...*",
|
| 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",
|
| 517 |
-
risk_out = gr.Textbox(label="Downtime Risk",
|
| 518 |
-
score_num = gr.Number( label="Agent Score / 1.0",
|
| 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,
|
| 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 |
-
|
|
|
|
| 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)
|