# %%
from jinja2 import Environment, FileSystemLoader
import pandas as pd
import gradio as gr
df = pd.read_csv("./data.csv")
def parse_into_jinja_markdown(
model_name,
performance,
accuracy,
Precision,
Recall,
Robustness,
Fairness,
Failure_Clusters,
):
env = Environment(loader=FileSystemLoader("."), autoescape=True)
temp = env.get_template("mc_template.md")
return temp.render(
model_id=model_name,
accuracy=accuracy,
Precision=Precision,
Recall=Recall,
Robustness=Robustness,
Fairness=Fairness,
Performance=performance,
Failure_Cluster=Failure_Clusters,
)
def md_builder(model, dataset, displayed_metrics):
row = df[df["friendly_name"] == model]
str = ""
## f"# Model Card for {model}
\n"
##f"On dataset `{dataset}`\n"
## )
# init vars to empty string
(
perform_val,
accuracy_val,
precision_val,
recall_val,
robustness_val,
fairness_val,
fail_cluster,
) = ("", "", "", "", "", "", "")
if "Performance" in displayed_metrics:
perform_val = f"\nPerformance: `{row['performance'].values[0]}`"
if "Accuracy" in displayed_metrics:
accuracy_val = f"\nAccuracy: `{row['accuracy'].values[0]}`"
if "Precision" in displayed_metrics:
precision_val = f"\nPrecision: `{row['precision_weighted'].values[0]}`"
if "Recall" in displayed_metrics:
recall_val = f"\nRecall: `{row['recall_weighted'].values[0]}`"
if "Robustness" in displayed_metrics:
robustness_val = f"\nRobustness: `{100-row['robustness'].values[0]}`"
if "Fairness" in displayed_metrics:
fairness_val = f"\nFairness: `{0}`"
if "Failure Clusters" in displayed_metrics:
cl_count = row["cluster_count"].values[0]
fail_cluster = f"\nTop failures: {row['top_failure_cluster'].values[0]} (+{cl_count - 1} others) (details for all {cl_count} clusters)"
str += "\n