Spaces:
Sleeping
Sleeping
Sibam commited on
Commit Β·
c3d75c0
1
Parent(s): e71b4ea
feat: transform custom UI into an intelligent Agent Learning dashboard with progress metrics and reasoning
Browse files- server/app.py +86 -19
server/app.py
CHANGED
|
@@ -38,36 +38,103 @@ if ENABLE_WEB_INTERFACE:
|
|
| 38 |
def build_progress_dashboard(web_manager, action_fields, metadata, is_chat_env, title, quick_start_md):
|
| 39 |
import gradio as gr
|
| 40 |
with gr.Blocks() as blocks:
|
| 41 |
-
gr.Markdown("##
|
| 42 |
gr.Markdown(
|
| 43 |
-
"This dashboard
|
| 44 |
-
"
|
| 45 |
-
"Rewards are computed via gold-standard dataset grounding."
|
| 46 |
)
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
import pandas as pd
|
| 58 |
logs = getattr(web_manager.episode_state, "action_logs", [])
|
| 59 |
-
if not logs:
|
| 60 |
-
return pd.DataFrame({"Step": [], "Reward": []})
|
| 61 |
|
| 62 |
data = []
|
| 63 |
for log in logs:
|
| 64 |
if getattr(log, "reward", None) is not None:
|
| 65 |
data.append({"Step": getattr(log, "step_count", 0), "Reward": float(log.reward)})
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
return blocks
|
| 72 |
|
| 73 |
# Mounts the Gradio playground at /web and redirects / β /web/
|
|
|
|
| 38 |
def build_progress_dashboard(web_manager, action_fields, metadata, is_chat_env, title, quick_start_md):
|
| 39 |
import gradio as gr
|
| 40 |
with gr.Blocks() as blocks:
|
| 41 |
+
gr.Markdown("## π€ Agent Learning Dashboard")
|
| 42 |
gr.Markdown(
|
| 43 |
+
"This dashboard transforms the basic interface into an intelligent view of the RLHF agent's decision-making process. "
|
| 44 |
+
"You can observe reward signals, evaluation rationale, and training progression."
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
+
with gr.Row():
|
| 48 |
+
with gr.Column(scale=2):
|
| 49 |
+
reward_plot = gr.LinePlot(
|
| 50 |
+
x="Step",
|
| 51 |
+
y="Reward",
|
| 52 |
+
title="Learning Progress (Agent Improving Over Time)",
|
| 53 |
+
tooltip=["Step", "Reward"],
|
| 54 |
+
x_title="Episode Step",
|
| 55 |
+
y_title="Reward",
|
| 56 |
+
y_lim=[0.0, 1.0]
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
with gr.Row():
|
| 60 |
+
reward_explanation = gr.Textbox(label="Reward Explanation", lines=2)
|
| 61 |
+
improvement_tip = gr.Textbox(label="Agent Suggestion", lines=2)
|
| 62 |
+
|
| 63 |
+
with gr.Column(scale=1):
|
| 64 |
+
refresh_btn = gr.Button("π Sync Agent State", variant="primary")
|
| 65 |
+
|
| 66 |
+
agent_thinking = gr.Markdown(
|
| 67 |
+
"### Agent Process:\n"
|
| 68 |
+
"- π Understanding input\n"
|
| 69 |
+
"- βοΈ Comparing responses\n"
|
| 70 |
+
"- π― Evaluating alignment\n"
|
| 71 |
+
"- π
Assigning reward\n"
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
dataset_vis = gr.HTML("Dataset: <b>...</b>")
|
| 75 |
+
session_summary = gr.Markdown("### Session Summary\n_Episode ongoing..._")
|
| 76 |
+
|
| 77 |
+
def update_dashboard():
|
| 78 |
import pandas as pd
|
| 79 |
logs = getattr(web_manager.episode_state, "action_logs", [])
|
|
|
|
|
|
|
| 80 |
|
| 81 |
data = []
|
| 82 |
for log in logs:
|
| 83 |
if getattr(log, "reward", None) is not None:
|
| 84 |
data.append({"Step": getattr(log, "step_count", 0), "Reward": float(log.reward)})
|
| 85 |
+
|
| 86 |
+
# Always ensure graph shows at least one point
|
| 87 |
+
if not data:
|
| 88 |
+
df = pd.DataFrame({"Step": [0], "Reward": [0.0]})
|
| 89 |
+
return df, "Awaiting first agent action...", "Waiting...", "Dataset: <b>Pending</b>", "### Episode Summary\n_No steps yet._"
|
| 90 |
+
|
| 91 |
+
df = pd.DataFrame(data)
|
| 92 |
+
latest_reward = data[-1]["Reward"]
|
| 93 |
+
latest_step = data[-1]["Step"]
|
| 94 |
+
|
| 95 |
+
# Explain reward
|
| 96 |
+
if latest_reward > 0.8:
|
| 97 |
+
exp = "High quality response, well aligned with user intent"
|
| 98 |
+
tip = "Try making the response more concise"
|
| 99 |
+
elif latest_reward > 0.5:
|
| 100 |
+
exp = "Decent response but can be improved in clarity"
|
| 101 |
+
tip = "Improve structure and clarity"
|
| 102 |
+
else:
|
| 103 |
+
exp = "Poor response, lacks relevance or correctness"
|
| 104 |
+
tip = "Focus on relevance and correctness"
|
| 105 |
+
|
| 106 |
+
# Extract dataset name
|
| 107 |
+
last_log = logs[-1]
|
| 108 |
+
info = {}
|
| 109 |
+
if hasattr(last_log, "observation") and last_log.observation is not None:
|
| 110 |
+
if hasattr(last_log.observation, "info"):
|
| 111 |
+
info = last_log.observation.info
|
| 112 |
+
elif hasattr(last_log.observation, "model_extra") and last_log.observation.model_extra:
|
| 113 |
+
info = last_log.observation.model_extra.get("info", {})
|
| 114 |
+
|
| 115 |
+
dataset_str = info.get("dataset", "Synthetic / Unknown") if isinstance(info, dict) else "Unknown"
|
| 116 |
+
|
| 117 |
+
# Session summary metrics
|
| 118 |
+
initial_reward = data[0]["Reward"]
|
| 119 |
+
improvement = 0.0
|
| 120 |
+
if initial_reward > 0:
|
| 121 |
+
improvement = ((latest_reward - initial_reward) / initial_reward) * 100
|
| 122 |
+
|
| 123 |
+
summary = (
|
| 124 |
+
f"### Episode Summary\n"
|
| 125 |
+
f"- **Final Reward:** {latest_reward:.2f}\n"
|
| 126 |
+
f"- **Improvement:** {improvement:+.1f}%\n"
|
| 127 |
+
f"- **Steps:** {latest_step}"
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
return df, exp, tip, f"Dataset: <b>{dataset_str.upper()}</b>", summary
|
| 131 |
|
| 132 |
+
# Manual safe refresh mapping
|
| 133 |
+
refresh_btn.click(
|
| 134 |
+
fn=update_dashboard,
|
| 135 |
+
inputs=None,
|
| 136 |
+
outputs=[reward_plot, reward_explanation, improvement_tip, dataset_vis, session_summary]
|
| 137 |
+
)
|
| 138 |
return blocks
|
| 139 |
|
| 140 |
# Mounts the Gradio playground at /web and redirects / β /web/
|