Spaces:
Runtime error
Runtime error
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 | |
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 | |
) |