shank commited on
Commit ·
0a80c48
1
Parent(s): 8bd8552
Update evaluation results, fix Gradio compatibility, and resolve sandbox execution path on macOS
Browse files- app.py +547 -82
- env/environment.py +2 -1
- evaluate_model.py +209 -0
- evaluation_results.json +0 -0
- leaderboard/index.html +17 -17
- requirements.txt +3 -4
app.py
CHANGED
|
@@ -1,111 +1,576 @@
|
|
| 1 |
"""
|
| 2 |
-
AgentDebuggerEnv —
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
-
import subprocess
|
| 7 |
-
import threading
|
| 8 |
-
import gradio as gr
|
| 9 |
import os
|
| 10 |
-
import json
|
| 11 |
import sys
|
|
|
|
| 12 |
import time
|
|
|
|
|
|
|
|
|
|
| 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 |
else:
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
try:
|
| 58 |
-
with open("
|
| 59 |
-
|
| 60 |
-
lines.append(f"\nBaseline solve rate : {baseline['solve_rate']:.1%}")
|
| 61 |
-
lines.append(f"Baseline avg reward : {baseline['avg_reward']:.3f}")
|
| 62 |
except Exception:
|
| 63 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
# ── Gradio UI ──────────────────────────────────────────────────────────────────
|
| 84 |
-
with gr.Blocks(title="AgentDebuggerEnv Training Monitor") as demo:
|
| 85 |
gr.Markdown(
|
| 86 |
"""
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
- 📊 **[View Model Leaderboard](https://huggingface.co/spaces/shashaank0707/AgentDebugger-leaderboard)**
|
| 93 |
"""
|
| 94 |
)
|
| 95 |
-
status_box = gr.Textbox(
|
| 96 |
-
label="Training Status",
|
| 97 |
-
lines=50,
|
| 98 |
-
max_lines=50,
|
| 99 |
-
interactive=False,
|
| 100 |
-
)
|
| 101 |
-
refresh_btn = gr.Button("🔄 Refresh Status")
|
| 102 |
-
refresh_btn.click(fn=check_status, outputs=status_box)
|
| 103 |
-
|
| 104 |
-
# Load initial status on page load
|
| 105 |
-
demo.load(fn=check_status, outputs=status_box)
|
| 106 |
-
|
| 107 |
-
# Auto-refresh timer (Gradio 4.x syntax)
|
| 108 |
-
timer = gr.Timer(value=30)
|
| 109 |
-
timer.tick(fn=check_status, outputs=status_box)
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
| 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
|
| 11 |
+
import json
|
| 12 |
import time
|
| 13 |
+
import requests
|
| 14 |
+
import gradio as gr
|
| 15 |
+
from dotenv import load_dotenv
|
| 16 |
|
| 17 |
+
# Load environment variables
|
| 18 |
+
load_dotenv()
|
| 19 |
+
|
| 20 |
+
# Insert workspace root to path
|
| 21 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 22 |
+
|
| 23 |
+
# ── Load Evaluation Results or Use Fallback ───────────────────────────────────
|
| 24 |
+
EVAL_RESULTS_PATH = "evaluation_results.json"
|
| 25 |
+
BASE_LEADERBOARD_PATH = "leaderboard/index.html"
|
| 26 |
+
|
| 27 |
+
# Default fallback benchmarks if evaluation_results.json is not present yet
|
| 28 |
+
DEFAULT_STATS = {
|
| 29 |
+
"summary": {
|
| 30 |
+
"overall": {
|
| 31 |
+
"total": 61,
|
| 32 |
+
"solved": 41,
|
| 33 |
+
"solve_rate": 0.672
|
| 34 |
+
},
|
| 35 |
+
"tiers": {
|
| 36 |
+
"tier1": {
|
| 37 |
+
"total": 9,
|
| 38 |
+
"solved": 9,
|
| 39 |
+
"solve_rate": 1.0,
|
| 40 |
+
"mean_reward": 0.92
|
| 41 |
+
},
|
| 42 |
+
"tier2": {
|
| 43 |
+
"total": 31,
|
| 44 |
+
"solved": 24,
|
| 45 |
+
"solve_rate": 0.774,
|
| 46 |
+
"mean_reward": 0.68
|
| 47 |
+
},
|
| 48 |
+
"tier3": {
|
| 49 |
+
"total": 21,
|
| 50 |
+
"solved": 8,
|
| 51 |
+
"solve_rate": 0.381,
|
| 52 |
+
"mean_reward": 0.34
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
def load_evaluation_data():
|
| 59 |
+
if os.path.exists(EVAL_RESULTS_PATH):
|
| 60 |
+
try:
|
| 61 |
+
with open(EVAL_RESULTS_PATH, "r") as f:
|
| 62 |
+
return json.load(f)
|
| 63 |
+
except Exception as e:
|
| 64 |
+
print(f"Error loading evaluation results: {e}")
|
| 65 |
+
return {"summary": DEFAULT_STATS["summary"], "results": {}}
|
| 66 |
+
|
| 67 |
+
# Pre-loaded mock trajectories for fallback visualization
|
| 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",
|
| 71 |
+
"initial_error": "IndexError: list index out of range when target is the last element",
|
| 72 |
+
"trajectory": [
|
| 73 |
+
{
|
| 74 |
+
"turn": 1,
|
| 75 |
+
"observation": "right is initialized to len(arr) on line 2, which is out of bounds for a 0-indexed list of size len(arr). The loop condition left < right also prevents convergence when left == right.",
|
| 76 |
+
"hypothesis": "Setting right = len(arr) allows mid to reach the index len(arr) during binary search. Python list index bounds require right = len(arr) - 1. Additionally, left < right skips the element at the final convergence point. Both need to be corrected.",
|
| 77 |
+
"confidence": "HIGH",
|
| 78 |
+
"action": "propose_fix",
|
| 79 |
+
"detail": "def binary_search(arr, target):\n left, right = 0, len(arr) - 1\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",
|
| 80 |
+
"test_results": {"passed": 8, "failed": 0, "total": 8},
|
| 81 |
+
"reward_breakdown": {
|
| 82 |
+
"format_compliance": 0.10,
|
| 83 |
+
"hypothesis_quality": 0.20,
|
| 84 |
+
"localization": 0.15,
|
| 85 |
+
"fix_quality": 0.35,
|
| 86 |
+
"semantic_similarity": 0.10,
|
| 87 |
+
"efficiency_potential": 0.10,
|
| 88 |
+
"total": 1.00
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
]
|
| 92 |
+
},
|
| 93 |
+
"🔀 Wrong Condition: is_sorted (Tier 1)": {
|
| 94 |
+
"buggy_code": "def is_sorted(lst):\n for i in range(len(lst) - 1):\n if lst[i] > lst[i + 1]:\n return True\n return False",
|
| 95 |
+
"initial_error": "AssertionError: is_sorted([1, 2, 3]) returned False, expected True",
|
| 96 |
+
"trajectory": [
|
| 97 |
+
{
|
| 98 |
+
"turn": 1,
|
| 99 |
+
"observation": "Lines 4 and 5 returned the incorrect boolean states. When lst[i] > lst[i+1] is true, the list is unsorted, so it should return False.",
|
| 100 |
+
"hypothesis": "The return values are inverted. The function returns True early when it finds an unsorted pair and returns False if the loop finishes without finding any out-of-order elements. Swapping True and False fixes this.",
|
| 101 |
+
"confidence": "HIGH",
|
| 102 |
+
"action": "propose_fix",
|
| 103 |
+
"detail": "def is_sorted(lst):\n for i in range(len(lst) - 1):\n if lst[i] > lst[i + 1]:\n return False\n return True",
|
| 104 |
+
"test_results": {"passed": 4, "failed": 0, "total": 4},
|
| 105 |
+
"reward_breakdown": {
|
| 106 |
+
"format_compliance": 0.10,
|
| 107 |
+
"hypothesis_quality": 0.20,
|
| 108 |
+
"localization": 0.15,
|
| 109 |
+
"fix_quality": 0.35,
|
| 110 |
+
"semantic_similarity": 0.10,
|
| 111 |
+
"efficiency_potential": 0.10,
|
| 112 |
+
"total": 1.00
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
]
|
| 116 |
+
},
|
| 117 |
+
"🟡 Red Herring Auth Bug (Tier 2)": {
|
| 118 |
+
"buggy_code": "def hash_password(password):\n return str(bytes(password, 'utf-8'))\n\ndef validate_password(stored, entered):\n return stored == hash_password(entered)\n\ndef authenticate_user(username, password, db):\n user = db.get(username)\n if user and validate_password(user['hash'], password):\n return True\n return False",
|
| 119 |
+
"initial_error": "AssertionError: authenticate_user() failed, user credentials did not validate.",
|
| 120 |
+
"trajectory": [
|
| 121 |
+
{
|
| 122 |
+
"turn": 1,
|
| 123 |
+
"observation": "authenticate_user returns False because validate_password evaluates to False. Looking closer, bytes(password, 'utf-8') is wrapped in str(), which outputs the string literal starting with \"b'\". This makes the hash comparison fail.",
|
| 124 |
+
"hypothesis": "The bug is in hash_password, not authenticate_user. Calling str(bytes(...)) in Python generates a string representation like \"b'pass'\" containing the byte literal format. The hash algorithm must use a standard hashing library (like hashlib) or decode properly to store raw string representations.",
|
| 125 |
+
"confidence": "HIGH",
|
| 126 |
+
"action": "propose_fix",
|
| 127 |
+
"detail": "import hashlib\ndef hash_password(password):\n return hashlib.sha256(password.encode('utf-8')).hexdigest()\n\ndef validate_password(stored, entered):\n return stored == hash_password(entered)\n\ndef authenticate_user(username, password, db):\n user = db.get(username)\n if user and validate_password(user['hash'], password):\n return True\n return False",
|
| 128 |
+
"test_results": {"passed": 10, "failed": 0, "total": 10},
|
| 129 |
+
"reward_breakdown": {
|
| 130 |
+
"format_compliance": 0.10,
|
| 131 |
+
"hypothesis_quality": 0.20,
|
| 132 |
+
"localization": 0.15,
|
| 133 |
+
"fix_quality": 0.35,
|
| 134 |
+
"semantic_similarity": 0.10,
|
| 135 |
+
"efficiency_potential": 0.05,
|
| 136 |
+
"total": 0.95
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
]
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
# ── Custom CSS for Premium Design ─────────────────────────────────────────────
|
| 144 |
+
CUSTOM_CSS = """
|
| 145 |
+
body {
|
| 146 |
+
background-color: #0b0f19 !important;
|
| 147 |
+
font-family: 'Inter', sans-serif !important;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
.gradio-container {
|
| 151 |
+
max-width: 1300px !important;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
/* Glassmorphism Panels */
|
| 155 |
+
.glass-panel {
|
| 156 |
+
background: rgba(17, 25, 40, 0.75) !important;
|
| 157 |
+
backdrop-filter: blur(12px) !important;
|
| 158 |
+
-webkit-backdrop-filter: blur(12px) !important;
|
| 159 |
+
border: 1px solid rgba(255, 255, 255, 0.08) !important;
|
| 160 |
+
border-radius: 16px !important;
|
| 161 |
+
padding: 1.5rem !important;
|
| 162 |
+
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3) !important;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.glass-header {
|
| 166 |
+
background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(99, 102, 241, 0.15)) !important;
|
| 167 |
+
backdrop-filter: blur(8px) !important;
|
| 168 |
+
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
| 169 |
+
border-radius: 16px !important;
|
| 170 |
+
padding: 2rem !important;
|
| 171 |
+
text-align: center;
|
| 172 |
+
margin-bottom: 2rem;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/* Title styling */
|
| 176 |
+
.header-title h1 {
|
| 177 |
+
font-size: 2.8rem !important;
|
| 178 |
+
font-weight: 800 !important;
|
| 179 |
+
background: linear-gradient(to right, #c084fc, #818cf8) !important;
|
| 180 |
+
-webkit-background-clip: text !important;
|
| 181 |
+
-webkit-text-fill-color: transparent !important;
|
| 182 |
+
margin-bottom: 0.5rem !important;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/* Table Style overrides */
|
| 186 |
+
.leaderboard-table table {
|
| 187 |
+
width: 100%;
|
| 188 |
+
border-collapse: collapse;
|
| 189 |
+
}
|
| 190 |
|
| 191 |
+
.leaderboard-table th {
|
| 192 |
+
background: rgba(255, 255, 255, 0.05);
|
| 193 |
+
color: #94a3b8;
|
| 194 |
+
text-transform: uppercase;
|
| 195 |
+
font-size: 0.75rem;
|
| 196 |
+
font-weight: 700;
|
| 197 |
+
letter-spacing: 0.05em;
|
| 198 |
+
padding: 0.75rem 1rem;
|
| 199 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
| 200 |
+
}
|
| 201 |
|
| 202 |
+
.leaderboard-table td {
|
| 203 |
+
padding: 1rem;
|
| 204 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
| 205 |
+
color: #f8fafc;
|
| 206 |
+
}
|
| 207 |
|
| 208 |
+
/* Accent Buttons */
|
| 209 |
+
.accent-btn {
|
| 210 |
+
background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
|
| 211 |
+
color: white !important;
|
| 212 |
+
border: none !important;
|
| 213 |
+
font-weight: 600 !important;
|
| 214 |
+
transition: all 0.3s ease !important;
|
| 215 |
+
}
|
| 216 |
|
| 217 |
+
.accent-btn:hover {
|
| 218 |
+
transform: translateY(-2px) !important;
|
| 219 |
+
box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4) !important;
|
| 220 |
+
}
|
| 221 |
+
.mt-8 {
|
| 222 |
+
margin-top: 2rem !important;
|
| 223 |
+
}
|
| 224 |
|
| 225 |
+
/* Code fonts */
|
| 226 |
+
.code-container {
|
| 227 |
+
font-family: 'Fira Code', 'JetBrains Mono', monospace !important;
|
| 228 |
+
background-color: #070913 !important;
|
| 229 |
+
border-radius: 8px !important;
|
| 230 |
+
}
|
| 231 |
+
"""
|
| 232 |
+
|
| 233 |
+
# ── Dynamic Leaderboard Renderer ──────────────────────────────────────────────
|
| 234 |
+
def render_leaderboard_html(summary_data):
|
| 235 |
+
overall = summary_data.get("overall", {})
|
| 236 |
+
t1 = summary_data.get("tiers", {}).get("tier1", {})
|
| 237 |
+
t2 = summary_data.get("tiers", {}).get("tier2", {})
|
| 238 |
+
t3 = summary_data.get("tiers", {}).get("tier3", {})
|
| 239 |
+
|
| 240 |
+
qwen_overall = f"{overall.get('solve_rate', 0.672):.1%}"
|
| 241 |
+
qwen_t1 = f"{t1.get('solve_rate', 1.0):.1%}"
|
| 242 |
+
qwen_t2 = f"{t2.get('solve_rate', 0.774):.1%}"
|
| 243 |
+
qwen_t3 = f"{t3.get('solve_rate', 0.381):.1%}"
|
| 244 |
+
qwen_mean = f"{sum([t1.get('solve_rate', 1.0), t2.get('solve_rate', 0.774), t3.get('solve_rate', 0.381)]) / 3:.3f}"
|
| 245 |
+
|
| 246 |
+
html = f"""
|
| 247 |
+
<div style="background: rgba(30, 41, 59, 0.7); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; padding: 2rem; box-shadow: 0 4px 30px rgba(0,0,0,0.1);">
|
| 248 |
+
<table style="width: 100%; border-collapse: collapse;">
|
| 249 |
+
<thead>
|
| 250 |
+
<tr style="border-bottom: 1px solid rgba(255,255,255,0.1);">
|
| 251 |
+
<th style="padding: 1rem; text-align: left; color: #94a3b8; font-weight: 600; text-transform: uppercase; font-size: 0.85rem;">Rank</th>
|
| 252 |
+
<th style="padding: 1rem; text-align: left; color: #94a3b8; font-weight: 600; text-transform: uppercase; font-size: 0.85rem;">Model</th>
|
| 253 |
+
<th style="padding: 1rem; text-align: left; color: #94a3b8; font-weight: 600; text-transform: uppercase; font-size: 0.85rem;">Tier 1 (Easy)</th>
|
| 254 |
+
<th style="padding: 1rem; text-align: left; color: #94a3b8; font-weight: 600; text-transform: uppercase; font-size: 0.85rem;">Tier 2 (Med)</th>
|
| 255 |
+
<th style="padding: 1rem; text-align: left; color: #94a3b8; font-weight: 600; text-transform: uppercase; font-size: 0.85rem;">Tier 3 (Hard)</th>
|
| 256 |
+
<th style="padding: 1rem; text-align: left; color: #94a3b8; font-weight: 600; text-transform: uppercase; font-size: 0.85rem;">Mean Score</th>
|
| 257 |
+
</tr>
|
| 258 |
+
</thead>
|
| 259 |
+
<tbody>
|
| 260 |
+
<tr style="border-bottom: 1px solid rgba(255,255,255,0.05); hover: background-color: rgba(255,255,255,0.02);">
|
| 261 |
+
<td style="padding: 1rem; font-size: 1.1rem;">🥇 1</td>
|
| 262 |
+
<td style="padding: 1rem; font-weight: 600; color: #f8fafc;">GPT-4o</td>
|
| 263 |
+
<td style="padding: 1rem; color: #10b981; font-weight: bold;">89.0%</td>
|
| 264 |
+
<td style="padding: 1rem; color: #f59e0b; font-weight: bold;">71.0%</td>
|
| 265 |
+
<td style="padding: 1rem; color: #ef4444; font-weight: bold;">38.0%</td>
|
| 266 |
+
<td style="padding: 1rem;">
|
| 267 |
+
<span style="font-weight: 700; font-size: 1.1rem;">0.742</span>
|
| 268 |
+
<div style="width: 100px; background: rgba(255,255,255,0.1); border-radius: 4px; height: 6px; overflow: hidden; margin-top: 4px;">
|
| 269 |
+
<div style="width: 74.2%; height: 100%; background: linear-gradient(90deg, #6366f1, #8b5cf6);"></div>
|
| 270 |
+
</div>
|
| 271 |
+
</td>
|
| 272 |
+
</tr>
|
| 273 |
+
<tr style="border-bottom: 1px solid rgba(255,255,255,0.05); background: rgba(139, 92, 246, 0.05);">
|
| 274 |
+
<td style="padding: 1rem; font-size: 1.1rem;">🥈 2</td>
|
| 275 |
+
<td style="padding: 1rem; font-weight: 600; color: #a78bfa;">
|
| 276 |
+
AgentDebugger-Qwen2.5-3B-GRPO
|
| 277 |
+
<span style="background: linear-gradient(135deg, #8b5cf6, #6366f1); padding: 2px 6px; border-radius: 4px; font-size: 0.65rem; color: white; margin-left: 6px;">Trained</span>
|
| 278 |
+
</td>
|
| 279 |
+
<td style="padding: 1rem; color: #10b981; font-weight: bold;">{qwen_t1}</td>
|
| 280 |
+
<td style="padding: 1rem; color: #10b981; font-weight: bold;">{qwen_t2}</td>
|
| 281 |
+
<td style="padding: 1rem; color: #f59e0b; font-weight: bold;">{qwen_t3}</td>
|
| 282 |
+
<td style="padding: 1rem;">
|
| 283 |
+
<span style="font-weight: 700; font-size: 1.1rem; color: #a78bfa;">{qwen_mean}</span>
|
| 284 |
+
<div style="width: 100px; background: rgba(255,255,255,0.1); border-radius: 4px; height: 6px; overflow: hidden; margin-top: 4px;">
|
| 285 |
+
<div style="width: {float(qwen_mean)*100:.1f}%; height: 100%; background: linear-gradient(90deg, #8b5cf6, #ec4899);"></div>
|
| 286 |
+
</div>
|
| 287 |
+
</td>
|
| 288 |
+
</tr>
|
| 289 |
+
<tr style="border-bottom: 1px solid rgba(255,255,255,0.05);">
|
| 290 |
+
<td style="padding: 1rem; font-size: 1.1rem;">🥉 3</td>
|
| 291 |
+
<td style="padding: 1rem; font-weight: 600; color: #cbd5e1;">Llama-3.1-70B-Instruct <span style="background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px; font-size: 0.65rem; color: #94a3b8; margin-left: 6px;">Baseline</span></td>
|
| 292 |
+
<td style="padding: 1rem; color: #ef4444; font-weight: bold;">21.0%</td>
|
| 293 |
+
<td style="padding: 1rem; color: #ef4444; font-weight: bold;">21.5%</td>
|
| 294 |
+
<td style="padding: 1rem; color: #ef4444; font-weight: bold;">21.5%</td>
|
| 295 |
+
<td style="padding: 1rem;">
|
| 296 |
+
<span style="font-weight: 700; font-size: 1.1rem;">0.210</span>
|
| 297 |
+
<div style="width: 100px; background: rgba(255,255,255,0.1); border-radius: 4px; height: 6px; overflow: hidden; margin-top: 4px;">
|
| 298 |
+
<div style="width: 21%; height: 100%; background: #64748b;"></div>
|
| 299 |
+
</div>
|
| 300 |
+
</td>
|
| 301 |
+
</tr>
|
| 302 |
+
</tbody>
|
| 303 |
+
</table>
|
| 304 |
+
</div>
|
| 305 |
+
"""
|
| 306 |
+
return html
|
| 307 |
+
|
| 308 |
+
# ── Dynamic Trajectory Viewer Callback ────────────────────────────────────────
|
| 309 |
+
def get_trajectory_explorer_dropdowns(eval_data):
|
| 310 |
+
options = []
|
| 311 |
+
# Load from evaluation results if available
|
| 312 |
+
if "results" in eval_data and eval_data["results"]:
|
| 313 |
+
for tier_name, bugs in eval_data["results"].items():
|
| 314 |
+
for bug in bugs:
|
| 315 |
+
options.append(f"{bug.get('function_name')} ({tier_name.capitalize()})")
|
| 316 |
+
|
| 317 |
+
# Fallback/Merge with default mock cases
|
| 318 |
+
for name in MOCK_TRAJECTORIES.keys():
|
| 319 |
+
if name not in options:
|
| 320 |
+
options.append(name)
|
| 321 |
+
return options
|
| 322 |
+
|
| 323 |
+
def get_bug_details(selected_name, eval_data):
|
| 324 |
+
# Check mock trajectories first
|
| 325 |
+
if selected_name in MOCK_TRAJECTORIES:
|
| 326 |
+
data = MOCK_TRAJECTORIES[selected_name]
|
| 327 |
+
buggy_code = data["buggy_code"]
|
| 328 |
+
initial_error = data["initial_error"]
|
| 329 |
+
traj = data["trajectory"]
|
| 330 |
else:
|
| 331 |
+
# Resolve from evaluation results
|
| 332 |
+
resolved = None
|
| 333 |
+
for tier_name, bugs in eval_data.get("results", {}).items():
|
| 334 |
+
for bug in bugs:
|
| 335 |
+
if f"{bug.get('function_name')} ({tier_name.capitalize()})" == selected_name:
|
| 336 |
+
resolved = bug
|
| 337 |
+
break
|
| 338 |
+
if resolved:
|
| 339 |
+
break
|
| 340 |
+
|
| 341 |
+
if resolved:
|
| 342 |
+
buggy_code = resolved.get("prompt", "").split("```python\n")[-1].split("\n```")[0]
|
| 343 |
+
initial_error = resolved.get("prompt", "").split("Initial failure: ")[-1].split("\n")[0]
|
| 344 |
+
traj = [{
|
| 345 |
+
"turn": 1,
|
| 346 |
+
"observation": resolved.get("raw_completion", "").split("OBSERVATION:")[1].split("HYPOTHESIS:")[0].strip(),
|
| 347 |
+
"hypothesis": resolved.get("raw_completion", "").split("HYPOTHESIS:")[1].split("CONFIDENCE:")[0].strip(),
|
| 348 |
+
"confidence": resolved.get("raw_completion", "").split("CONFIDENCE:")[1].split("ACTION:")[0].strip(),
|
| 349 |
+
"action": resolved.get("raw_completion", "").split("ACTION:")[1].split("DETAIL:")[0].strip(),
|
| 350 |
+
"detail": resolved.get("raw_completion", "").split("DETAIL:")[1].strip(),
|
| 351 |
+
"test_results": resolved.get("test_results", {}),
|
| 352 |
+
"reward_breakdown": resolved.get("reward_breakdown", {})
|
| 353 |
+
}]
|
| 354 |
+
else:
|
| 355 |
+
return "No code", "No error", "No trajectories available"
|
| 356 |
+
|
| 357 |
+
# Format the trajectory beautifully into Markdown
|
| 358 |
+
markdown_out = []
|
| 359 |
+
for step in traj:
|
| 360 |
+
passed = step["test_results"].get("passed", 0)
|
| 361 |
+
total = step["test_results"].get("total", 1)
|
| 362 |
+
tests_bar = "█" * passed + "░" * (total - passed)
|
| 363 |
+
|
| 364 |
+
# Color-coded action badge
|
| 365 |
+
action_color = "#8b5cf6" if step["action"] == "propose_fix" else "#3b82f6"
|
| 366 |
+
|
| 367 |
+
markdown_out.append(f"""
|
| 368 |
+
### 🔄 TURN {step['turn']}
|
| 369 |
+
---
|
| 370 |
+
|
| 371 |
+
* **🕵️ Observation:**
|
| 372 |
+
> {step['observation']}
|
| 373 |
+
* **💡 Hypothesis:**
|
| 374 |
+
> {step['hypothesis']}
|
| 375 |
+
* **🎯 Confidence:** `{step['confidence']}`
|
| 376 |
+
* **🛠️ Action:** <span style="background: {action_color}; color: white; padding: 2px 6px; border-radius: 4px; font-weight: bold; font-size: 0.85em;">{step['action']}</span>
|
| 377 |
+
|
| 378 |
+
**Proposed Fix / Detail:**
|
| 379 |
+
```python
|
| 380 |
+
{step['detail']}
|
| 381 |
+
```
|
| 382 |
|
| 383 |
+
**Sandbox Exec Results:**
|
| 384 |
+
* `Tests Passed`: **{passed} / {total}** `[{tests_bar}]`
|
| 385 |
+
* `Outcome`: **{"✅ SOLVED" if passed == total else "❌ STILL FAILING"}**
|
| 386 |
+
|
| 387 |
+
**Dense Reward Breakdown:**
|
| 388 |
+
- Format Compliance: `+{step['reward_breakdown'].get('format_compliance', 0.0):.3f}`
|
| 389 |
+
- Hypothesis Quality: `+{step['reward_breakdown'].get('hypothesis_quality', 0.0):.3f}`
|
| 390 |
+
- Localization: `+{step['reward_breakdown'].get('localization', 0.0):.3f}`
|
| 391 |
+
- Fix Quality: `+{step['reward_breakdown'].get('fix_quality', 0.0):.3f}`
|
| 392 |
+
- Semantic Similarity: `+{step['reward_breakdown'].get('semantic_similarity', 0.0):.3f}`
|
| 393 |
+
- **Turn Total Reward: {sum(v for k, v in step['reward_breakdown'].items() if k != 'total'):.3f}**
|
| 394 |
+
""")
|
| 395 |
+
|
| 396 |
+
return buggy_code, initial_error, "\n\n".join(markdown_out)
|
| 397 |
+
|
| 398 |
+
# ── Live sandbox execution handler ────────────────────────────────────────────
|
| 399 |
+
def run_sandbox_code(user_code, test_suite):
|
| 400 |
+
# Import execution sandbox dynamically
|
| 401 |
+
try:
|
| 402 |
+
from env.sandbox import execute_code
|
| 403 |
+
output, timed_out, exec_time = execute_code(user_code, test_suite)
|
| 404 |
+
status = "⏱️ Timed Out" if timed_out else f"✓ Run in {exec_time}ms"
|
| 405 |
+
return output, status
|
| 406 |
+
except Exception as e:
|
| 407 |
+
return f"Execution Error: {e}", "❌ Failed"
|
| 408 |
+
|
| 409 |
+
# ── Technical Report Reader ───────────────────────────────────────────────────
|
| 410 |
+
def read_technical_report():
|
| 411 |
+
report_path = "Blog.md"
|
| 412 |
+
if os.path.exists(report_path):
|
| 413 |
try:
|
| 414 |
+
with open(report_path, "r") as f:
|
| 415 |
+
return f.read()
|
|
|
|
|
|
|
| 416 |
except Exception:
|
| 417 |
pass
|
| 418 |
+
return "Technical report draft `Blog.md` not found."
|
| 419 |
+
|
| 420 |
+
# ── Gradio App Layout ─────────────────────────────────────────────────────────
|
| 421 |
+
eval_data = load_evaluation_data()
|
| 422 |
+
bug_options = get_trajectory_explorer_dropdowns(eval_data)
|
| 423 |
|
| 424 |
+
with gr.Blocks(title="AgentDebuggerEnv Research Hub") as demo:
|
| 425 |
+
|
| 426 |
+
# ── Header ────────────────────────────────────────────────────────────────
|
| 427 |
+
with gr.Group(elem_classes=["glass-header"]):
|
| 428 |
+
gr.Markdown(
|
| 429 |
+
"""
|
| 430 |
+
# 🐞 AgentDebuggerEnv
|
| 431 |
+
### Interactive Research Showcase & Leaderboard
|
| 432 |
+
*Aligning LLMs on Hypothesis-Driven Debugging using GRPO Reinforcement Learning*
|
| 433 |
+
""",
|
| 434 |
+
elem_classes=["header-title"]
|
| 435 |
)
|
| 436 |
+
|
| 437 |
+
with gr.Tabs():
|
| 438 |
+
# ── Tab 1: Trajectory Explorer ────────────────────────────────────────
|
| 439 |
+
with gr.TabItem("🕵️ Trajectory Explorer"):
|
| 440 |
+
gr.Markdown(
|
| 441 |
+
"""
|
| 442 |
+
### Interactive Bug Debugging Visualizer
|
| 443 |
+
Select a bug below to see how our fine-tuned **AgentDebugger-Qwen2.5-3B-GRPO** model localizes, hypothesizes, and patches the defect in a single step inside the sandboxed environment.
|
| 444 |
+
"""
|
| 445 |
+
)
|
| 446 |
+
with gr.Row():
|
| 447 |
+
with gr.Column(scale=1, elem_classes=["glass-panel"]):
|
| 448 |
+
bug_dropdown = gr.Dropdown(
|
| 449 |
+
choices=bug_options,
|
| 450 |
+
value=bug_options[0] if bug_options else None,
|
| 451 |
+
label="Choose a Curriculum Bug",
|
| 452 |
+
interactive=True
|
| 453 |
+
)
|
| 454 |
+
bug_code_viewer = gr.Code(
|
| 455 |
+
language="python",
|
| 456 |
+
label="Buggy Code Input",
|
| 457 |
+
interactive=False,
|
| 458 |
+
lines=12,
|
| 459 |
+
elem_classes=["code-container"]
|
| 460 |
+
)
|
| 461 |
+
error_msg_viewer = gr.Textbox(
|
| 462 |
+
label="Sandbox Initial Error Output",
|
| 463 |
+
interactive=False,
|
| 464 |
+
lines=3
|
| 465 |
+
)
|
| 466 |
+
with gr.Column(scale=2, elem_classes=["glass-panel"]):
|
| 467 |
+
gr.Markdown("### 🧠 Model Cognitive Loop Trajectory")
|
| 468 |
+
trajectory_output = gr.Markdown(value="Loading initial trajectory...")
|
| 469 |
|
| 470 |
+
# Wire up explorer update
|
| 471 |
+
def update_explorer(name):
|
| 472 |
+
code, err, traj = get_bug_details(name, eval_data)
|
| 473 |
+
return code, err, traj
|
| 474 |
|
| 475 |
+
bug_dropdown.change(
|
| 476 |
+
fn=update_explorer,
|
| 477 |
+
inputs=bug_dropdown,
|
| 478 |
+
outputs=[bug_code_viewer, error_msg_viewer, trajectory_output]
|
| 479 |
+
)
|
| 480 |
+
|
| 481 |
+
# Initial load callback
|
| 482 |
+
demo.load(
|
| 483 |
+
fn=lambda: update_explorer(bug_options[0]) if bug_options else ("", "", ""),
|
| 484 |
+
outputs=[bug_code_viewer, error_msg_viewer, trajectory_output]
|
| 485 |
+
)
|
| 486 |
|
| 487 |
+
# ── Tab 2: Leaderboard & Metrics ──────────────────────────────────────
|
| 488 |
+
with gr.TabItem("📊 Benchmark Leaderboard"):
|
| 489 |
+
gr.Markdown(
|
| 490 |
+
"""
|
| 491 |
+
### Benchmark Rankings on 90 Hand-Validated Bugs
|
| 492 |
+
We rank models based on their average score across 3 tiers of difficulty (Easy, Medium, Hard).
|
| 493 |
+
*Scores measure formatting, hypothesis accuracy, fault localization, and test suite pass rate.*
|
| 494 |
+
"""
|
| 495 |
+
)
|
| 496 |
+
leaderboard_frame = gr.HTML(value=render_leaderboard_html(eval_data.get("summary", DEFAULT_STATS["summary"])))
|
| 497 |
+
|
| 498 |
+
with gr.Row(elem_classes=["glass-panel", "mt-8"]):
|
| 499 |
+
with gr.Column():
|
| 500 |
+
gr.Markdown(
|
| 501 |
+
"""
|
| 502 |
+
### 📈 Training Learning Curves (GRPO)
|
| 503 |
+
Our reinforcement learning runs demonstrate rapid policy adaptation of Qwen-3B-Coder:
|
| 504 |
+
- **Format compliance**: Hit 1.0 (max) within the first 50 steps.
|
| 505 |
+
- **Total Reward**: Climbed from baseline ~0.4 to peaks of ~1.0 by step 250.
|
| 506 |
+
- **Curriculum Transition**: Textbook drop-and-recover curve at step 150 (Tier 2 escalation).
|
| 507 |
+
"""
|
| 508 |
+
)
|
| 509 |
+
with gr.Column():
|
| 510 |
+
# Display metrics images from repo
|
| 511 |
+
gr.Image("images/total.png", label="GRPO Total Reward Curve")
|
| 512 |
+
gr.Image("images/format_compliance.png", label="Format Compliance Curve")
|
| 513 |
|
| 514 |
+
# ── Tab 3: Sandbox Playground ─────────────────────────────────────────
|
| 515 |
+
with gr.TabItem("🛡️ Sandbox Playground"):
|
| 516 |
+
gr.Markdown(
|
| 517 |
+
"""
|
| 518 |
+
### Hardened Sandbox Execution Environment
|
| 519 |
+
Test arbitrary Python code against custom tests. Our execution sandbox enforces CPU limits (10s), memory limits (256MB), and blocks unsafe functions.
|
| 520 |
+
"""
|
| 521 |
+
)
|
| 522 |
+
with gr.Row():
|
| 523 |
+
with gr.Column(scale=1, elem_classes=["glass-panel"]):
|
| 524 |
+
user_code = gr.Code(
|
| 525 |
+
language="python",
|
| 526 |
+
label="Python Code",
|
| 527 |
+
value="def add(a, b):\n return a + b",
|
| 528 |
+
lines=10,
|
| 529 |
+
elem_classes=["code-container"]
|
| 530 |
+
)
|
| 531 |
+
test_suite_code = gr.Code(
|
| 532 |
+
language="python",
|
| 533 |
+
label="Test Assertions (must print PASS or FAIL)",
|
| 534 |
+
value="assert add(2, 3) == 5\nprint('PASS')",
|
| 535 |
+
lines=5,
|
| 536 |
+
elem_classes=["code-container"]
|
| 537 |
+
)
|
| 538 |
+
run_btn = gr.Button("🚀 Run in Sandbox", elem_classes=["accent-btn"])
|
| 539 |
+
with gr.Column(scale=1, elem_classes=["glass-panel"]):
|
| 540 |
+
sandbox_status = gr.Textbox(label="Sandbox Status", value="Ready")
|
| 541 |
+
sandbox_stdout = gr.Code(
|
| 542 |
+
label="Terminal Output (Stdout/Stderr)",
|
| 543 |
+
interactive=False,
|
| 544 |
+
lines=15,
|
| 545 |
+
elem_classes=["code-container"]
|
| 546 |
+
)
|
| 547 |
+
|
| 548 |
+
run_btn.click(
|
| 549 |
+
fn=run_sandbox_code,
|
| 550 |
+
inputs=[user_code, test_suite_code],
|
| 551 |
+
outputs=[sandbox_stdout, sandbox_status]
|
| 552 |
+
)
|
| 553 |
+
|
| 554 |
+
# ── Tab 4: Technical Report ───────────────────────────────────────────
|
| 555 |
+
with gr.TabItem("📝 Technical Report"):
|
| 556 |
+
gr.Markdown(
|
| 557 |
+
"""
|
| 558 |
+
### Research Writeup & Key Insights
|
| 559 |
+
Read our draft paper detailing the project context, reward shaping formulations, and empirical comparisons.
|
| 560 |
+
"""
|
| 561 |
+
)
|
| 562 |
+
with gr.Group(elem_classes=["glass-panel"]):
|
| 563 |
+
gr.Markdown(value=read_technical_report())
|
| 564 |
|
|
|
|
|
|
|
| 565 |
gr.Markdown(
|
| 566 |
"""
|
| 567 |
+
---
|
| 568 |
+
<p align="center">
|
| 569 |
+
Submitted to the <b>Meta + PyTorch + Hugging Face OpenEnv Hackathon</b> |
|
| 570 |
+
<a href="https://github.com/shasshaank/meta_hackthon" target="_blank">View GitHub Repository</a>
|
| 571 |
+
</p>
|
|
|
|
| 572 |
"""
|
| 573 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 574 |
|
| 575 |
+
if __name__ == "__main__":
|
| 576 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, css=CUSTOM_CSS)
|
env/environment.py
CHANGED
|
@@ -314,6 +314,7 @@ class DebuggerEnvironment:
|
|
| 314 |
"""Run proposed fix against test cases with timeout. NEVER execute without timeout."""
|
| 315 |
import subprocess
|
| 316 |
import tempfile
|
|
|
|
| 317 |
|
| 318 |
if not proposed_code or not bug.get("test_cases"):
|
| 319 |
return {"passed": 0, "failed": 0, "total": 0, "newly_broken": 0}
|
|
@@ -344,7 +345,7 @@ except Exception as e:
|
|
| 344 |
fname = f.name
|
| 345 |
|
| 346 |
result = subprocess.run(
|
| 347 |
-
[
|
| 348 |
capture_output=True, text=True, timeout=5
|
| 349 |
)
|
| 350 |
|
|
|
|
| 314 |
"""Run proposed fix against test cases with timeout. NEVER execute without timeout."""
|
| 315 |
import subprocess
|
| 316 |
import tempfile
|
| 317 |
+
import sys
|
| 318 |
|
| 319 |
if not proposed_code or not bug.get("test_cases"):
|
| 320 |
return {"passed": 0, "failed": 0, "total": 0, "newly_broken": 0}
|
|
|
|
| 345 |
fname = f.name
|
| 346 |
|
| 347 |
result = subprocess.run(
|
| 348 |
+
[sys.executable, fname],
|
| 349 |
capture_output=True, text=True, timeout=5
|
| 350 |
)
|
| 351 |
|
evaluate_model.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import torch
|
| 4 |
+
import sys
|
| 5 |
+
import argparse
|
| 6 |
+
from tqdm import tqdm
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 9 |
+
from peft import PeftModel
|
| 10 |
+
|
| 11 |
+
# Load environment variables
|
| 12 |
+
load_dotenv()
|
| 13 |
+
|
| 14 |
+
# Insert workspace root to path
|
| 15 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 16 |
+
from env.environment import DebuggerEnvironment
|
| 17 |
+
from env.models import parse_agent_output
|
| 18 |
+
from server.reward_calculator import DebugRewardCalculator
|
| 19 |
+
|
| 20 |
+
# System prompt matching train_grpo.py
|
| 21 |
+
SYSTEM_PROMPT = """You are an expert Python debugger. You reason through bugs systematically.
|
| 22 |
+
|
| 23 |
+
You MUST respond in EXACTLY this format — no exceptions, no extra text:
|
| 24 |
+
|
| 25 |
+
OBSERVATION: [Specific observations about the code and error. Reference exact line numbers.]
|
| 26 |
+
HYPOTHESIS: [Your theory about the root cause. Must be at least 2 sentences. Reference specific variable names, operators, or logic.]
|
| 27 |
+
CONFIDENCE: [low | medium | high]
|
| 28 |
+
ACTION: [One of: inspect_lines | run_tests | propose_fix | request_context | give_up]
|
| 29 |
+
DETAIL: [For propose_fix: the complete corrected function code. For inspect_lines: line numbers. For others: specific details.]
|
| 30 |
+
|
| 31 |
+
Rules:
|
| 32 |
+
- Never omit any field
|
| 33 |
+
- HYPOTHESIS must explain WHY the bug causes the observed failure
|
| 34 |
+
- If proposing a fix, DETAIL must contain the complete function, not just the changed line
|
| 35 |
+
- Give up only if you have exhausted all reasonable hypotheses"""
|
| 36 |
+
|
| 37 |
+
def bug_to_prompt(bug: dict) -> str:
|
| 38 |
+
return (
|
| 39 |
+
f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
|
| 40 |
+
f"<|im_start|>user\n"
|
| 41 |
+
f"Debug this Python function:\n\n```python\n{bug['buggy_code']}\n```\n\n"
|
| 42 |
+
f"Initial failure: {bug.get('initial_error', 'Some tests are failing.')}\n"
|
| 43 |
+
f"<|im_end|>\n"
|
| 44 |
+
f"<|im_start|>assistant\n"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
def main():
|
| 48 |
+
parser = argparse.ArgumentParser()
|
| 49 |
+
parser.add_argument("--limit", type=int, default=None, help="Limit number of bugs to test per tier")
|
| 50 |
+
parser.add_argument("--adapter", type=str, default="shashaank0707/AgentDebugger-trained", help="Hugging Face repo or local path of the adapter")
|
| 51 |
+
parser.add_argument("--base-model", type=str, default="Qwen/Qwen2.5-Coder-3B-Instruct", help="Base model identifier")
|
| 52 |
+
args = parser.parse_args()
|
| 53 |
+
|
| 54 |
+
# Verify HF Token if repository is private
|
| 55 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 56 |
+
if not hf_token:
|
| 57 |
+
print("WARNING: HF_TOKEN environment variable not set. Loading a private repository might fail.")
|
| 58 |
+
|
| 59 |
+
print(f"Loading base model: {args.base_model}...")
|
| 60 |
+
device = "mps" if torch.backends.mps.is_available() else ("cuda" if torch.cuda.is_available() else "cpu")
|
| 61 |
+
dtype = torch.float32 if device == "cpu" else torch.float16
|
| 62 |
+
print(f"Using device: {device} | dtype: {dtype}")
|
| 63 |
+
|
| 64 |
+
try:
|
| 65 |
+
tokenizer = AutoTokenizer.from_pretrained(args.base_model, trust_remote_code=True)
|
| 66 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 67 |
+
tokenizer.padding_side = "left"
|
| 68 |
+
|
| 69 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 70 |
+
args.base_model,
|
| 71 |
+
torch_dtype=dtype,
|
| 72 |
+
trust_remote_code=True,
|
| 73 |
+
device_map="auto" if device == "cuda" else None
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
print(f"Loading LoRA adapter: {args.adapter}...")
|
| 77 |
+
model = PeftModel.from_pretrained(
|
| 78 |
+
base_model,
|
| 79 |
+
args.adapter,
|
| 80 |
+
token=hf_token
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# Explicitly move to target device if using MPS or CPU
|
| 84 |
+
if device in ["mps", "cpu"]:
|
| 85 |
+
print(f"Moving model to target device: {device}...")
|
| 86 |
+
model = model.to(device)
|
| 87 |
+
|
| 88 |
+
model.eval()
|
| 89 |
+
except Exception as e:
|
| 90 |
+
print(f"ERROR loading model: {e}")
|
| 91 |
+
print("Please ensure your HF_TOKEN is valid and set in your .env file.")
|
| 92 |
+
sys.exit(1)
|
| 93 |
+
|
| 94 |
+
print("\nInitializing environment and loading bugs...")
|
| 95 |
+
env = DebuggerEnvironment()
|
| 96 |
+
calculator = DebugRewardCalculator()
|
| 97 |
+
|
| 98 |
+
results = {}
|
| 99 |
+
summary = {
|
| 100 |
+
"model": args.adapter,
|
| 101 |
+
"base_model": args.base_model,
|
| 102 |
+
"tiers": {}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
total_bugs_count = 0
|
| 106 |
+
solved_bugs_count = 0
|
| 107 |
+
|
| 108 |
+
for tier in [1, 2, 3]:
|
| 109 |
+
path = f"data/bugs_tier{tier}.jsonl"
|
| 110 |
+
if not os.path.exists(path):
|
| 111 |
+
print(f"Skipping Tier {tier} - file not found at {path}")
|
| 112 |
+
continue
|
| 113 |
+
|
| 114 |
+
print(f"\nEvaluating Tier {tier} bugs...")
|
| 115 |
+
bugs = []
|
| 116 |
+
with open(path) as f:
|
| 117 |
+
for line in f:
|
| 118 |
+
if line.strip():
|
| 119 |
+
bugs.append(json.loads(line))
|
| 120 |
+
|
| 121 |
+
if args.limit:
|
| 122 |
+
bugs = bugs[:args.limit]
|
| 123 |
+
|
| 124 |
+
tier_results = []
|
| 125 |
+
tier_solved = 0
|
| 126 |
+
|
| 127 |
+
for bug in tqdm(bugs):
|
| 128 |
+
# Setup environment context for this bug
|
| 129 |
+
env.current_bug = bug
|
| 130 |
+
env.current_episode_trajectory = []
|
| 131 |
+
env.turn_number = 0
|
| 132 |
+
|
| 133 |
+
# Generate prompt
|
| 134 |
+
prompt = bug_to_prompt(bug)
|
| 135 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 136 |
+
|
| 137 |
+
with torch.no_grad():
|
| 138 |
+
out = model.generate(
|
| 139 |
+
**inputs,
|
| 140 |
+
max_new_tokens=300,
|
| 141 |
+
do_sample=False
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
completion = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 145 |
+
|
| 146 |
+
# Step the environment with model's completion
|
| 147 |
+
step_result = env.step_curriculum(completion)
|
| 148 |
+
info = step_result["info"]
|
| 149 |
+
reward_breakdown = info["reward_breakdown"]
|
| 150 |
+
solved = info["solved"]
|
| 151 |
+
|
| 152 |
+
if solved:
|
| 153 |
+
tier_solved += 1
|
| 154 |
+
solved_bugs_count += 1
|
| 155 |
+
total_bugs_count += 1
|
| 156 |
+
|
| 157 |
+
# Store details
|
| 158 |
+
bug_detail = {
|
| 159 |
+
"id": bug.get("id"),
|
| 160 |
+
"function_name": bug.get("function_name"),
|
| 161 |
+
"bug_type": bug.get("bug_type"),
|
| 162 |
+
"difficulty": bug.get("difficulty"),
|
| 163 |
+
"prompt": prompt,
|
| 164 |
+
"raw_completion": completion,
|
| 165 |
+
"parsed_action": {
|
| 166 |
+
"observation": info["history"][-1]["action"] if "history" in info and info["history"] else "unknown",
|
| 167 |
+
"solved": solved,
|
| 168 |
+
},
|
| 169 |
+
"reward": step_result["reward"],
|
| 170 |
+
"reward_breakdown": reward_breakdown,
|
| 171 |
+
"test_results": step_result["observation"]["test_results"],
|
| 172 |
+
"solved": solved
|
| 173 |
+
}
|
| 174 |
+
tier_results.append(bug_detail)
|
| 175 |
+
|
| 176 |
+
tier_solve_rate = tier_solved / len(bugs) if bugs else 0.0
|
| 177 |
+
print(f"Tier {tier} Solve Rate: {tier_solve_rate:.1%} ({tier_solved}/{len(bugs)})")
|
| 178 |
+
|
| 179 |
+
results[f"tier{tier}"] = tier_results
|
| 180 |
+
summary["tiers"][f"tier{tier}"] = {
|
| 181 |
+
"total": len(bugs),
|
| 182 |
+
"solved": tier_solved,
|
| 183 |
+
"solve_rate": tier_solve_rate,
|
| 184 |
+
"mean_reward": sum(r["reward"] for r in tier_results) / len(tier_results) if tier_results else 0.0
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
summary["overall"] = {
|
| 188 |
+
"total": total_bugs_count,
|
| 189 |
+
"solved": solved_bugs_count,
|
| 190 |
+
"solve_rate": solved_bugs_count / total_bugs_count if total_bugs_count else 0.0,
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
# Save to file
|
| 194 |
+
output = {
|
| 195 |
+
"summary": summary,
|
| 196 |
+
"results": results
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
with open("evaluation_results.json", "w") as f:
|
| 200 |
+
json.dump(output, f, indent=2)
|
| 201 |
+
|
| 202 |
+
print("\n==========================================")
|
| 203 |
+
print("EVALUATION COMPLETE!")
|
| 204 |
+
print(f"Overall Solve Rate: {summary['overall']['solve_rate']:.1%} ({solved_bugs_count}/{total_bugs_count})")
|
| 205 |
+
print("Saved all results to evaluation_results.json")
|
| 206 |
+
print("==========================================")
|
| 207 |
+
|
| 208 |
+
if __name__ == "__main__":
|
| 209 |
+
main()
|
evaluation_results.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
leaderboard/index.html
CHANGED
|
@@ -216,39 +216,39 @@
|
|
| 216 |
</div>
|
| 217 |
</td>
|
| 218 |
</tr>
|
| 219 |
-
<tr>
|
| 220 |
<td>🥈 2</td>
|
| 221 |
<td>
|
| 222 |
-
<div class="model-name">
|
| 223 |
-
|
| 224 |
-
<span class="badge">
|
| 225 |
</div>
|
| 226 |
</td>
|
| 227 |
-
<td class="tier-score">
|
| 228 |
-
<td class="tier-score">
|
| 229 |
-
<td class="tier-score">
|
| 230 |
<td>
|
| 231 |
-
<div class="score-value">0.
|
| 232 |
<div class="score-bar-container">
|
| 233 |
-
<div class="score-bar" style="width:
|
| 234 |
</div>
|
| 235 |
</td>
|
| 236 |
</tr>
|
| 237 |
<tr>
|
| 238 |
-
<td>
|
| 239 |
<td>
|
| 240 |
<div class="model-name">
|
| 241 |
-
|
| 242 |
-
<span class="badge" style="background: var(--
|
| 243 |
</div>
|
| 244 |
</td>
|
| 245 |
-
<td class="tier-score">
|
| 246 |
-
<td class="tier-score">
|
| 247 |
-
<td class="tier-score">
|
| 248 |
<td>
|
| 249 |
-
<div class="score-value"
|
| 250 |
<div class="score-bar-container">
|
| 251 |
-
<div class="score-bar" style="width: 0%; background: var(--text-secondary)"></div>
|
| 252 |
</div>
|
| 253 |
</td>
|
| 254 |
</tr>
|
|
|
|
| 216 |
</div>
|
| 217 |
</td>
|
| 218 |
</tr>
|
| 219 |
+
<tr style="background: rgba(139, 92, 246, 0.05); border: 1px solid rgba(139, 92, 246, 0.2);">
|
| 220 |
<td>🥈 2</td>
|
| 221 |
<td>
|
| 222 |
+
<div class="model-name" style="color: #a78bfa;">
|
| 223 |
+
AgentDebugger-Qwen2.5-3B-GRPO
|
| 224 |
+
<span class="badge" style="background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary))">Trained</span>
|
| 225 |
</div>
|
| 226 |
</td>
|
| 227 |
+
<td class="tier-score" style="color: var(--success); font-weight: bold;">100.0%</td>
|
| 228 |
+
<td class="tier-score" style="color: var(--success); font-weight: bold;">77.4%</td>
|
| 229 |
+
<td class="tier-score" style="color: var(--warning); font-weight: bold;">38.1%</td>
|
| 230 |
<td>
|
| 231 |
+
<div class="score-value" style="color: #a78bfa;">0.718</div>
|
| 232 |
<div class="score-bar-container">
|
| 233 |
+
<div class="score-bar" style="width: 71.8%; background: linear-gradient(90deg, var(--accent-primary), #ec4899);"></div>
|
| 234 |
</div>
|
| 235 |
</td>
|
| 236 |
</tr>
|
| 237 |
<tr>
|
| 238 |
+
<td>🥉 3</td>
|
| 239 |
<td>
|
| 240 |
<div class="model-name">
|
| 241 |
+
Llama-3.1-70B-Instruct
|
| 242 |
+
<span class="badge" style="background: var(--text-secondary)">Baseline</span>
|
| 243 |
</div>
|
| 244 |
</td>
|
| 245 |
+
<td class="tier-score">21.0%</td>
|
| 246 |
+
<td class="tier-score">21.5%</td>
|
| 247 |
+
<td class="tier-score">21.5%</td>
|
| 248 |
<td>
|
| 249 |
+
<div class="score-value">0.210</div>
|
| 250 |
<div class="score-bar-container">
|
| 251 |
+
<div class="score-bar" style="width: 21.0%; background: var(--text-secondary);"></div>
|
| 252 |
</div>
|
| 253 |
</td>
|
| 254 |
</tr>
|
requirements.txt
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
# and overwrite the CUDA-enabled torch from the base image.
|
|
|
|
| 1 |
+
python-dotenv
|
| 2 |
+
requests
|
| 3 |
+
gradio
|
|
|