GGUF_tracker / app.py
RichardErkhov's picture
Update app.py
bc4be63 verified
raw
history blame
4.43 kB
import gradio as gr
import pandas as pd
from huggingface_hub import HfApi
# Initialize Hugging Face API
api = HfApi()
# Constants
GGUF_TAG = "gguf"
CHUNK_SIZE = 1000
# Clickable links function
def clickable(x, which_one):
if which_one == "models":
if x not in ["Not Found", "Unknown"]:
return f'<a target="_blank" href="https://huggingface.co/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
else:
return "Not Found"
else:
if x != "Not Found":
return f'<a target="_blank" href="https://huggingface.co/{which_one}/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
return "Not Found"
# Fetch models and return a DataFrame with clickable links
def fetch_models():
models = api.list_models(filter=GGUF_TAG, full=True)
data = []
for model in models:
model_id = model.id if model.id else "Not Found"
author = model.author if model.author else "Unknown"
data.append({
"Model ID": model_id,
"Author Name": author,
"Downloads (30d)": model.downloads or 0,
"Likes": model.likes or 0,
"Created At": model.created_at.isoformat() if model.created_at else "N/A",
"Last Modified": model.last_modified.isoformat() if model.last_modified else "N/A",
})
df = pd.DataFrame(data)
# Apply clickable links
df["Model ID"] = df["Model ID"].apply(lambda x: clickable(x, "models"))
df["Author Name"] = df["Author Name"].apply(lambda x: clickable(x, "models"))
return df
# Prepare authors DataFrame
def prepare_authors_df(models_df):
# Extract the actual author name from the link (if needed)
authors_df = models_df.copy()
authors_df["Clean Author Name"] = authors_df["Author Name"].str.extract(r'href="https://huggingface\.co/(.*?)"')
grouped = authors_df.groupby("Clean Author Name").agg(
Models_Count=("Model ID", "count"),
Total_Downloads=("Downloads (30d)", "sum")
).reset_index()
grouped.rename(columns={"Clean Author Name": "Author Name"}, inplace=True)
return grouped.sort_values(by="Models_Count", ascending=False)
all_models_df = fetch_models().sort_values(by="Downloads (30d)", ascending=False)
authors_df = prepare_authors_df(all_models_df)
def update_model_table(start_idx):
# Instead of messing with model_table.value, just return more rows from all_models_df
new_end = start_idx + CHUNK_SIZE
# Slice the global DataFrame that already has HTML formatting
combined_df = all_models_df.iloc[:new_end].copy()
return combined_df, new_end
with gr.Blocks() as demo:
gr.Markdown("""
# 🚀GGUF Tracker🚀
Welcome to 🚀**GGUF Tracker**🚀, a live-updating leaderboard for all things GGUF on 🚀Hugging Face. It’s simple: the stats refresh every hour, giving you the latest numbers on downloads, likes, and top contributors. Whether you're here to find models or just check out who's 🚀killing it, this is the place.
By the way, I’m 🚀Richard Erkhov, and you can check out more of what I’m working on at my [🌟**github**](https://github.com/RichardErkhov), [🌟**huggingface**](https://huggingface.co/RichardErkhov) or [🌟**erkhov.com**](https://erkhov.com). Go take a look—I think you’ll like what you find.
""")
# Existing content
gr.Markdown("# GGUF Models and Authors Leaderboard")
with gr.Tabs():
with gr.TabItem("Models"):
# Initially load the first CHUNK_SIZE rows
model_table = gr.DataFrame(
value=all_models_df.iloc[:CHUNK_SIZE],
interactive=True,
label="GGUF Models",
wrap=True,
datatype=["markdown", "markdown", "number", "number", "str", "str"]
)
load_more_button = gr.Button("Load More Models")
start_idx = gr.State(value=CHUNK_SIZE)
load_more_button.click(fn=update_model_table, inputs=start_idx, outputs=[model_table, start_idx])
with gr.TabItem("Authors"):
gr.DataFrame(
value=authors_df,
interactive=False,
label="Authors",
wrap=True,
datatype=["str", "number", "number"]
)
demo.launch()