Spaces:
Runtime error
Runtime error
File size: 2,079 Bytes
635c44a |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import requests
import json
import pandas as pd
from tqdm.auto import tqdm
import streamlit as st
from huggingface_hub import HfApi, hf_hub_download
from huggingface_hub.repocard import metadata_load
def make_clickable(model_name):
link = "https://huggingface.co/" + model_name
return f'<a target="_blank" href="{link}">{model_name}</a>'
def get_model_ids():
api = HfApi()
models = api.list_models(filter="llamaleaderboard")
model_ids = [x.modelId for x in models]
return model_ids
def get_metadata(model_id):
try:
readme_path = hf_hub_download(model_id, filename="README.md")
return metadata_load(readme_path)
except requests.exceptions.HTTPError:
# 404 README.md not found
return None
def parse_metrics_accuracy(meta):
if "model-index" not in meta:
return None
result = meta["model-index"][0]["results"]
metrics = result[0]["metrics"]
accuracy = metrics[0]["value"]
yield accuracy
@st.cache(ttl=600)
def get_data():
data = []
model_ids = get_model_ids()
for model_id in tqdm(model_ids):
meta = get_metadata(model_id)
if meta is None:
continue
row = {}
row["Model"] = model_id
row["accuracy"] = parse_metrics_accuracy(meta)
data.append(row)
return pd.DataFrame.from_records(data)
dataframe = get_data()
dataframe = dataframe.fillna("")
st.markdown("# The 🦙 Leaderboard")
st.markdown(
f"This is a leaderboard of **{len(dataframe)}** llama classification models.\n\n"
)
st.markdown(
"Please click on the model's name to be redirected to its model card which includes documentation and examples on how to use it."
)
dataset_df = dataframe.reset_index(drop=True)
dataset_df.index += 1
# turn the model ids into clickable links
dataset_df["Model"] = dataset_df["Model"].apply(make_clickable)
table_html = dataset_df.to_html(escape=False)
table_html = table_html.replace("<th>", '<th align="left">') # left-align the headers
st.write(table_html, unsafe_allow_html=True) |