Spaces:
Sleeping
Sleeping
File size: 2,736 Bytes
120d6b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import pandas as pd
import gradio as gr
def set_error(row):
if row.error not in [True, False]:
if not row.prompt_response:
return True
return False
return row.error
def get_error_data(tools_df, inc_tools):
tools_inc = tools_df[tools_df['tool'].isin(inc_tools)]
tools_inc['error'] = tools_inc.apply(set_error, axis=1)
error = tools_inc.groupby(['tool', 'request_month_year_week', 'error']).size().unstack().fillna(0).reset_index()
error['error_perc'] = (error[True] / (error[False] + error[True])) * 100
error['total_requests'] = error[False] + error[True]
return error
def get_error_data_overall(error_df):
error_total = error_df.groupby('request_month_year_week').agg({'total_requests': 'sum', False: 'sum', True: 'sum'}).reset_index()
error_total['error_perc'] = (error_total[True] / error_total['total_requests']) * 100
error_total.columns = error_total.columns.astype(str)
error_total['error_perc'] = error_total['error_perc'].apply(lambda x: round(x, 4))
return error_total
def plot_error_data(error_all_df):
return gr.BarPlot(
value=error_all_df,
x="request_month_year_week",
y="error_perc",
title="Error Percentage",
x_title="Week",
y_title="Error Percentage",
height=800,
show_label=True,
interactive=True,
show_actions_button=True,
tooltip=["request_month_year_week", "error_perc"]
)
def plot_tool_error_data(error_df, tool):
error_tool = error_df[error_df['tool'] == tool]
error_tool.columns = error_tool.columns.astype(str)
error_tool['error_perc'] = error_tool['error_perc'].apply(lambda x: round(x, 4))
return gr.BarPlot(
title="Error Percentage",
x_title="Week",
y_title="Error Percentage",
show_label=True,
interactive=True,
show_actions_button=True,
tooltip=["request_month_year_week", "error_perc"],
width=800,
value=error_tool,
x="request_month_year_week",
y="error_perc"
)
def plot_week_error_data(error_df, week):
error_week = error_df[error_df['request_month_year_week'] == week]
error_week.columns = error_week.columns.astype(str)
error_week['error_perc'] = error_week['error_perc'].apply(lambda x: round(x, 4))
return gr.BarPlot(
value=error_week,
x="tool",
y="error_perc",
title="Error Percentage",
x_title="Tool",
y_title="Error Percentage",
height=800,
show_label=True,
interactive=True,
show_actions_button=True,
tooltip=["tool", "error_perc"]
)
|