Spaces:
Running
Running
burtenshaw
commited on
Commit
·
fab0ae1
1
Parent(s):
24869d6
add defaults and
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
from urllib.parse import urlencode
|
4 |
-
|
5 |
import os
|
|
|
6 |
|
7 |
# Load environment variables
|
8 |
|
|
|
|
|
9 |
|
10 |
def create_image(stats, username):
|
11 |
url = "https://argilla.imglab-cdn.net/dibt/dibt_v2.png"
|
@@ -44,6 +46,13 @@ Space: <span weight="bold">{top_items['Top Space']['name']}</span>
|
|
44 |
return f"{url}?{urlencode(params)}"
|
45 |
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def get_user_stats(username):
|
48 |
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
49 |
|
@@ -53,7 +62,12 @@ def get_user_stats(username):
|
|
53 |
params={"author": username, "full": "True"},
|
54 |
headers=headers,
|
55 |
)
|
56 |
-
models
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
# Get datasets stats
|
59 |
datasets_response = requests.get(
|
@@ -61,7 +75,12 @@ def get_user_stats(username):
|
|
61 |
params={"author": username, "full": "True"},
|
62 |
headers=headers,
|
63 |
)
|
64 |
-
datasets
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
# Get spaces stats
|
67 |
spaces_response = requests.get(
|
@@ -69,16 +88,21 @@ def get_user_stats(username):
|
|
69 |
params={"author": username, "full": "True"},
|
70 |
headers=headers,
|
71 |
)
|
72 |
-
spaces
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
total_model_downloads = sum(model.get("downloads", 0) for model in models)
|
76 |
total_model_likes = sum(model.get("likes", 0) for model in models)
|
77 |
total_dataset_downloads = sum(dataset.get("downloads", 0) for dataset in datasets)
|
78 |
total_dataset_likes = sum(dataset.get("likes", 0) for dataset in datasets)
|
79 |
total_space_likes = sum(space.get("likes", 0) for space in spaces)
|
80 |
|
81 |
-
# Find most liked items
|
82 |
most_liked_model = max(models, key=lambda x: x.get("likes", 0), default=None)
|
83 |
most_liked_dataset = max(datasets, key=lambda x: x.get("likes", 0), default=None)
|
84 |
most_liked_space = max(spaces, key=lambda x: x.get("likes", 0), default=None)
|
@@ -135,13 +159,18 @@ with gr.Blocks(title="Hugging Face Community Stats") as demo:
|
|
135 |
|
136 |
with gr.Row():
|
137 |
username_input = gr.Textbox(
|
138 |
-
label=
|
|
|
|
|
|
|
139 |
)
|
140 |
-
submit_btn = gr.Button("Get Stats", scale=
|
141 |
|
142 |
with gr.Row():
|
143 |
with gr.Column():
|
144 |
-
stats_image = gr.Markdown(
|
|
|
|
|
145 |
|
146 |
# Add example usernames
|
147 |
gr.Examples(
|
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
from urllib.parse import urlencode
|
|
|
4 |
import os
|
5 |
+
from datetime import datetime
|
6 |
|
7 |
# Load environment variables
|
8 |
|
9 |
+
DEFAULT_IMAGE = "https://argilla.imglab-cdn.net/dibt/dibt_v2.png?width=1200&text=%3Cspan+size%3D%2212pt%22+weight%3D%22bold%22%3EHugging+Face++%E2%9D%A4%EF%B8%8F+bartowski+in+2024%3C%2Fspan%3E%0A%0A%3Cspan+weight%3D%22bold%22%3E3%2C057%2C452%3C%2Fspan%3E+model+downloads%0A%3Cspan+weight%3D%22bold%22%3E5%2C404%3C%2Fspan%3E+model+likes%0A%3Cspan+weight%3D%22bold%22%3E0%3C%2Fspan%3E+dataset+downloads%0A%3Cspan+weight%3D%22bold%22%3E0%3C%2Fspan%3E+dataset+likes%0A%0A%3Cspan+size%3D%2210pt%22%3EMost+Popular+Contributions%3A%3C%2Fspan%3E%0AModel%3A+%3Cspan+weight%3D%22bold%22%3Ebartowski%2Fgemma-2-9b-it-GGUF%3C%2Fspan%3E%0A++%2844%2C256+downloads%2C+196+likes%29%0ADataset%3A+%3Cspan+weight%3D%22bold%22%3ENone%3C%2Fspan%3E%0A++%280+downloads%2C+0+likes%29%0ASpace%3A+%3Cspan+weight%3D%22bold%22%3Ebartowski%2Fgguf-metadata-updater%3C%2Fspan%3E%0A++%287+likes%29&text-width=800&text-height=600&text-padding=60&text-color=39%2C71%2C111&text-x=460&text-y=40&format=png&dpr=2"
|
10 |
+
|
11 |
|
12 |
def create_image(stats, username):
|
13 |
url = "https://argilla.imglab-cdn.net/dibt/dibt_v2.png"
|
|
|
46 |
return f"{url}?{urlencode(params)}"
|
47 |
|
48 |
|
49 |
+
def is_from_2024(created_at_str):
|
50 |
+
if not created_at_str:
|
51 |
+
return False
|
52 |
+
created_at = datetime.strptime(created_at_str, "%Y-%m-%dT%H:%M:%S.%fZ")
|
53 |
+
return created_at.year == 2024
|
54 |
+
|
55 |
+
|
56 |
def get_user_stats(username):
|
57 |
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
58 |
|
|
|
62 |
params={"author": username, "full": "True"},
|
63 |
headers=headers,
|
64 |
)
|
65 |
+
# Filter for 2024 models only
|
66 |
+
models = [
|
67 |
+
model
|
68 |
+
for model in models_response.json()
|
69 |
+
if is_from_2024(model.get("createdAt"))
|
70 |
+
]
|
71 |
|
72 |
# Get datasets stats
|
73 |
datasets_response = requests.get(
|
|
|
75 |
params={"author": username, "full": "True"},
|
76 |
headers=headers,
|
77 |
)
|
78 |
+
# Filter for 2024 datasets only
|
79 |
+
datasets = [
|
80 |
+
dataset
|
81 |
+
for dataset in datasets_response.json()
|
82 |
+
if is_from_2024(dataset.get("createdAt"))
|
83 |
+
]
|
84 |
|
85 |
# Get spaces stats
|
86 |
spaces_response = requests.get(
|
|
|
88 |
params={"author": username, "full": "True"},
|
89 |
headers=headers,
|
90 |
)
|
91 |
+
# Filter for 2024 spaces only
|
92 |
+
spaces = [
|
93 |
+
space
|
94 |
+
for space in spaces_response.json()
|
95 |
+
if is_from_2024(space.get("createdAt"))
|
96 |
+
]
|
97 |
+
|
98 |
+
# Calculate totals for 2024 items only
|
99 |
total_model_downloads = sum(model.get("downloads", 0) for model in models)
|
100 |
total_model_likes = sum(model.get("likes", 0) for model in models)
|
101 |
total_dataset_downloads = sum(dataset.get("downloads", 0) for dataset in datasets)
|
102 |
total_dataset_likes = sum(dataset.get("likes", 0) for dataset in datasets)
|
103 |
total_space_likes = sum(space.get("likes", 0) for space in spaces)
|
104 |
|
105 |
+
# Find most liked items from 2024
|
106 |
most_liked_model = max(models, key=lambda x: x.get("likes", 0), default=None)
|
107 |
most_liked_dataset = max(datasets, key=lambda x: x.get("likes", 0), default=None)
|
108 |
most_liked_space = max(spaces, key=lambda x: x.get("likes", 0), default=None)
|
|
|
159 |
|
160 |
with gr.Row():
|
161 |
username_input = gr.Textbox(
|
162 |
+
label="Hub username",
|
163 |
+
placeholder="Enter Hugging Face username...",
|
164 |
+
scale=6,
|
165 |
+
value="bartowski",
|
166 |
)
|
167 |
+
submit_btn = gr.Button("Get Stats", scale=6)
|
168 |
|
169 |
with gr.Row():
|
170 |
with gr.Column():
|
171 |
+
stats_image = gr.Markdown(
|
172 |
+
f"![Hugging Face Stats]({DEFAULT_IMAGE})"
|
173 |
+
)
|
174 |
|
175 |
# Add example usernames
|
176 |
gr.Examples(
|