File size: 3,007 Bytes
635c44a
 
 
 
 
 
 
476d25a
635c44a
 
 
 
 
 
 
9071c4c
635c44a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
949cdc1
635c44a
 
 
 
 
 
 
 
 
 
 
bef0c51
635c44a
 
 
 
 
 
 
 
 
 
 
 
 
68da3e6
 
 
 
 
635c44a
 
 
5268424
d478878
5268424
635c44a
476d25a
 
 
 
33720db
476d25a
f4f94db
 
476d25a
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
70
71
72
73
74
75
76
77
78
79
80
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
import streamlit.components.v1 as components

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="llama-leaderboard")
    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"]
    return 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(
    "This is the most comprehensive leaderboard of llama image classifier models published. You can try out the different models below"
)

st.markdown(
    "Please click on the model's name to be redirected to its model card which includes documentation."
)

# turn the model ids into clickable links
dataframe["Model"] = dataframe["Model"].apply(make_clickable)
dataframe = dataframe.sort_values(by=['Accuracy'], ascending=False)
table_html = dataframe.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)

embed_gradio = components.html(
        """
        <iframe src="https://hf.space/embed/osanseviero/llama-classifiers/+" frameBorder="0" height="1200" width="700" title="Gradio app" class="container p-0 flex-grow space-iframe" allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"></iframe>
        """,
        height=1200,
        width=700
    )