Spaces:
Runtime error
Runtime error
Omar Sanseviero
commited on
Commit
·
635c44a
1
Parent(s):
1f6107e
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from tqdm.auto import tqdm
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 7 |
+
from huggingface_hub.repocard import metadata_load
|
| 8 |
+
|
| 9 |
+
def make_clickable(model_name):
|
| 10 |
+
link = "https://huggingface.co/" + model_name
|
| 11 |
+
return f'<a target="_blank" href="{link}">{model_name}</a>'
|
| 12 |
+
|
| 13 |
+
def get_model_ids():
|
| 14 |
+
api = HfApi()
|
| 15 |
+
models = api.list_models(filter="llamaleaderboard")
|
| 16 |
+
model_ids = [x.modelId for x in models]
|
| 17 |
+
return model_ids
|
| 18 |
+
|
| 19 |
+
def get_metadata(model_id):
|
| 20 |
+
try:
|
| 21 |
+
readme_path = hf_hub_download(model_id, filename="README.md")
|
| 22 |
+
return metadata_load(readme_path)
|
| 23 |
+
except requests.exceptions.HTTPError:
|
| 24 |
+
# 404 README.md not found
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
def parse_metrics_accuracy(meta):
|
| 28 |
+
if "model-index" not in meta:
|
| 29 |
+
return None
|
| 30 |
+
result = meta["model-index"][0]["results"]
|
| 31 |
+
metrics = result[0]["metrics"]
|
| 32 |
+
accuracy = metrics[0]["value"]
|
| 33 |
+
yield accuracy
|
| 34 |
+
|
| 35 |
+
@st.cache(ttl=600)
|
| 36 |
+
def get_data():
|
| 37 |
+
data = []
|
| 38 |
+
model_ids = get_model_ids()
|
| 39 |
+
for model_id in tqdm(model_ids):
|
| 40 |
+
meta = get_metadata(model_id)
|
| 41 |
+
if meta is None:
|
| 42 |
+
continue
|
| 43 |
+
row = {}
|
| 44 |
+
row["Model"] = model_id
|
| 45 |
+
row["accuracy"] = parse_metrics_accuracy(meta)
|
| 46 |
+
data.append(row)
|
| 47 |
+
return pd.DataFrame.from_records(data)
|
| 48 |
+
|
| 49 |
+
dataframe = get_data()
|
| 50 |
+
dataframe = dataframe.fillna("")
|
| 51 |
+
|
| 52 |
+
st.markdown("# The 🦙 Leaderboard")
|
| 53 |
+
|
| 54 |
+
st.markdown(
|
| 55 |
+
f"This is a leaderboard of **{len(dataframe)}** llama classification models.\n\n"
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
st.markdown(
|
| 59 |
+
"Please click on the model's name to be redirected to its model card which includes documentation and examples on how to use it."
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
dataset_df = dataframe.reset_index(drop=True)
|
| 63 |
+
dataset_df.index += 1
|
| 64 |
+
|
| 65 |
+
# turn the model ids into clickable links
|
| 66 |
+
dataset_df["Model"] = dataset_df["Model"].apply(make_clickable)
|
| 67 |
+
table_html = dataset_df.to_html(escape=False)
|
| 68 |
+
table_html = table_html.replace("<th>", '<th align="left">') # left-align the headers
|
| 69 |
+
st.write(table_html, unsafe_allow_html=True)
|