File size: 1,526 Bytes
f740333 |
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 |
import pandas as pd
import gradio as gr
import matplotlib.pyplot as plt
import seaborn as sns
def get_weighted_accuracy(row, global_requests: int):
"""Function to compute the weighted accuracy of a tool"""
return (row["tool_accuracy"] / 100.0) * (row["total_requests"] / global_requests)
def compute_weighted_accuracy(tools_accuracy: pd.DataFrame):
global_requests = tools_accuracy.total_requests.sum()
tools_accuracy["weighted_accuracy"] = tools_accuracy.apply(
lambda x: get_weighted_accuracy(x, global_requests), axis=1
)
return tools_accuracy
def plot_tools_accuracy_graph(tools_accuracy_info: pd.DataFrame):
tools_accuracy_info = tools_accuracy_info.sort_values(
by="tool_accuracy", ascending=False
)
plt.figure(figsize=(25, 10))
plot = sns.barplot(
tools_accuracy_info,
x="tool_accuracy",
y="tool",
hue="tool",
dodge=False,
palette="viridis",
)
return gr.Plot(value=plot.get_figure())
def plot_tools_weighted_accuracy_graph(tools_accuracy_info: pd.DataFrame):
tools_accuracy_info = tools_accuracy_info.sort_values(
by="weighted_accuracy", ascending=False
)
# Create the Seaborn bar plot
sns.set_theme(palette="viridis")
plt.figure(figsize=(25, 10))
plot = sns.barplot(
tools_accuracy_info,
x="weighted_accuracy",
y="tool",
hue="tool",
dodge=False,
)
# Display the plot using gr.Plot
gr.Plot(value=plot.get_figure())
|