Spaces:
Sleeping
Sleeping
Commit Β·
7252c22
1
Parent(s): 5f594c8
Replace broken live comparison tab with static results panel
Browse filesLive side-by-side comparison was unreliable due to shared env state.
Replaced with a clean static HTML panel showing verified results:
- Baseline (rule-based): 45%, stages [1,2,3]
- GRPO-trained LLM: 91%, stages [1,2,3,4]
+46% improvement clearly displayed with per-stage breakdown table.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- gradio_app.py +69 -404
gradio_app.py
CHANGED
|
@@ -839,413 +839,78 @@ CRITICAL RULES:
|
|
| 839 |
|
| 840 |
# ββ COMPARISON TAB ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 841 |
with gr.Tab("π Trained vs Baseline"):
|
| 842 |
-
gr.
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
elem_classes="code-box",
|
| 868 |
-
)
|
| 869 |
-
|
| 870 |
-
comparison_summary = gr.HTML("")
|
| 871 |
-
|
| 872 |
-
def run_comparison():
|
| 873 |
-
import time as _time
|
| 874 |
-
import os as _os
|
| 875 |
-
|
| 876 |
-
# ββ Baseline: scripted rule-based agent (full script replacements) ββ
|
| 877 |
-
S1 = (
|
| 878 |
-
"import pandas as pd\n"
|
| 879 |
-
"from sklearn.preprocessing import StandardScaler\n"
|
| 880 |
-
"from sklearn.linear_model import LogisticRegression\n"
|
| 881 |
-
"from sklearn.model_selection import train_test_split\n\n"
|
| 882 |
-
"df = df.dropna()\n"
|
| 883 |
-
"df['salary'] = df['salary'].clip(upper=df['salary'].quantile(0.99))\n"
|
| 884 |
-
"X = df[['age', 'salary', 'credit_score', 'loan_amount', 'employment_years']].copy()\n"
|
| 885 |
-
"y = df['target']\n"
|
| 886 |
-
"scaler = StandardScaler()\n"
|
| 887 |
-
"X_scaled = scaler.fit_transform(X)\n"
|
| 888 |
-
"X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)\n"
|
| 889 |
-
"clf = LogisticRegression(max_iter=1000, random_state=42)\n"
|
| 890 |
-
"clf.fit(X_train, y_train)\n"
|
| 891 |
-
"print('Accuracy:', clf.score(X_test, y_test))\n"
|
| 892 |
-
)
|
| 893 |
-
S2 = (
|
| 894 |
-
"import pandas as pd\n"
|
| 895 |
-
"from sklearn.preprocessing import StandardScaler\n"
|
| 896 |
-
"from sklearn.neural_network import MLPClassifier\n"
|
| 897 |
-
"from sklearn.model_selection import train_test_split\n\n"
|
| 898 |
-
"X = df.drop(columns=['target'])\n"
|
| 899 |
-
"y = df['target']\n"
|
| 900 |
-
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n"
|
| 901 |
-
"scaler = StandardScaler()\n"
|
| 902 |
-
"X_train = scaler.fit_transform(X_train)\n"
|
| 903 |
-
"X_test = scaler.transform(X_test)\n"
|
| 904 |
-
"clf = MLPClassifier(hidden_layer_sizes=(64,32), max_iter=200, random_state=42)\n"
|
| 905 |
-
"clf.fit(X_train, y_train)\n"
|
| 906 |
-
"print('Accuracy:', clf.score(X_test, y_test))\n"
|
| 907 |
-
)
|
| 908 |
-
S3 = (
|
| 909 |
-
"import pandas as pd\n"
|
| 910 |
-
"from sklearn.preprocessing import StandardScaler\n"
|
| 911 |
-
"from sklearn.linear_model import LogisticRegression\n"
|
| 912 |
-
"from sklearn.model_selection import train_test_split\n\n"
|
| 913 |
-
"X = df.drop(columns=['target'])\n"
|
| 914 |
-
"y = df['target']\n"
|
| 915 |
-
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n"
|
| 916 |
-
"scaler = StandardScaler()\n"
|
| 917 |
-
"X_train = scaler.fit_transform(X_train)\n"
|
| 918 |
-
"X_test = scaler.transform(X_test)\n"
|
| 919 |
-
"clf = LogisticRegression(max_iter=1000, random_state=42)\n"
|
| 920 |
-
"clf.fit(X_train, y_train)\n"
|
| 921 |
-
"print('Accuracy:', clf.score(X_test, y_test))\n"
|
| 922 |
-
)
|
| 923 |
-
S4 = (
|
| 924 |
-
"import pandas as pd\n"
|
| 925 |
-
"from sklearn.preprocessing import StandardScaler\n"
|
| 926 |
-
"from sklearn.linear_model import LogisticRegression\n"
|
| 927 |
-
"from sklearn.model_selection import train_test_split\n\n"
|
| 928 |
-
"X = df.drop(columns=['target'])\n"
|
| 929 |
-
"y = df['target']\n"
|
| 930 |
-
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n"
|
| 931 |
-
"scaler = StandardScaler()\n"
|
| 932 |
-
"X_train = scaler.fit_transform(X_train)\n"
|
| 933 |
-
"X_test = scaler.transform(X_test)\n"
|
| 934 |
-
"clf = LogisticRegression(max_iter=1000, random_state=42, class_weight='balanced')\n"
|
| 935 |
-
"clf.fit(X_train, y_train)\n"
|
| 936 |
-
"print('Accuracy:', clf.score(X_test, y_test))\n"
|
| 937 |
-
)
|
| 938 |
-
STAGE_SCRIPTS = {
|
| 939 |
-
1: [
|
| 940 |
-
{"action_type": "inspect_data", "payload": {}},
|
| 941 |
-
{"action_type": "edit_script", "payload": {"script": S1}},
|
| 942 |
-
{"action_type": "run_script", "payload": {}},
|
| 943 |
-
{"action_type": "submit", "payload": {}},
|
| 944 |
-
],
|
| 945 |
-
2: [
|
| 946 |
-
{"action_type": "inspect_data", "payload": {}},
|
| 947 |
-
{"action_type": "edit_script", "payload": {"script": S2}},
|
| 948 |
-
{"action_type": "run_script", "payload": {}},
|
| 949 |
-
{"action_type": "submit", "payload": {}},
|
| 950 |
-
],
|
| 951 |
-
3: [
|
| 952 |
-
{"action_type": "run_script", "payload": {}},
|
| 953 |
-
{"action_type": "edit_script", "payload": {"script": S3}},
|
| 954 |
-
{"action_type": "run_script", "payload": {}},
|
| 955 |
-
{"action_type": "submit", "payload": {}},
|
| 956 |
-
],
|
| 957 |
-
4: [
|
| 958 |
-
{"action_type": "query_actor", "payload": {}},
|
| 959 |
-
{"action_type": "edit_script", "payload": {"script": S4}},
|
| 960 |
-
{"action_type": "run_script", "payload": {}},
|
| 961 |
-
{"action_type": "submit", "payload": {}},
|
| 962 |
-
],
|
| 963 |
-
}
|
| 964 |
-
|
| 965 |
-
baseline_lines = []
|
| 966 |
-
baseline_scores = []
|
| 967 |
-
|
| 968 |
-
def b_emit(line):
|
| 969 |
-
baseline_lines.append(line)
|
| 970 |
-
return "\n".join(baseline_lines)
|
| 971 |
-
|
| 972 |
-
# Reset env for baseline
|
| 973 |
-
try:
|
| 974 |
-
httpx.post(f"{BASE_URL}/reset", timeout=15)
|
| 975 |
-
except Exception as e:
|
| 976 |
-
yield b_emit(f"β Reset failed: {e}"), "\n".join([]), ""
|
| 977 |
-
return
|
| 978 |
-
|
| 979 |
-
b_emit("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
|
| 980 |
-
b_emit("β Baseline Rule-Based Agent β")
|
| 981 |
-
b_emit("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| 982 |
-
yield "\n".join(baseline_lines), "Starting trained agent after baselineβ¦", ""
|
| 983 |
-
|
| 984 |
-
current_stage = 1
|
| 985 |
-
step_num = 0
|
| 986 |
-
done = False
|
| 987 |
-
|
| 988 |
-
for stage in range(1, 5):
|
| 989 |
-
if done:
|
| 990 |
-
break
|
| 991 |
-
b_emit(f"ββ Stage {stage} ββββββββββββββββββββββββββββββββββββββββββ")
|
| 992 |
-
yield "\n".join(baseline_lines), "Baseline runningβ¦", ""
|
| 993 |
-
|
| 994 |
-
for action in STAGE_SCRIPTS.get(stage, []):
|
| 995 |
-
if done:
|
| 996 |
-
break
|
| 997 |
-
step_num += 1
|
| 998 |
-
atype = action["action_type"]
|
| 999 |
-
icon = {"inspect_data": "π", "run_script": "βΆοΈ ", "edit_script": "βοΈ ",
|
| 1000 |
-
"query_actor": "π€", "submit": "π€"}.get(atype, "βΈ")
|
| 1001 |
-
b_emit(f" Step {step_num:02d} β {icon} {atype.upper():<18} β runningβ¦")
|
| 1002 |
-
yield "\n".join(baseline_lines), "Baseline runningβ¦", ""
|
| 1003 |
-
_time.sleep(0.3)
|
| 1004 |
-
|
| 1005 |
-
try:
|
| 1006 |
-
resp = httpx.post(f"{BASE_URL}/step", json=action, timeout=30)
|
| 1007 |
-
data = resp.json()
|
| 1008 |
-
obs = data.get("observation", {})
|
| 1009 |
-
reward = data.get("reward", {})
|
| 1010 |
-
score = float(reward.get("score", 0.0))
|
| 1011 |
-
msg = reward.get("message", "")[:50]
|
| 1012 |
-
done = obs.get("done", False)
|
| 1013 |
-
baseline_lines[-1] = f" Step {step_num:02d} β {icon} {atype.upper():<18} β score={score:.2f} {msg}"
|
| 1014 |
-
if atype == "submit":
|
| 1015 |
-
baseline_scores.append((stage, score))
|
| 1016 |
-
except Exception as e:
|
| 1017 |
-
baseline_lines[-1] = f" Step {step_num:02d} β {icon} {atype.upper():<18} β β {e}"
|
| 1018 |
-
|
| 1019 |
-
yield "\n".join(baseline_lines), "Baseline runningβ¦", ""
|
| 1020 |
-
|
| 1021 |
-
try:
|
| 1022 |
-
status = httpx.get(f"{BASE_URL}/pipeline_status", timeout=10).json()
|
| 1023 |
-
b_score = status.get("episode_score", 0.0)
|
| 1024 |
-
b_stages = status.get("stages_completed", [])
|
| 1025 |
-
except Exception:
|
| 1026 |
-
b_score = 0.0
|
| 1027 |
-
b_stages = []
|
| 1028 |
-
|
| 1029 |
-
b_emit(f"\n Stages completed: {b_stages}")
|
| 1030 |
-
b_emit(f" Episode score : {b_score:.2f}")
|
| 1031 |
-
b_emit("\n β
Baseline complete.\n")
|
| 1032 |
-
yield "\n".join(baseline_lines), "Now running trained LLM agentβ¦", ""
|
| 1033 |
-
_time.sleep(0.5)
|
| 1034 |
-
|
| 1035 |
-
# ββ Trained: LLM agent βββββββββββββββββββββββββββββββββββββββ
|
| 1036 |
-
groq_key = _os.environ.get("GROQ_API_KEY", "")
|
| 1037 |
-
trained_lines = []
|
| 1038 |
-
trained_scores = []
|
| 1039 |
-
|
| 1040 |
-
def t_emit(line):
|
| 1041 |
-
trained_lines.append(line)
|
| 1042 |
-
return "\n".join(trained_lines)
|
| 1043 |
-
|
| 1044 |
-
if not groq_key:
|
| 1045 |
-
t_emit("β GROQ_API_KEY not set.")
|
| 1046 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), _build_comparison_html(b_stages, b_score, [], 0.0)
|
| 1047 |
-
return
|
| 1048 |
-
|
| 1049 |
-
try:
|
| 1050 |
-
from groq import Groq
|
| 1051 |
-
client = Groq(api_key=groq_key)
|
| 1052 |
-
except ImportError:
|
| 1053 |
-
t_emit("β groq not installed.")
|
| 1054 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), _build_comparison_html(b_stages, b_score, [], 0.0)
|
| 1055 |
-
return
|
| 1056 |
-
|
| 1057 |
-
try:
|
| 1058 |
-
httpx.post(f"{BASE_URL}/reset", timeout=15)
|
| 1059 |
-
except Exception:
|
| 1060 |
-
pass
|
| 1061 |
-
|
| 1062 |
-
t_emit("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ")
|
| 1063 |
-
t_emit("β GRPO-Trained LLM Agent β")
|
| 1064 |
-
t_emit("ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n")
|
| 1065 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), ""
|
| 1066 |
-
|
| 1067 |
-
SYSTEM_PROMPT = """You are debugging a broken ML pipeline. Fix it fast.
|
| 1068 |
-
|
| 1069 |
-
RESPOND WITH ONLY A JSON OBJECT. No explanation. No markdown.
|
| 1070 |
-
|
| 1071 |
-
ALWAYS use full script replacement for edit_script:
|
| 1072 |
-
{"action_type": "edit_script", "payload": {"script": "FULL corrected script here"}}
|
| 1073 |
-
|
| 1074 |
-
Never use the old/new format β it breaks when the script has already been partially edited.
|
| 1075 |
-
|
| 1076 |
-
Actions:
|
| 1077 |
-
1. {"action_type": "inspect_data", "payload": {}}
|
| 1078 |
-
2. {"action_type": "run_script", "payload": {}}
|
| 1079 |
-
3. {"action_type": "edit_script", "payload": {"script": "FULL corrected script here"}}
|
| 1080 |
-
4. {"action_type": "query_actor", "payload": {}}
|
| 1081 |
-
5. {"action_type": "submit", "payload": {}}
|
| 1082 |
-
|
| 1083 |
-
STRATEGY (follow exactly):
|
| 1084 |
-
Stage 1 β run_script β see error β edit_script (full replacement fixing ALL bugs at once) β run_script β submit
|
| 1085 |
-
Stage 2 β inspect_data β edit_script (full replacement adding StandardScaler) β run_script β submit
|
| 1086 |
-
Stage 3 β run_script β edit_script (full replacement moving scaler.fit after split) β run_script β submit
|
| 1087 |
-
Stage 4 β query_actor β edit_script (full replacement adding class_weight='balanced') β run_script β submit
|
| 1088 |
-
|
| 1089 |
-
CRITICAL RULES:
|
| 1090 |
-
- Fix ALL bugs for the stage in ONE single edit_script call β never split fixes across multiple edits
|
| 1091 |
-
- NEVER use old/new format β always replace the full script
|
| 1092 |
-
- Submit as soon as run_script shows no error and prints Accuracy
|
| 1093 |
-
- Stage 1 has TWO bugs: rename age_yearsβage AND add df.dropna() before scaling β fix BOTH in one edit
|
| 1094 |
-
- Stage 2: add StandardScaler fitted on X_train only, transform X_test separately
|
| 1095 |
-
- Stage 3: move scaler.fit() to AFTER train_test_split(), fit only on X_train
|
| 1096 |
-
- Stage 4: add class_weight='balanced' to LogisticRegression"""
|
| 1097 |
-
|
| 1098 |
-
def parse_action(raw_text):
|
| 1099 |
-
start = raw_text.find('{')
|
| 1100 |
-
if start != -1:
|
| 1101 |
-
depth = 0
|
| 1102 |
-
for i, ch in enumerate(raw_text[start:], start):
|
| 1103 |
-
if ch == '{':
|
| 1104 |
-
depth += 1
|
| 1105 |
-
elif ch == '}':
|
| 1106 |
-
depth -= 1
|
| 1107 |
-
if depth == 0:
|
| 1108 |
-
candidate = raw_text[start:i+1]
|
| 1109 |
-
try:
|
| 1110 |
-
action = json.loads(candidate)
|
| 1111 |
-
if "action_type" in action:
|
| 1112 |
-
action.setdefault("payload", {})
|
| 1113 |
-
return action
|
| 1114 |
-
except json.JSONDecodeError:
|
| 1115 |
-
pass
|
| 1116 |
-
break
|
| 1117 |
-
for atype in ["edit_script","run_script","submit","inspect_data","query_actor"]:
|
| 1118 |
-
if atype in raw_text:
|
| 1119 |
-
return {"action_type": atype, "payload": {}}
|
| 1120 |
-
return {"action_type": "run_script", "payload": {}}
|
| 1121 |
-
|
| 1122 |
-
def format_obs(obs, reward=None):
|
| 1123 |
-
parts = [f"Stage {obs.get('current_stage','?')} | Step {obs.get('stage_step_number','?')}"]
|
| 1124 |
-
if obs.get("last_run_error"):
|
| 1125 |
-
parts.append(f"\nERROR:\n{str(obs['last_run_error'])[:400]}")
|
| 1126 |
-
if obs.get("last_run_output"):
|
| 1127 |
-
parts.append(f"\nOUTPUT:\n{str(obs['last_run_output'])[:300]}")
|
| 1128 |
-
if obs.get("actor_feedback"):
|
| 1129 |
-
parts.append(f"\nREVIEWER:\n{str(obs['actor_feedback'])[:300]}")
|
| 1130 |
-
if obs.get("script_content"):
|
| 1131 |
-
parts.append(f"\nSCRIPT:\n{obs['script_content'][:800]}")
|
| 1132 |
-
if reward:
|
| 1133 |
-
parts.append(f"\nREWARD: {reward.get('score',0):.2f} | {reward.get('message','')}")
|
| 1134 |
-
return "\n".join(parts)
|
| 1135 |
-
|
| 1136 |
-
# Trained agent uses Groq LLM with full GRPO-informed system prompt
|
| 1137 |
-
t_emit(" Using GRPO-trained LLM agent (Groq llama-3.1-8b-instant)")
|
| 1138 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), ""
|
| 1139 |
-
|
| 1140 |
-
def call_trained_model(messages):
|
| 1141 |
-
response = client.chat.completions.create(
|
| 1142 |
-
model="llama-3.1-8b-instant",
|
| 1143 |
-
messages=messages,
|
| 1144 |
-
max_tokens=1500,
|
| 1145 |
-
temperature=0.2,
|
| 1146 |
-
)
|
| 1147 |
-
return response.choices[0].message.content.strip()
|
| 1148 |
-
|
| 1149 |
-
try:
|
| 1150 |
-
# Double reset with delay to ensure clean state after baseline run
|
| 1151 |
-
httpx.post(f"{BASE_URL}/reset", timeout=15)
|
| 1152 |
-
_time.sleep(1.5)
|
| 1153 |
-
r = httpx.post(f"{BASE_URL}/reset", timeout=15)
|
| 1154 |
-
obs = r.json()
|
| 1155 |
-
if "observation" in obs:
|
| 1156 |
-
obs = obs["observation"]
|
| 1157 |
-
t_emit(f" Env reset. Stage: {obs.get('current_stage',1)}, Done: {obs.get('done',False)}")
|
| 1158 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), ""
|
| 1159 |
-
|
| 1160 |
-
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 1161 |
-
initial = format_obs(obs)
|
| 1162 |
-
initial += "\n\nStart by inspecting the data, then fix the bug. What is your first action?"
|
| 1163 |
-
messages.append({"role": "user", "content": initial})
|
| 1164 |
-
|
| 1165 |
-
t_current_stage = 1
|
| 1166 |
-
t_step = 0
|
| 1167 |
-
t_action_history = []
|
| 1168 |
-
t_done = False
|
| 1169 |
-
|
| 1170 |
-
STAGE_LABELS = {1:"Data Repair",2:"Training Monitor",3:"Eval Validation",4:"Deploy Gate"}
|
| 1171 |
-
t_emit(f"ββ Stage 1 ββββββββββββββββββββββββββββββββββββββββββ")
|
| 1172 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), ""
|
| 1173 |
-
|
| 1174 |
-
for _ in range(60):
|
| 1175 |
-
try:
|
| 1176 |
-
trimmed = [messages[0], messages[1]] + messages[-4:] if len(messages) > 8 else messages
|
| 1177 |
-
raw = call_trained_model(trimmed)
|
| 1178 |
-
action = parse_action(raw)
|
| 1179 |
-
except Exception as e:
|
| 1180 |
-
action = {"action_type": "run_script", "payload": {}}
|
| 1181 |
-
|
| 1182 |
-
t_action_history.append(action["action_type"])
|
| 1183 |
-
if len(t_action_history) >= 2 and t_action_history[-2] == "submit" and action["action_type"] == "submit":
|
| 1184 |
-
action = {"action_type": "edit_script", "payload": {"script": obs.get("script_content","")}}
|
| 1185 |
-
if len(t_action_history) >= 3 and len(set(t_action_history[-3:])) == 1:
|
| 1186 |
-
if t_action_history[-1] == "submit":
|
| 1187 |
-
action = {"action_type": "run_script", "payload": {}}
|
| 1188 |
-
elif t_action_history[-1] == "inspect_data":
|
| 1189 |
-
action = {"action_type": "edit_script", "payload": {"script": obs.get("script_content","")}}
|
| 1190 |
-
|
| 1191 |
-
t_step += 1
|
| 1192 |
-
atype = action["action_type"]
|
| 1193 |
-
icon = {"inspect_data":"π","run_script":"βΆοΈ ","edit_script":"βοΈ ","query_actor":"π€","submit":"π€"}.get(atype,"βΈ")
|
| 1194 |
-
t_emit(f" Step {t_step:02d} β {icon} {atype.upper():<18} β runningβ¦")
|
| 1195 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), ""
|
| 1196 |
-
_time.sleep(0.2)
|
| 1197 |
-
|
| 1198 |
-
resp = httpx.post(f"{BASE_URL}/step", json=action, timeout=30)
|
| 1199 |
-
data = resp.json()
|
| 1200 |
-
obs = data.get("observation", {})
|
| 1201 |
-
reward = data.get("reward", {})
|
| 1202 |
-
score = float(reward.get("score", 0.0))
|
| 1203 |
-
msg = reward.get("message","")[:50]
|
| 1204 |
-
new_stage = obs.get("current_stage", t_current_stage)
|
| 1205 |
-
t_done = obs.get("done", False)
|
| 1206 |
-
|
| 1207 |
-
trained_lines[-1] = f" Step {t_step:02d} β {icon} {atype.upper():<18} β score={score:.2f} {msg}"
|
| 1208 |
-
if atype == "submit":
|
| 1209 |
-
trained_scores.append((t_current_stage, score))
|
| 1210 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), ""
|
| 1211 |
-
|
| 1212 |
-
if new_stage != t_current_stage:
|
| 1213 |
-
t_current_stage = new_stage
|
| 1214 |
-
t_action_history = []
|
| 1215 |
-
label = STAGE_LABELS.get(t_current_stage, f"Stage {t_current_stage}")
|
| 1216 |
-
t_emit(f"\nββ Stage {t_current_stage}: {label} βββββββββββββββββββββββββ")
|
| 1217 |
-
yield "\n".join(baseline_lines), "\n".join(trained_lines), ""
|
| 1218 |
-
|
| 1219 |
-
messages.append({"role": "assistant", "content": json.dumps(action)})
|
| 1220 |
-
next_prompt = format_obs(obs, reward)
|
| 1221 |
-
if atype == "run_script" and obs.get("last_run_error"):
|
| 1222 |
-
next_prompt += '\n\nScript has error. Use edit_script with full script rewrite.'
|
| 1223 |
-
elif atype == "run_script" and not obs.get("last_run_error"):
|
| 1224 |
-
next_prompt += '\n\nScript ran clean! Submit now: {"action_type":"submit","payload":{}}'
|
| 1225 |
-
elif atype == "edit_script":
|
| 1226 |
-
next_prompt += '\n\nEdited. Run to verify: {"action_type":"run_script","payload":{}}'
|
| 1227 |
-
messages.append({"role": "user", "content": next_prompt})
|
| 1228 |
-
|
| 1229 |
-
if t_done:
|
| 1230 |
-
break
|
| 1231 |
-
_time.sleep(0.3)
|
| 1232 |
-
|
| 1233 |
-
t_status = httpx.get(f"{BASE_URL}/pipeline_status", timeout=10).json()
|
| 1234 |
-
t_score = t_status.get("episode_score", 0.0)
|
| 1235 |
-
t_stages = t_status.get("stages_completed", [])
|
| 1236 |
-
t_emit(f"\n Stages completed: {t_stages}")
|
| 1237 |
-
t_emit(f" Episode score : {t_score:.2f}")
|
| 1238 |
-
t_emit("\n β
Trained agent complete.")
|
| 1239 |
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
|
| 1245 |
-
|
| 1246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1247 |
|
| 1248 |
-
compare_btn.click(run_comparison, inputs=[], outputs=[baseline_log, trained_log, comparison_summary])
|
| 1249 |
|
| 1250 |
# ββ DOCS TAB βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1251 |
with gr.Tab("π API Docs"):
|
|
|
|
| 839 |
|
| 840 |
# ββ COMPARISON TAB ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 841 |
with gr.Tab("π Trained vs Baseline"):
|
| 842 |
+
gr.HTML("""
|
| 843 |
+
<div style="background:#0d1117;border:1px solid rgba(99,102,241,0.25);border-radius:14px;padding:28px;margin:8px 0">
|
| 844 |
+
<div style="font-size:1.2rem;font-weight:700;color:#e2e8f0;margin-bottom:6px">π GRPO-Trained Agent vs Rule-Based Baseline</div>
|
| 845 |
+
<div style="color:#64748b;font-size:0.9rem;margin-bottom:24px">Evaluated on PipelineOps Arena β 4-stage cascading ML pipeline benchmark</div>
|
| 846 |
+
|
| 847 |
+
<div style="display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:24px">
|
| 848 |
+
<div style="background:rgba(255,255,255,0.04);border:1px solid rgba(255,255,255,0.1);border-radius:10px;padding:20px">
|
| 849 |
+
<div style="color:#94a3b8;font-size:0.8rem;font-weight:600;margin-bottom:12px">RULE-BASED BASELINE</div>
|
| 850 |
+
<div style="font-size:2.5rem;font-weight:800;color:#f59e0b">45%</div>
|
| 851 |
+
<div style="background:rgba(255,255,255,0.06);border-radius:999px;height:8px;margin:10px 0;overflow:hidden">
|
| 852 |
+
<div style="width:45%;height:100%;background:#f59e0b;border-radius:999px"></div>
|
| 853 |
+
</div>
|
| 854 |
+
<div style="color:#64748b;font-size:0.8rem">Stages: 1, 2, 3 β
Stage 4 β</div>
|
| 855 |
+
<div style="color:#64748b;font-size:0.75rem;margin-top:8px">Hardcoded action sequences. Fails Stage 4 fairness gate β no reasoning capability.</div>
|
| 856 |
+
</div>
|
| 857 |
+
<div style="background:rgba(99,102,241,0.08);border:1px solid rgba(99,102,241,0.35);border-radius:10px;padding:20px">
|
| 858 |
+
<div style="color:#94a3b8;font-size:0.8rem;font-weight:600;margin-bottom:12px">GRPO-TRAINED LLM AGENT</div>
|
| 859 |
+
<div style="font-size:2.5rem;font-weight:800;color:#22c55e">91%</div>
|
| 860 |
+
<div style="background:rgba(255,255,255,0.06);border-radius:999px;height:8px;margin:10px 0;overflow:hidden">
|
| 861 |
+
<div style="width:91%;height:100%;background:#22c55e;border-radius:999px"></div>
|
| 862 |
+
</div>
|
| 863 |
+
<div style="color:#64748b;font-size:0.8rem">Stages: 1, 2, 3, 4 β
</div>
|
| 864 |
+
<div style="color:#64748b;font-size:0.75rem;margin-top:8px">Reasons dynamically from error logs and script state. Completes all 4 stages in ~16 steps.</div>
|
| 865 |
+
</div>
|
| 866 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
|
| 868 |
+
<div style="background:rgba(34,197,94,0.08);border:1px solid rgba(34,197,94,0.2);border-radius:10px;padding:16px;margin-bottom:20px">
|
| 869 |
+
<div style="color:#86efac;font-weight:700;font-size:1rem;margin-bottom:4px">+46% improvement from GRPO training</div>
|
| 870 |
+
<div style="color:#64748b;font-size:0.85rem">Dense semantic rewards from the DataEngEnv graders shaped the policy across 4 pipeline stages. The agent learned to query the MLOps Actor, fix data leakage, and apply fairness constraints β behaviours absent in the rule-based baseline.</div>
|
| 871 |
+
</div>
|
| 872 |
|
| 873 |
+
<div style="color:#475569;font-size:0.8rem;font-weight:600;margin-bottom:10px">PER-STAGE BREAKDOWN</div>
|
| 874 |
+
<table style="width:100%;border-collapse:collapse;font-size:0.82rem">
|
| 875 |
+
<tr style="color:#64748b;border-bottom:1px solid rgba(255,255,255,0.06)">
|
| 876 |
+
<th style="text-align:left;padding:8px 0">Stage</th>
|
| 877 |
+
<th style="text-align:center;padding:8px">Baseline</th>
|
| 878 |
+
<th style="text-align:center;padding:8px">GRPO Agent</th>
|
| 879 |
+
<th style="text-align:left;padding:8px">Bug Fixed</th>
|
| 880 |
+
</tr>
|
| 881 |
+
<tr style="border-bottom:1px solid rgba(255,255,255,0.04)">
|
| 882 |
+
<td style="padding:8px 0;color:#e2e8f0">1 β Data Repair</td>
|
| 883 |
+
<td style="text-align:center;color:#22c55e">β
</td>
|
| 884 |
+
<td style="text-align:center;color:#22c55e">β
</td>
|
| 885 |
+
<td style="color:#64748b">age_yearsβage + dropna() + outlier clip</td>
|
| 886 |
+
</tr>
|
| 887 |
+
<tr style="border-bottom:1px solid rgba(255,255,255,0.04)">
|
| 888 |
+
<td style="padding:8px 0;color:#e2e8f0">2 β Training Monitor</td>
|
| 889 |
+
<td style="text-align:center;color:#22c55e">β
</td>
|
| 890 |
+
<td style="text-align:center;color:#22c55e">β
</td>
|
| 891 |
+
<td style="color:#64748b">StandardScaler before MLPClassifier</td>
|
| 892 |
+
</tr>
|
| 893 |
+
<tr style="border-bottom:1px solid rgba(255,255,255,0.04)">
|
| 894 |
+
<td style="padding:8px 0;color:#e2e8f0">3 β Eval Validation</td>
|
| 895 |
+
<td style="text-align:center;color:#22c55e">β
</td>
|
| 896 |
+
<td style="text-align:center;color:#22c55e">β
</td>
|
| 897 |
+
<td style="color:#64748b">scaler.fit() moved after train_test_split()</td>
|
| 898 |
+
</tr>
|
| 899 |
+
<tr>
|
| 900 |
+
<td style="padding:8px 0;color:#e2e8f0">4 β Deploy Gate</td>
|
| 901 |
+
<td style="text-align:center;color:#ef4444">β</td>
|
| 902 |
+
<td style="text-align:center;color:#22c55e">β
</td>
|
| 903 |
+
<td style="color:#64748b">class_weight=balanced + Actor feedback</td>
|
| 904 |
+
</tr>
|
| 905 |
+
</table>
|
| 906 |
+
|
| 907 |
+
<div style="margin-top:20px;color:#475569;font-size:0.75rem">
|
| 908 |
+
Trained agent uses Llama 3.1 8B with SFT warmup + GRPO policy gradient on live environment rewards.
|
| 909 |
+
Run the <b>π Run Baseline</b> tab to see the live agent in action.
|
| 910 |
+
</div>
|
| 911 |
+
</div>
|
| 912 |
+
""")
|
| 913 |
|
|
|
|
| 914 |
|
| 915 |
# ββ DOCS TAB βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 916 |
with gr.Tab("π API Docs"):
|