Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
TIME_URL = "https://erkhov.com/huggingspace_time"
|
| 8 |
-
CHUNK_SIZE = 1000
|
| 9 |
-
|
| 10 |
-
def fetch_data():
|
| 11 |
-
response = requests.get(DATA_URL)
|
| 12 |
-
data = response.json()
|
| 13 |
-
return data
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
|
|
|
| 19 |
def clickable(x, which_one):
|
| 20 |
if x in ["Not Found", "Unknown"]:
|
| 21 |
return "Not Found"
|
|
@@ -24,40 +18,55 @@ def clickable(x, which_one):
|
|
| 24 |
else:
|
| 25 |
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>'
|
| 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 |
visible_model_id = df["Model ID"].str.extract(r'>(.*?)<')[0]
|
| 62 |
visible_author_name = df["Author Name"].str.extract(r'>(.*?)<')[0]
|
| 63 |
|
|
@@ -77,8 +86,8 @@ def apply_model_filters(models_df, search_query, min_downloads, min_likes):
|
|
| 77 |
|
| 78 |
return df
|
| 79 |
|
| 80 |
-
def filter_models(
|
| 81 |
-
filtered = apply_model_filters(
|
| 82 |
return filtered.iloc[:CHUNK_SIZE], CHUNK_SIZE, filtered
|
| 83 |
|
| 84 |
def update_model_table(start_idx, filtered_df):
|
|
@@ -86,7 +95,7 @@ def update_model_table(start_idx, filtered_df):
|
|
| 86 |
combined_df = filtered_df.iloc[:new_end].copy()
|
| 87 |
return combined_df, new_end
|
| 88 |
|
| 89 |
-
def apply_author_filters(
|
| 90 |
df = authors_df.copy()
|
| 91 |
|
| 92 |
# Extract visible text for author filtering:
|
|
@@ -107,24 +116,12 @@ def apply_author_filters(authors_df, search_query, min_author_downloads, min_aut
|
|
| 107 |
|
| 108 |
return df
|
| 109 |
|
| 110 |
-
def filter_authors(authors_df, author_search_query, min_author_downloads, min_author_likes):
|
| 111 |
-
filtered_authors = apply_author_filters(authors_df, author_search_query, min_author_downloads, min_author_likes)
|
| 112 |
-
return filtered_authors
|
| 113 |
-
|
| 114 |
-
# Fetch data once at start
|
| 115 |
-
last_updated = fetch_time()
|
| 116 |
-
data = fetch_data()
|
| 117 |
-
all_models_df, authors_df = create_dataframes(data)
|
| 118 |
-
|
| 119 |
-
total_models_count = data["total_models"]
|
| 120 |
-
total_downloads = data["total_downloads"]
|
| 121 |
-
total_likes = all_models_df["Likes"].sum() if "Likes" in all_models_df.columns else 0
|
| 122 |
|
| 123 |
with gr.Blocks() as demo:
|
| 124 |
gr.Markdown(f"""
|
| 125 |
# 🚀GGUF Tracker🚀
|
| 126 |
Welcome to 🚀**GGUF Tracker**🚀, a live-updating leaderboard for all things GGUF on 🚀Hugging Face.
|
| 127 |
-
|
| 128 |
|
| 129 |
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),
|
| 130 |
[🌟**huggingface**](https://huggingface.co/RichardErkhov) or [🌟**erkhov.com**](https://erkhov.com). Go take a look—I think you’ll like what you find.
|
|
@@ -132,8 +129,7 @@ with gr.Blocks() as demo:
|
|
| 132 |
|
| 133 |
gr.Markdown(f"""
|
| 134 |
# GGUF Models and Authors Leaderboard
|
| 135 |
-
**Total Models:** {total_models_count} | **Total Downloads (30d):** {total_downloads} | **Total Likes:** {total_likes}
|
| 136 |
-
**Last Updated:** {last_updated}
|
| 137 |
""")
|
| 138 |
|
| 139 |
with gr.Tabs():
|
|
@@ -155,11 +151,11 @@ with gr.Blocks() as demo:
|
|
| 155 |
|
| 156 |
# States
|
| 157 |
start_idx = gr.State(value=CHUNK_SIZE)
|
| 158 |
-
filtered_df_state = gr.State(value=all_models_df)
|
| 159 |
|
| 160 |
filter_button.click(
|
| 161 |
fn=filter_models,
|
| 162 |
-
inputs=[
|
| 163 |
outputs=[model_table, start_idx, filtered_df_state]
|
| 164 |
)
|
| 165 |
load_more_button.click(fn=update_model_table, inputs=[start_idx, filtered_df_state], outputs=[model_table, start_idx])
|
|
@@ -179,10 +175,14 @@ with gr.Blocks() as demo:
|
|
| 179 |
datatype=["markdown", "number", "number", "number"]
|
| 180 |
)
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
author_filter_button.click(
|
| 183 |
fn=filter_authors,
|
| 184 |
-
inputs=[
|
| 185 |
outputs=author_table
|
| 186 |
)
|
| 187 |
|
| 188 |
-
demo.launch()
|
|
|
|
| 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 x in ["Not Found", "Unknown"]:
|
| 15 |
return "Not Found"
|
|
|
|
| 18 |
else:
|
| 19 |
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>'
|
| 20 |
|
| 21 |
+
# Fetch models and return a DataFrame with clickable links
|
| 22 |
+
def fetch_models():
|
| 23 |
+
models = api.list_models(filter=GGUF_TAG, full=True)
|
| 24 |
+
data = []
|
| 25 |
+
for model in models:
|
| 26 |
+
model_id = model.id if model.id else "Not Found"
|
| 27 |
+
author = model.author if model.author else "Unknown"
|
| 28 |
+
data.append({
|
| 29 |
+
"Model ID": model_id,
|
| 30 |
+
"Author Name": author,
|
| 31 |
+
"Downloads (30d)": model.downloads or 0,
|
| 32 |
+
"Likes": model.likes or 0,
|
| 33 |
+
"Created At": model.created_at.isoformat() if model.created_at else "N/A",
|
| 34 |
+
"Last Modified": model.last_modified.isoformat() if model.last_modified else "N/A",
|
| 35 |
+
})
|
| 36 |
+
df = pd.DataFrame(data)
|
| 37 |
+
# Apply clickable links to models and authors
|
| 38 |
+
df["Model ID"] = df["Model ID"].apply(lambda x: clickable(x, "models"))
|
| 39 |
+
df["Author Name"] = df["Author Name"].apply(lambda x: clickable(x, "models"))
|
| 40 |
+
return df
|
| 41 |
+
|
| 42 |
+
# Prepare authors DataFrame
|
| 43 |
+
def prepare_authors_df(models_df):
|
| 44 |
+
authors_df = models_df.copy()
|
| 45 |
+
# Extract the author name from the href in the clickable link
|
| 46 |
+
authors_df["Clean Author Name"] = authors_df["Author Name"].str.extract(r'href="https://huggingface\.co/(.*?)"')
|
| 47 |
+
|
| 48 |
+
grouped = authors_df.groupby("Clean Author Name").agg(
|
| 49 |
+
Models_Count=("Model ID", "count"),
|
| 50 |
+
Total_Downloads=("Downloads (30d)", "sum"),
|
| 51 |
+
Total_Likes=("Likes", "sum")
|
| 52 |
+
).reset_index()
|
| 53 |
+
|
| 54 |
+
grouped.rename(columns={"Clean Author Name": "Author Name"}, inplace=True)
|
| 55 |
+
grouped["Author Name"] = grouped["Author Name"].apply(lambda x: clickable(x, "models"))
|
| 56 |
+
return grouped.sort_values(by="Models_Count", ascending=False)
|
| 57 |
+
|
| 58 |
+
all_models_df = fetch_models().sort_values(by="Downloads (30d)", ascending=False)
|
| 59 |
+
authors_df = prepare_authors_df(all_models_df)
|
| 60 |
+
|
| 61 |
+
# Calculate totals
|
| 62 |
+
total_models_count = len(all_models_df)
|
| 63 |
+
total_downloads = all_models_df["Downloads (30d)"].sum()
|
| 64 |
+
total_likes = all_models_df["Likes"].sum()
|
| 65 |
+
|
| 66 |
+
def apply_model_filters(search_query, min_downloads, min_likes):
|
| 67 |
+
df = all_models_df.copy()
|
| 68 |
+
|
| 69 |
+
# Extract visible text for filtering purposes:
|
| 70 |
visible_model_id = df["Model ID"].str.extract(r'>(.*?)<')[0]
|
| 71 |
visible_author_name = df["Author Name"].str.extract(r'>(.*?)<')[0]
|
| 72 |
|
|
|
|
| 86 |
|
| 87 |
return df
|
| 88 |
|
| 89 |
+
def filter_models(search_query, min_downloads, min_likes):
|
| 90 |
+
filtered = apply_model_filters(search_query, min_downloads, min_likes)
|
| 91 |
return filtered.iloc[:CHUNK_SIZE], CHUNK_SIZE, filtered
|
| 92 |
|
| 93 |
def update_model_table(start_idx, filtered_df):
|
|
|
|
| 95 |
combined_df = filtered_df.iloc[:new_end].copy()
|
| 96 |
return combined_df, new_end
|
| 97 |
|
| 98 |
+
def apply_author_filters(search_query, min_author_downloads, min_author_likes):
|
| 99 |
df = authors_df.copy()
|
| 100 |
|
| 101 |
# Extract visible text for author filtering:
|
|
|
|
| 116 |
|
| 117 |
return df
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
with gr.Blocks() as demo:
|
| 121 |
gr.Markdown(f"""
|
| 122 |
# 🚀GGUF Tracker🚀
|
| 123 |
Welcome to 🚀**GGUF Tracker**🚀, a live-updating leaderboard for all things GGUF on 🚀Hugging Face.
|
| 124 |
+
Stats refresh every hour, giving you the latest numbers.
|
| 125 |
|
| 126 |
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),
|
| 127 |
[🌟**huggingface**](https://huggingface.co/RichardErkhov) or [🌟**erkhov.com**](https://erkhov.com). Go take a look—I think you’ll like what you find.
|
|
|
|
| 129 |
|
| 130 |
gr.Markdown(f"""
|
| 131 |
# GGUF Models and Authors Leaderboard
|
| 132 |
+
**Total Models:** {total_models_count} | **Total Downloads (30d):** {total_downloads} | **Total Likes:** {total_likes}
|
|
|
|
| 133 |
""")
|
| 134 |
|
| 135 |
with gr.Tabs():
|
|
|
|
| 151 |
|
| 152 |
# States
|
| 153 |
start_idx = gr.State(value=CHUNK_SIZE)
|
| 154 |
+
filtered_df_state = gr.State(value=all_models_df) # holds the currently filtered df
|
| 155 |
|
| 156 |
filter_button.click(
|
| 157 |
fn=filter_models,
|
| 158 |
+
inputs=[search_query, min_downloads, min_likes],
|
| 159 |
outputs=[model_table, start_idx, filtered_df_state]
|
| 160 |
)
|
| 161 |
load_more_button.click(fn=update_model_table, inputs=[start_idx, filtered_df_state], outputs=[model_table, start_idx])
|
|
|
|
| 175 |
datatype=["markdown", "number", "number", "number"]
|
| 176 |
)
|
| 177 |
|
| 178 |
+
def filter_authors(author_search_query, min_author_downloads, min_author_likes):
|
| 179 |
+
filtered_authors = apply_author_filters(author_search_query, min_author_downloads, min_author_likes)
|
| 180 |
+
return filtered_authors
|
| 181 |
+
|
| 182 |
author_filter_button.click(
|
| 183 |
fn=filter_authors,
|
| 184 |
+
inputs=[author_search_query, min_author_downloads, min_author_likes],
|
| 185 |
outputs=author_table
|
| 186 |
)
|
| 187 |
|
| 188 |
+
demo.launch()
|