shank commited on
Commit Β·
2e70173
1
Parent(s): 7e7bcac
fix: move css to gr.Blocks() for Gradio 5.x compat
Browse files
app.py
CHANGED
|
@@ -1,10 +1,3 @@
|
|
| 1 |
-
"""
|
| 2 |
-
AgentDebuggerEnv β Interactive Research Showcase & Leaderboard
|
| 3 |
-
=============================================================
|
| 4 |
-
Primary entry point for the Hugging Face Space. Provides a premium,
|
| 5 |
-
glassmorphic UI to explore model debugging trajectories, benchmark rankings,
|
| 6 |
-
sandboxed execution, and the technical report.
|
| 7 |
-
"""
|
| 8 |
|
| 9 |
import os
|
| 10 |
import sys
|
|
@@ -14,17 +7,17 @@ import requests
|
|
| 14 |
import gradio as gr
|
| 15 |
from dotenv import load_dotenv
|
| 16 |
|
| 17 |
-
|
| 18 |
load_dotenv()
|
| 19 |
|
| 20 |
-
|
| 21 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 22 |
|
| 23 |
-
|
| 24 |
EVAL_RESULTS_PATH = "evaluation_results.json"
|
| 25 |
BASE_LEADERBOARD_PATH = "leaderboard/index.html"
|
| 26 |
|
| 27 |
-
|
| 28 |
DEFAULT_STATS = {
|
| 29 |
"summary": {
|
| 30 |
"overall": {
|
|
@@ -64,7 +57,7 @@ def load_evaluation_data():
|
|
| 64 |
print(f"Error loading evaluation results: {e}")
|
| 65 |
return {"summary": DEFAULT_STATS["summary"], "results": {}}
|
| 66 |
|
| 67 |
-
|
| 68 |
MOCK_TRAJECTORIES = {
|
| 69 |
"π’ Off-by-One: binary_search (Tier 1)": {
|
| 70 |
"buggy_code": "def binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1",
|
|
@@ -285,7 +278,7 @@ body {
|
|
| 285 |
}
|
| 286 |
"""
|
| 287 |
|
| 288 |
-
|
| 289 |
def render_leaderboard_html(summary_data):
|
| 290 |
overall = summary_data.get("overall", {})
|
| 291 |
t1 = summary_data.get("tiers", {}).get("tier1", {})
|
|
@@ -376,30 +369,30 @@ def render_leaderboard_html(summary_data):
|
|
| 376 |
"""
|
| 377 |
return html
|
| 378 |
|
| 379 |
-
|
| 380 |
def get_trajectory_explorer_dropdowns(eval_data):
|
| 381 |
options = []
|
| 382 |
-
|
| 383 |
if "results" in eval_data and eval_data["results"]:
|
| 384 |
for tier_name, bugs in eval_data["results"].items():
|
| 385 |
for bug in bugs:
|
| 386 |
options.append(f"{bug.get('function_name')} ({tier_name.capitalize()})")
|
| 387 |
|
| 388 |
-
|
| 389 |
for name in MOCK_TRAJECTORIES.keys():
|
| 390 |
if name not in options:
|
| 391 |
options.append(name)
|
| 392 |
return options
|
| 393 |
|
| 394 |
def get_bug_details(selected_name, eval_data):
|
| 395 |
-
|
| 396 |
if selected_name in MOCK_TRAJECTORIES:
|
| 397 |
data = MOCK_TRAJECTORIES[selected_name]
|
| 398 |
buggy_code = data["buggy_code"]
|
| 399 |
initial_error = data["initial_error"]
|
| 400 |
traj = data["trajectory"]
|
| 401 |
else:
|
| 402 |
-
|
| 403 |
resolved = None
|
| 404 |
for tier_name, bugs in eval_data.get("results", {}).items():
|
| 405 |
for bug in bugs:
|
|
@@ -425,14 +418,14 @@ def get_bug_details(selected_name, eval_data):
|
|
| 425 |
else:
|
| 426 |
return "No code", "No error", "No trajectories available"
|
| 427 |
|
| 428 |
-
|
| 429 |
markdown_out = []
|
| 430 |
for step in traj:
|
| 431 |
passed = step["test_results"].get("passed", 0)
|
| 432 |
total = step["test_results"].get("total", 1)
|
| 433 |
tests_bar = "β" * passed + "β" * (total - passed)
|
| 434 |
|
| 435 |
-
|
| 436 |
action_color = "#8b5cf6" if step["action"] == "propose_fix" else "#3b82f6"
|
| 437 |
|
| 438 |
rb = step["reward_breakdown"]
|
|
@@ -473,9 +466,9 @@ def get_bug_details(selected_name, eval_data):
|
|
| 473 |
|
| 474 |
return buggy_code, initial_error, "\n\n".join(markdown_out)
|
| 475 |
|
| 476 |
-
|
| 477 |
def run_sandbox_code(user_code, test_suite):
|
| 478 |
-
|
| 479 |
try:
|
| 480 |
from env.sandbox import execute_code
|
| 481 |
output, timed_out, exec_time = execute_code(user_code, test_suite)
|
|
@@ -484,7 +477,7 @@ def run_sandbox_code(user_code, test_suite):
|
|
| 484 |
except Exception as e:
|
| 485 |
return f"Execution Error: {e}", "β Failed"
|
| 486 |
|
| 487 |
-
|
| 488 |
def read_technical_report():
|
| 489 |
report_path = "Blog.md"
|
| 490 |
if os.path.exists(report_path):
|
|
@@ -495,13 +488,13 @@ def read_technical_report():
|
|
| 495 |
pass
|
| 496 |
return "Technical report draft `Blog.md` not found."
|
| 497 |
|
| 498 |
-
|
| 499 |
eval_data = load_evaluation_data()
|
| 500 |
bug_options = get_trajectory_explorer_dropdowns(eval_data)
|
| 501 |
|
| 502 |
-
with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
|
|
|
| 503 |
|
| 504 |
-
# ββ Header ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 505 |
gr.HTML(
|
| 506 |
"""
|
| 507 |
<div class="glass-header">
|
|
@@ -513,7 +506,7 @@ with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
|
| 513 |
)
|
| 514 |
|
| 515 |
with gr.Tabs():
|
| 516 |
-
|
| 517 |
with gr.TabItem("π΅οΈ Trajectory Explorer"):
|
| 518 |
gr.Markdown(
|
| 519 |
"""
|
|
@@ -545,7 +538,7 @@ with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
|
| 545 |
gr.Markdown("### π§ Model Cognitive Loop Trajectory")
|
| 546 |
trajectory_output = gr.Markdown(value="Loading initial trajectory...")
|
| 547 |
|
| 548 |
-
|
| 549 |
def update_explorer(name):
|
| 550 |
code, err, traj = get_bug_details(name, eval_data)
|
| 551 |
return code, err, traj
|
|
@@ -556,13 +549,13 @@ with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
|
| 556 |
outputs=[bug_code_viewer, error_msg_viewer, trajectory_output]
|
| 557 |
)
|
| 558 |
|
| 559 |
-
|
| 560 |
demo.load(
|
| 561 |
fn=lambda: update_explorer(bug_options[0]) if bug_options else ("", "", ""),
|
| 562 |
outputs=[bug_code_viewer, error_msg_viewer, trajectory_output]
|
| 563 |
)
|
| 564 |
|
| 565 |
-
|
| 566 |
with gr.TabItem("π Benchmark Leaderboard"):
|
| 567 |
gr.Markdown(
|
| 568 |
"""
|
|
@@ -585,11 +578,11 @@ with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
|
| 585 |
"""
|
| 586 |
)
|
| 587 |
with gr.Column():
|
| 588 |
-
|
| 589 |
gr.Image("images/total.png", label="GRPO Total Reward Curve")
|
| 590 |
gr.Image("images/format_compliance.png", label="Format Compliance Curve")
|
| 591 |
|
| 592 |
-
|
| 593 |
with gr.TabItem("π‘οΈ Sandbox Playground"):
|
| 594 |
gr.Markdown(
|
| 595 |
"""
|
|
@@ -629,7 +622,7 @@ with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
|
| 629 |
outputs=[sandbox_stdout, sandbox_status]
|
| 630 |
)
|
| 631 |
|
| 632 |
-
|
| 633 |
with gr.TabItem("π Technical Report"):
|
| 634 |
gr.Markdown(
|
| 635 |
"""
|
|
@@ -651,4 +644,4 @@ with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
|
| 651 |
)
|
| 652 |
|
| 653 |
if __name__ == "__main__":
|
| 654 |
-
demo.launch(server_name="0.0.0.0", server_port=7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
import os
|
| 3 |
import sys
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
|
| 10 |
+
|
| 11 |
load_dotenv()
|
| 12 |
|
| 13 |
+
|
| 14 |
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 15 |
|
| 16 |
+
|
| 17 |
EVAL_RESULTS_PATH = "evaluation_results.json"
|
| 18 |
BASE_LEADERBOARD_PATH = "leaderboard/index.html"
|
| 19 |
|
| 20 |
+
|
| 21 |
DEFAULT_STATS = {
|
| 22 |
"summary": {
|
| 23 |
"overall": {
|
|
|
|
| 57 |
print(f"Error loading evaluation results: {e}")
|
| 58 |
return {"summary": DEFAULT_STATS["summary"], "results": {}}
|
| 59 |
|
| 60 |
+
|
| 61 |
MOCK_TRAJECTORIES = {
|
| 62 |
"π’ Off-by-One: binary_search (Tier 1)": {
|
| 63 |
"buggy_code": "def binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1",
|
|
|
|
| 278 |
}
|
| 279 |
"""
|
| 280 |
|
| 281 |
+
|
| 282 |
def render_leaderboard_html(summary_data):
|
| 283 |
overall = summary_data.get("overall", {})
|
| 284 |
t1 = summary_data.get("tiers", {}).get("tier1", {})
|
|
|
|
| 369 |
"""
|
| 370 |
return html
|
| 371 |
|
| 372 |
+
|
| 373 |
def get_trajectory_explorer_dropdowns(eval_data):
|
| 374 |
options = []
|
| 375 |
+
|
| 376 |
if "results" in eval_data and eval_data["results"]:
|
| 377 |
for tier_name, bugs in eval_data["results"].items():
|
| 378 |
for bug in bugs:
|
| 379 |
options.append(f"{bug.get('function_name')} ({tier_name.capitalize()})")
|
| 380 |
|
| 381 |
+
|
| 382 |
for name in MOCK_TRAJECTORIES.keys():
|
| 383 |
if name not in options:
|
| 384 |
options.append(name)
|
| 385 |
return options
|
| 386 |
|
| 387 |
def get_bug_details(selected_name, eval_data):
|
| 388 |
+
|
| 389 |
if selected_name in MOCK_TRAJECTORIES:
|
| 390 |
data = MOCK_TRAJECTORIES[selected_name]
|
| 391 |
buggy_code = data["buggy_code"]
|
| 392 |
initial_error = data["initial_error"]
|
| 393 |
traj = data["trajectory"]
|
| 394 |
else:
|
| 395 |
+
|
| 396 |
resolved = None
|
| 397 |
for tier_name, bugs in eval_data.get("results", {}).items():
|
| 398 |
for bug in bugs:
|
|
|
|
| 418 |
else:
|
| 419 |
return "No code", "No error", "No trajectories available"
|
| 420 |
|
| 421 |
+
|
| 422 |
markdown_out = []
|
| 423 |
for step in traj:
|
| 424 |
passed = step["test_results"].get("passed", 0)
|
| 425 |
total = step["test_results"].get("total", 1)
|
| 426 |
tests_bar = "β" * passed + "β" * (total - passed)
|
| 427 |
|
| 428 |
+
|
| 429 |
action_color = "#8b5cf6" if step["action"] == "propose_fix" else "#3b82f6"
|
| 430 |
|
| 431 |
rb = step["reward_breakdown"]
|
|
|
|
| 466 |
|
| 467 |
return buggy_code, initial_error, "\n\n".join(markdown_out)
|
| 468 |
|
| 469 |
+
|
| 470 |
def run_sandbox_code(user_code, test_suite):
|
| 471 |
+
|
| 472 |
try:
|
| 473 |
from env.sandbox import execute_code
|
| 474 |
output, timed_out, exec_time = execute_code(user_code, test_suite)
|
|
|
|
| 477 |
except Exception as e:
|
| 478 |
return f"Execution Error: {e}", "β Failed"
|
| 479 |
|
| 480 |
+
|
| 481 |
def read_technical_report():
|
| 482 |
report_path = "Blog.md"
|
| 483 |
if os.path.exists(report_path):
|
|
|
|
| 488 |
pass
|
| 489 |
return "Technical report draft `Blog.md` not found."
|
| 490 |
|
| 491 |
+
|
| 492 |
eval_data = load_evaluation_data()
|
| 493 |
bug_options = get_trajectory_explorer_dropdowns(eval_data)
|
| 494 |
|
| 495 |
+
with gr.Blocks(title="AgentDebuggerEnv Research Hub", css=CUSTOM_CSS) as demo:
|
| 496 |
+
|
| 497 |
|
|
|
|
| 498 |
gr.HTML(
|
| 499 |
"""
|
| 500 |
<div class="glass-header">
|
|
|
|
| 506 |
)
|
| 507 |
|
| 508 |
with gr.Tabs():
|
| 509 |
+
|
| 510 |
with gr.TabItem("π΅οΈ Trajectory Explorer"):
|
| 511 |
gr.Markdown(
|
| 512 |
"""
|
|
|
|
| 538 |
gr.Markdown("### π§ Model Cognitive Loop Trajectory")
|
| 539 |
trajectory_output = gr.Markdown(value="Loading initial trajectory...")
|
| 540 |
|
| 541 |
+
|
| 542 |
def update_explorer(name):
|
| 543 |
code, err, traj = get_bug_details(name, eval_data)
|
| 544 |
return code, err, traj
|
|
|
|
| 549 |
outputs=[bug_code_viewer, error_msg_viewer, trajectory_output]
|
| 550 |
)
|
| 551 |
|
| 552 |
+
|
| 553 |
demo.load(
|
| 554 |
fn=lambda: update_explorer(bug_options[0]) if bug_options else ("", "", ""),
|
| 555 |
outputs=[bug_code_viewer, error_msg_viewer, trajectory_output]
|
| 556 |
)
|
| 557 |
|
| 558 |
+
|
| 559 |
with gr.TabItem("π Benchmark Leaderboard"):
|
| 560 |
gr.Markdown(
|
| 561 |
"""
|
|
|
|
| 578 |
"""
|
| 579 |
)
|
| 580 |
with gr.Column():
|
| 581 |
+
|
| 582 |
gr.Image("images/total.png", label="GRPO Total Reward Curve")
|
| 583 |
gr.Image("images/format_compliance.png", label="Format Compliance Curve")
|
| 584 |
|
| 585 |
+
|
| 586 |
with gr.TabItem("π‘οΈ Sandbox Playground"):
|
| 587 |
gr.Markdown(
|
| 588 |
"""
|
|
|
|
| 622 |
outputs=[sandbox_stdout, sandbox_status]
|
| 623 |
)
|
| 624 |
|
| 625 |
+
|
| 626 |
with gr.TabItem("π Technical Report"):
|
| 627 |
gr.Markdown(
|
| 628 |
"""
|
|
|
|
| 644 |
)
|
| 645 |
|
| 646 |
if __name__ == "__main__":
|
| 647 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|