import gradio as gr import json import pandas as pd import html import logging # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def load_and_display_json(file): try: # Function to format tools list as HTML with each tool on a separate line def format_tools_list(tools): if not tools or not isinstance(tools, list) or len(tools) == 0: return "No tools used" html_list = "
{html.escape(tool_details)}
| {col} | " for col in ['#', 'User ID', 'Question', 'Confidence', 'Send to Human', 'Time Spent', 'Eval Scores', 'Details']) + "||||||||
|---|---|---|---|---|---|---|---|---|
| {row['Index'] + 1} | " html_output += f"{html.escape(str(row['User ID']))} | " html_output += f"{html.escape(str(row['Question']))} | " html_output += f"{row['Confidence']} | " # Add Send to Human cell with conditional message display if row['Send to Human'] is True: # Format call_human_message as JSON if it's a dictionary call_human_message = row['Call Human Message'] try: if isinstance(call_human_message, dict): formatted_message = json.dumps(call_human_message, indent=2, ensure_ascii=False) else: formatted_message = str(call_human_message) except: formatted_message = str(call_human_message) html_output += f"""True | """ else: html_output += f"False | " html_output += f"{row['Time Spent']} | " html_output += f"{row['Eval Scores']} | " # Convert JSON objects to pretty-printed strings retrieval_context_json = html.escape(str(row['Retrieval Context'])) if row['Retrieval Context'] else "N/A" # Format evaluation metrics with 3 decimal places for scores if row['Evaluation Metrics']: formatted_metrics = [] for metric in row['Evaluation Metrics']: metric_copy = dict(metric) if 'score' in metric_copy and isinstance(metric_copy['score'], (int, float)): metric_copy['score'] = format(float(metric_copy['score']), '.3f') formatted_metrics.append(metric_copy) eval_metrics_json = json.dumps(formatted_metrics, indent=2, ensure_ascii=False) else: eval_metrics_json = "N/A" # Add buttons for different popups in the same row html_output += f"""
Question:
{html.escape(str(row['Question']))} Ground Truth:{html.escape(str(row['Ground Truth']))} Response:{html.escape(str(row['Response']))} Source:{html.escape(str(row['Source']))} Tools:
{format_tools_list(row['Tools'])}
{f"Call Human Message:{html.escape(formatted_message)} " if row['Send to Human'] is True else ""} Information to Check:{html.escape(str(row['Information to Check']))}
Information to Check:
{html.escape(str(row['Information to Check']))} Evaluation Metrics:{html.escape(eval_metrics_json)}
Retrieval Context:
{retrieval_context_json} |
"""
html_output += "