Supastrikas-004 commited on
Commit
37e95fb
·
verified ·
1 Parent(s): 4b64fe3

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +34 -0
  2. evaluator.py +37 -0
  3. requirements.txt +6 -0
  4. synthetic_data.py +11 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from evaluator import evaluate_responses
4
+ from synthetic_data import generate_synthetic_dataset
5
+
6
+ # Demo synthetic dataset
7
+ df = generate_synthetic_dataset(num_agents=10, num_samples=50)
8
+
9
+ def run_evaluation(use_llm_judge=False):
10
+ results = evaluate_responses(df, use_llm_judge=use_llm_judge)
11
+ leaderboard = results.groupby("agent")["final_score"].mean().reset_index()
12
+ leaderboard = leaderboard.sort_values("final_score", ascending=False)
13
+ return results, leaderboard
14
+
15
+ with gr.Blocks(title="Agentic Evaluation Framework") as demo:
16
+ gr.Markdown("# 🤖 Agentic Evaluation Framework")
17
+ gr.Markdown("Automatically evaluate AI agents across multiple dimensions.")
18
+
19
+ with gr.Tab("Synthetic Data Preview"):
20
+ gr.DataFrame(df, label="Generated Dataset", interactive=False)
21
+
22
+ with gr.Tab("Run Evaluation"):
23
+ use_llm = gr.Checkbox(label="Use LLM Judge (Optional)", value=False)
24
+ run_button = gr.Button("Run Evaluation")
25
+ results_output = gr.DataFrame(label="Evaluation Results")
26
+ leaderboard_output = gr.DataFrame(label="Leaderboard")
27
+
28
+ run_button.click(
29
+ fn=run_evaluation,
30
+ inputs=[use_llm],
31
+ outputs=[results_output, leaderboard_output]
32
+ )
33
+
34
+ demo.launch()
evaluator.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import textstat
3
+ import language_tool_python
4
+
5
+ tool = language_tool_python.LanguageTool('en-US')
6
+
7
+ def evaluate_responses(df, use_llm_judge=False):
8
+ scores = []
9
+ for _, row in df.iterrows():
10
+ response = row["response"]
11
+
12
+ # Rule-based metrics
13
+ grammar_matches = len(tool.check(response))
14
+ readability = textstat.flesch_reading_ease(response)
15
+
16
+ # Simple scoring
17
+ instruction_follow = 1 if row["instruction"].lower() in response.lower() else 0
18
+ coherence = 1 if readability > 40 else 0
19
+ grammar_score = max(0, 1 - grammar_matches/10)
20
+
21
+ final_score = (instruction_follow + coherence + grammar_score) / 3
22
+
23
+ # Optional LLM judge (stubbed for now, can hook Hugging Face API later)
24
+ if use_llm_judge:
25
+ final_score = (final_score + 0.8) / 2 # Example: trust LLM judge
26
+
27
+ scores.append({
28
+ "agent": row["agent"],
29
+ "instruction": row["instruction"],
30
+ "response": response,
31
+ "score_instruction": instruction_follow,
32
+ "score_coherence": coherence,
33
+ "score_grammar": grammar_score,
34
+ "final_score": final_score
35
+ })
36
+
37
+ return pd.DataFrame(scores)
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio==4.44.0
2
+ pandas
3
+ numpy
4
+ scikit-learn
5
+ language-tool-python
6
+ textstat
synthetic_data.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import random
3
+
4
+ def generate_synthetic_dataset(num_agents=5, num_samples=20):
5
+ data = []
6
+ for agent in range(num_agents):
7
+ for i in range(num_samples):
8
+ instr = f"Task {i}: Summarize topic {random.randint(1,10)}"
9
+ resp = f"This is a response to {instr}. Agent {agent} provides details."
10
+ data.append({"agent": f"Agent_{agent}", "instruction": instr, "response": resp})
11
+ return pd.DataFrame(data)