Ezi commited on
Commit
2029c47
1 Parent(s): a293aa3

adding in MC template + parsing

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -1,41 +1,47 @@
1
  # %%
 
2
  import pandas as pd
3
  import gradio as gr
4
 
5
  df = pd.read_csv("./data.csv")
6
 
 
 
 
 
7
 
8
  def md_builder(model, dataset, displayed_metrics):
9
  row = df[df["friendly_name"] == model]
10
- str = (
11
- f"## <span style='font-size: 16px;'>🚧 Performance and safety of <code style='font-weight: 400'>{model}</code></span>\n"
12
- f"On dataset `{dataset}`\n"
13
- )
 
14
 
15
  if "Performance" in displayed_metrics:
16
- str += f"\nPerformance: `{row['performance'].values[0]}`"
17
 
18
  if "Accuracy" in displayed_metrics:
19
- str += f"\nAccuracy: `{row['accuracy'].values[0]}`"
20
 
21
  if "Precision" in displayed_metrics:
22
- str += f"\nPrecision: `{row['precision_weighted'].values[0]}`"
23
 
24
  if "Recall" in displayed_metrics:
25
- str += f"\nRecall: `{row['recall_weighted'].values[0]}`"
26
 
27
  if "Robustness" in displayed_metrics:
28
- str += f"\nRobustness: `{100-row['robustness'].values[0]}`"
29
 
30
  if "Fairness" in displayed_metrics:
31
- str += f"\nFairness: `{0}`"
32
 
33
  if "Failure Clusters" in displayed_metrics:
34
  cl_count = row['cluster_count'].values[0]
35
- str += f"\n<details><summary>Top failures: <code>{row['top_failure_cluster'].values[0]}</code> (+{cl_count - 1} others)</summary>(details for all {cl_count} clusters)</details>"
36
 
37
  str += "\n<div style='text-align: right'>⛶ Expand safety card</div>"
38
-
39
  return str
40
 
41
 
 
1
  # %%
2
+ from jinja2 import Environment, FileSystemLoader
3
  import pandas as pd
4
  import gradio as gr
5
 
6
  df = pd.read_csv("./data.csv")
7
 
8
+ def parse_into_jinja_markdown(model_name, performance,accuracy,Precision, Recall, Robustness, Fairness, Failure_Clusters ):
9
+ env = Environment(loader=FileSystemLoader('.'), autoescape=True)
10
+ temp = env.get_template('mc_template.md')
11
+ return( temp.render(model_id =model_name, accuracy=accuracy,Precision=Precision,Recall=Recall,Robustness=Robustness,Fairness=Fairness,Performance =performance, Failure_Cluster=Failure_Clusters))
12
 
13
  def md_builder(model, dataset, displayed_metrics):
14
  row = df[df["friendly_name"] == model]
15
+ str = ""
16
+ ## f"# <span style='font-size: 16px;'> Model Card for <code style='font-weight: 400'>{model}</code></span>\n"
17
+ ##f"On dataset `{dataset}`\n"
18
+
19
+ ## )
20
 
21
  if "Performance" in displayed_metrics:
22
+ perform_val = f"\nPerformance: `{row['performance'].values[0]}`"
23
 
24
  if "Accuracy" in displayed_metrics:
25
+ accuracy_val= f"\nAccuracy: `{row['accuracy'].values[0]}`"
26
 
27
  if "Precision" in displayed_metrics:
28
+ precision_val= f"\nPrecision: `{row['precision_weighted'].values[0]}`"
29
 
30
  if "Recall" in displayed_metrics:
31
+ recall_val= f"\nRecall: `{row['recall_weighted'].values[0]}`"
32
 
33
  if "Robustness" in displayed_metrics:
34
+ robustness_val = f"\nRobustness: `{100-row['robustness'].values[0]}`"
35
 
36
  if "Fairness" in displayed_metrics:
37
+ fairness_val = f"\nFairness: `{0}`"
38
 
39
  if "Failure Clusters" in displayed_metrics:
40
  cl_count = row['cluster_count'].values[0]
41
+ fail_cluster = f"\nTop failures: {row['top_failure_cluster'].values[0]}(+{cl_count - 1} others)(details for all {cl_count} clusters)"
42
 
43
  str += "\n<div style='text-align: right'>⛶ Expand safety card</div>"
44
+ str = parse_into_jinja_markdown(model,perform_val,accuracy_val,precision_val,recall_val,robustness_val,fairness_val,fail_cluster)
45
  return str
46
 
47