Update app.py (#4)
Browse files- Update app.py (d87432cacb951f3bf583d2a6a23d7f6139a7999b)
Co-authored-by: Manay Porwal <manayporwal07@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -32,16 +32,16 @@ custom_css = """
|
|
| 32 |
}
|
| 33 |
"""
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
def process_single_evaluation(
|
| 38 |
prompt: str,
|
| 39 |
response: str,
|
| 40 |
expected_answer: Optional[str] = None,
|
| 41 |
agent_name: str = "Agent-1",
|
| 42 |
task_type: str = "general"
|
| 43 |
-
) -> Tuple[Dict, go.Figure, go.Figure, str]:
|
| 44 |
-
|
|
|
|
| 45 |
if not prompt or not response:
|
| 46 |
return {}, go.Figure(), go.Figure(), "Please provide both prompt and response."
|
| 47 |
|
|
@@ -54,17 +54,17 @@ def process_single_evaluation(
|
|
| 54 |
)
|
| 55 |
scores = eval_result.get("scores", {})
|
| 56 |
|
| 57 |
-
# Store result for explainability
|
| 58 |
-
eval_id = scores.get("eval_id", "")
|
| 59 |
-
if eval_id:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
# Generate visualizations
|
| 64 |
spider_chart = visualizer.create_spider_chart(scores, agent_name)
|
| 65 |
score_bars = visualizer.create_score_bars(scores, agent_name)
|
| 66 |
|
| 67 |
-
#
|
| 68 |
explanation = evaluator.generate_explanation(scores)
|
| 69 |
|
| 70 |
# Format scores for display
|
|
@@ -73,14 +73,15 @@ def process_single_evaluation(
|
|
| 73 |
|
| 74 |
return scores_display, spider_chart, score_bars, explanation
|
| 75 |
|
|
|
|
| 76 |
def process_batch_evaluation(
|
| 77 |
file_input,
|
| 78 |
evaluation_mode: str = "comprehensive"
|
| 79 |
) -> Tuple[go.Figure, go.Figure, go.Figure, str, pd.DataFrame]:
|
| 80 |
-
|
|
|
|
| 81 |
if file_input is None:
|
| 82 |
return go.Figure(), go.Figure(), go.Figure(), "Please upload a file.", pd.DataFrame()
|
| 83 |
-
|
| 84 |
try:
|
| 85 |
if file_input.name.endswith('.json'):
|
| 86 |
with open(file_input.name, 'r') as f:
|
|
@@ -102,7 +103,7 @@ def process_batch_evaluation(
|
|
| 102 |
# if eval_id:
|
| 103 |
# evaluation_storage[eval_id] = res
|
| 104 |
|
| 105 |
-
#
|
| 106 |
heatmap = visualizer.create_evaluation_heatmap(results)
|
| 107 |
distribution = visualizer.create_score_distribution(results)
|
| 108 |
trends = visualizer.create_performance_trends(results)
|
|
|
|
| 32 |
}
|
| 33 |
"""
|
| 34 |
|
| 35 |
+
# Single Evaluation Process
|
|
|
|
| 36 |
def process_single_evaluation(
|
| 37 |
prompt: str,
|
| 38 |
response: str,
|
| 39 |
expected_answer: Optional[str] = None,
|
| 40 |
agent_name: str = "Agent-1",
|
| 41 |
task_type: str = "general"
|
| 42 |
+
) -> Tuple[Dict, go.Figure, go.Figure, str]:
|
| 43 |
+
|
| 44 |
+
# If Prompt or Response is missing from User
|
| 45 |
if not prompt or not response:
|
| 46 |
return {}, go.Figure(), go.Figure(), "Please provide both prompt and response."
|
| 47 |
|
|
|
|
| 54 |
)
|
| 55 |
scores = eval_result.get("scores", {})
|
| 56 |
|
| 57 |
+
# # Store result for explainability
|
| 58 |
+
# eval_id = scores.get("eval_id", "")
|
| 59 |
+
# if eval_id:
|
| 60 |
+
# evaluation_storage[eval_id] = eval_result
|
| 61 |
+
# print(f"Stored evaluation {eval_id}")
|
| 62 |
|
| 63 |
# Generate visualizations
|
| 64 |
spider_chart = visualizer.create_spider_chart(scores, agent_name)
|
| 65 |
score_bars = visualizer.create_score_bars(scores, agent_name)
|
| 66 |
|
| 67 |
+
# Generating explanation
|
| 68 |
explanation = evaluator.generate_explanation(scores)
|
| 69 |
|
| 70 |
# Format scores for display
|
|
|
|
| 73 |
|
| 74 |
return scores_display, spider_chart, score_bars, explanation
|
| 75 |
|
| 76 |
+
# For Batch Evaluation
|
| 77 |
def process_batch_evaluation(
|
| 78 |
file_input,
|
| 79 |
evaluation_mode: str = "comprehensive"
|
| 80 |
) -> Tuple[go.Figure, go.Figure, go.Figure, str, pd.DataFrame]:
|
| 81 |
+
|
| 82 |
+
# If file input is None
|
| 83 |
if file_input is None:
|
| 84 |
return go.Figure(), go.Figure(), go.Figure(), "Please upload a file.", pd.DataFrame()
|
|
|
|
| 85 |
try:
|
| 86 |
if file_input.name.endswith('.json'):
|
| 87 |
with open(file_input.name, 'r') as f:
|
|
|
|
| 103 |
# if eval_id:
|
| 104 |
# evaluation_storage[eval_id] = res
|
| 105 |
|
| 106 |
+
# Generating visualizations
|
| 107 |
heatmap = visualizer.create_evaluation_heatmap(results)
|
| 108 |
distribution = visualizer.create_score_distribution(results)
|
| 109 |
trends = visualizer.create_performance_trends(results)
|