Mandark-droid commited on
Commit
184f198
Β·
1 Parent(s): f65e58b

Add comprehensive error handling to all load functions

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -65,29 +65,38 @@ def apply_filters(model, provider, sort_by_col):
65
 
66
  def load_drilldown(agent_type, provider):
67
  """Load drilldown data with filters"""
68
- df = data_loader.load_leaderboard()
 
69
 
70
- if agent_type != "All" and 'agent_type' in df.columns:
71
- df = df[df['agent_type'] == agent_type]
72
- if provider != "All" and 'provider' in df.columns:
73
- df = df[df['provider'] == provider]
74
 
75
- # Select only columns that exist
76
- desired_columns = [
77
- 'run_id', 'model', 'agent_type', 'provider',
78
- 'success_rate', 'total_tests', 'avg_duration_ms', 'total_cost_usd'
79
- ]
80
 
81
- # Filter to only existing columns
82
- available_columns = [col for col in desired_columns if col in df.columns]
 
 
 
83
 
84
- if not available_columns:
85
- # If no desired columns exist, return empty dataframe
86
- return pd.DataFrame()
 
 
 
87
 
88
- display_df = df[available_columns].copy()
89
 
90
- return display_df
 
 
 
 
 
91
 
92
 
93
  def load_trends():
@@ -118,13 +127,17 @@ def generate_card(top_n):
118
 
119
  def generate_insights():
120
  """Generate AI insights summary"""
121
- df = data_loader.load_leaderboard()
 
122
 
123
- top_model = df.loc[df['success_rate'].idxmax()]
124
- most_cost_effective = df.loc[(df['success_rate'] / (df['total_cost_usd'] + 0.0001)).idxmax()]
125
- fastest = df.loc[df['avg_duration_ms'].idxmin()]
126
 
127
- insights = f"""
 
 
 
 
128
  ## πŸ“Š Leaderboard Summary
129
 
130
  **Total Runs:** {len(df)}
@@ -142,9 +155,14 @@ def generate_insights():
142
  ---
143
 
144
  *Note: AI-powered insights will be available via MCP integration in the full version.*
145
- """
146
-
147
- return insights
 
 
 
 
 
148
 
149
 
150
  # Build Gradio app
 
65
 
66
  def load_drilldown(agent_type, provider):
67
  """Load drilldown data with filters"""
68
+ try:
69
+ df = data_loader.load_leaderboard()
70
 
71
+ if df.empty:
72
+ return pd.DataFrame()
 
 
73
 
74
+ if agent_type != "All" and 'agent_type' in df.columns:
75
+ df = df[df['agent_type'] == agent_type]
76
+ if provider != "All" and 'provider' in df.columns:
77
+ df = df[df['provider'] == provider]
 
78
 
79
+ # Select only columns that exist
80
+ desired_columns = [
81
+ 'run_id', 'model', 'agent_type', 'provider',
82
+ 'success_rate', 'total_tests', 'avg_duration_ms', 'total_cost_usd'
83
+ ]
84
 
85
+ # Filter to only existing columns
86
+ available_columns = [col for col in desired_columns if col in df.columns]
87
+
88
+ if not available_columns:
89
+ # If no desired columns exist, return empty dataframe
90
+ return pd.DataFrame()
91
 
92
+ display_df = df[available_columns].copy()
93
 
94
+ return display_df
95
+ except Exception as e:
96
+ print(f"[ERROR] load_drilldown: {e}")
97
+ import traceback
98
+ traceback.print_exc()
99
+ return pd.DataFrame()
100
 
101
 
102
  def load_trends():
 
127
 
128
  def generate_insights():
129
  """Generate AI insights summary"""
130
+ try:
131
+ df = data_loader.load_leaderboard()
132
 
133
+ if df.empty or 'success_rate' not in df.columns:
134
+ return "## πŸ“Š Leaderboard Summary\n\nNo data available for insights."
 
135
 
136
+ top_model = df.loc[df['success_rate'].idxmax()]
137
+ most_cost_effective = df.loc[(df['success_rate'] / (df['total_cost_usd'] + 0.0001)).idxmax()]
138
+ fastest = df.loc[df['avg_duration_ms'].idxmin()]
139
+
140
+ insights = f"""
141
  ## πŸ“Š Leaderboard Summary
142
 
143
  **Total Runs:** {len(df)}
 
155
  ---
156
 
157
  *Note: AI-powered insights will be available via MCP integration in the full version.*
158
+ """
159
+
160
+ return insights
161
+ except Exception as e:
162
+ print(f"[ERROR] generate_insights: {e}")
163
+ import traceback
164
+ traceback.print_exc()
165
+ return f"## πŸ“Š Leaderboard Summary\n\nError generating insights: {str(e)}"
166
 
167
 
168
  # Build Gradio app