Muennighoff commited on
Commit
ec6b925
1 Parent(s): 78db81b
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -7,14 +7,6 @@ from huggingface_hub.repocard import metadata_load
7
 
8
  path = f"https://huggingface.co/api/spaces"
9
 
10
-
11
- #api = HfApi()
12
- #models = api.list_models(filter="mteb")
13
- #readme_path = hf_hub_download(models[0].modelId, filename="README.md")
14
- #meta = metadata_load(readme_path)
15
- #list(filter(lambda x: x["task"]["type"] == "Retrieval", meta["model-index"][0]["results"]))
16
-
17
-
18
  def get_blocks_party_spaces():
19
  r = requests.get(path)
20
  d = r.json()
@@ -28,7 +20,14 @@ def get_blocks_party_spaces():
28
  df = df.sort_values(by=['likes'],ascending=False)
29
  return df
30
 
31
- def get_clustering(task="Clustering", metric="v_measure"):
 
 
 
 
 
 
 
32
  api = HfApi()
33
  models = api.list_models(filter="mteb")
34
  df_list = []
@@ -37,11 +36,14 @@ def get_clustering(task="Clustering", metric="v_measure"):
37
  meta = metadata_load(readme_path)
38
  out = list(
39
  map(
40
- lambda x: {x["dataset"]["name"]: list(filter(lambda x: x["type"] == metric, x["metrics"]))[0]["value"]},
41
  filter(lambda x: x["task"]["type"] == task, meta["model-index"][0]["results"])
42
  )
43
  )
44
  out = {k: v for d in out for k, v in d.items()}
 
 
 
45
  out["Model"] = model.modelId
46
  df_list.append(out)
47
  df = pd.DataFrame(df_list)
@@ -67,7 +69,9 @@ with block:
67
  data = gr.components.Dataframe(type="pandas")
68
  with gr.Row():
69
  data_run = gr.Button("Refresh")
70
- data_run.click(get_clustering, inputs=None, outputs=data)
 
 
71
  with gr.TabItem("Blocks Party Leaderboard2"):
72
  with gr.Row():
73
  data = gr.components.Dataframe(type="pandas")
 
7
 
8
  path = f"https://huggingface.co/api/spaces"
9
 
 
 
 
 
 
 
 
 
10
  def get_blocks_party_spaces():
11
  r = requests.get(path)
12
  d = r.json()
 
20
  df = df.sort_values(by=['likes'],ascending=False)
21
  return df
22
 
23
+ def make_clickable_model(model_name):
24
+ # remove user from model name
25
+ model_name_show = ' '.join(model_name.split('/')[1:])
26
+
27
+ link = "https://huggingface.co/" + model_name
28
+ return f'<a target="_blank" href="{link}">{model_name_show}</a>'
29
+
30
+ def get_mteb_data(task="Clustering", metric="v_measure"):
31
  api = HfApi()
32
  models = api.list_models(filter="mteb")
33
  df_list = []
 
36
  meta = metadata_load(readme_path)
37
  out = list(
38
  map(
39
+ lambda x: {x["dataset"]["name"].replace("MTEB ", ""): round(list(filter(lambda x: x["type"] == metric, x["metrics"]))[0]["value"], 2)},
40
  filter(lambda x: x["task"]["type"] == task, meta["model-index"][0]["results"])
41
  )
42
  )
43
  out = {k: v for d in out for k, v in d.items()}
44
+ # Does not work https://github.com/gradio-app/gradio/issues/2375
45
+ # Turning it into HTML will make the formatting ugly
46
+ # make_clickable_model(model.modelId)
47
  out["Model"] = model.modelId
48
  df_list.append(out)
49
  df = pd.DataFrame(df_list)
 
69
  data = gr.components.Dataframe(type="pandas")
70
  with gr.Row():
71
  data_run = gr.Button("Refresh")
72
+ task = gr.Variable(value="Clustering")
73
+ metric = gr.Variable(value="v_measure")
74
+ data_run.click(get_mteb_data, inputs=[task, metric], outputs=data)
75
  with gr.TabItem("Blocks Party Leaderboard2"):
76
  with gr.Row():
77
  data = gr.components.Dataframe(type="pandas")