Spaces:
Running
Running
RichardErkhov
commited on
Commit
•
f39233d
1
Parent(s):
33a29ff
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from huggingface_hub import HfApi
|
4 |
+
|
5 |
+
# Initialize Hugging Face API
|
6 |
+
api = HfApi()
|
7 |
+
|
8 |
+
# Constants
|
9 |
+
GGUF_TAG = "gguf"
|
10 |
+
CHUNK_SIZE = 1000
|
11 |
+
|
12 |
+
# Clickable links function
|
13 |
+
def clickable(x, which_one):
|
14 |
+
if which_one == "models":
|
15 |
+
if x not in ["Not Found", "Unknown"]:
|
16 |
+
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>'
|
17 |
+
else:
|
18 |
+
return "Not Found"
|
19 |
+
else:
|
20 |
+
if x != "Not Found":
|
21 |
+
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>'
|
22 |
+
return "Not Found"
|
23 |
+
|
24 |
+
# Fetch models and return a DataFrame with clickable links
|
25 |
+
def fetch_models():
|
26 |
+
models = api.list_models(filter=GGUF_TAG, full=True)
|
27 |
+
data = []
|
28 |
+
for model in models:
|
29 |
+
model_id = model.id if model.id else "Not Found"
|
30 |
+
author = model.author if model.author else "Unknown"
|
31 |
+
data.append({
|
32 |
+
"Model ID": model_id,
|
33 |
+
"Author Name": author,
|
34 |
+
"Downloads (30d)": model.downloads or 0,
|
35 |
+
"Likes": model.likes or 0,
|
36 |
+
"Created At": model.created_at.isoformat() if model.created_at else "N/A",
|
37 |
+
"Last Modified": model.last_modified.isoformat() if model.last_modified else "N/A",
|
38 |
+
})
|
39 |
+
df = pd.DataFrame(data)
|
40 |
+
# Apply clickable links
|
41 |
+
df["Model ID"] = df["Model ID"].apply(lambda x: clickable(x, "models"))
|
42 |
+
df["Author Name"] = df["Author Name"].apply(lambda x: clickable(x, "models"))
|
43 |
+
return df
|
44 |
+
|
45 |
+
# Prepare authors DataFrame
|
46 |
+
def prepare_authors_df(models_df):
|
47 |
+
# Extract the actual author name from the link (if needed)
|
48 |
+
authors_df = models_df.copy()
|
49 |
+
authors_df["Clean Author Name"] = authors_df["Author Name"].str.extract(r'href="https://huggingface\.co/(.*?)"')
|
50 |
+
grouped = authors_df.groupby("Clean Author Name").agg(
|
51 |
+
Models_Count=("Model ID", "count"),
|
52 |
+
Total_Downloads=("Downloads (30d)", "sum")
|
53 |
+
).reset_index()
|
54 |
+
grouped.rename(columns={"Clean Author Name": "Author Name"}, inplace=True)
|
55 |
+
return grouped.sort_values(by="Models_Count", ascending=False)
|
56 |
+
|
57 |
+
all_models_df = fetch_models().sort_values(by="Downloads (30d)", ascending=False)
|
58 |
+
authors_df = prepare_authors_df(all_models_df)
|
59 |
+
|
60 |
+
def update_model_table(start_idx):
|
61 |
+
# Instead of messing with model_table.value, just return more rows from all_models_df
|
62 |
+
new_end = start_idx + CHUNK_SIZE
|
63 |
+
# Slice the global DataFrame that already has HTML formatting
|
64 |
+
combined_df = all_models_df.iloc[:new_end].copy()
|
65 |
+
return combined_df, new_end
|
66 |
+
|
67 |
+
with gr.Blocks() as demo:
|
68 |
+
gr.Markdown("""
|
69 |
+
# GGUF Tracker
|
70 |
+
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.
|
71 |
+
|
72 |
+
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.
|
73 |
+
""")
|
74 |
+
# Existing content
|
75 |
+
gr.Markdown("# GGUF Models and Authors Leaderboard")
|
76 |
+
with gr.Tabs():
|
77 |
+
with gr.TabItem("Models"):
|
78 |
+
# Initially load the first CHUNK_SIZE rows
|
79 |
+
model_table = gr.DataFrame(
|
80 |
+
value=all_models_df.iloc[:CHUNK_SIZE],
|
81 |
+
interactive=True,
|
82 |
+
label="GGUF Models",
|
83 |
+
wrap=True,
|
84 |
+
datatype=["markdown", "markdown", "number", "number", "str", "str"]
|
85 |
+
)
|
86 |
+
load_more_button = gr.Button("Load More Models")
|
87 |
+
start_idx = gr.State(value=CHUNK_SIZE)
|
88 |
+
|
89 |
+
load_more_button.click(fn=update_model_table, inputs=start_idx, outputs=[model_table, start_idx])
|
90 |
+
|
91 |
+
with gr.TabItem("Authors"):
|
92 |
+
gr.DataFrame(
|
93 |
+
value=authors_df,
|
94 |
+
interactive=False,
|
95 |
+
label="Authors",
|
96 |
+
wrap=True,
|
97 |
+
datatype=["str", "number", "number"]
|
98 |
+
)
|
99 |
+
|
100 |
+
demo.launch()
|