Spaces:
Running
Running
burtenshaw
commited on
Commit
•
6b07e4a
0
Parent(s):
first commit
Browse files- .env.example +1 -0
- .gitignore +11 -0
- .python-version +1 -0
- README.md +0 -0
- app.py +172 -0
- pyproject.toml +10 -0
- requirements.txt +55 -0
- uv.lock +0 -0
.env.example
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
HF_TOKEN=your_hugging_face_token_here
|
.gitignore
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python-generated files
|
2 |
+
__pycache__/
|
3 |
+
*.py[oc]
|
4 |
+
build/
|
5 |
+
dist/
|
6 |
+
wheels/
|
7 |
+
*.egg-info
|
8 |
+
|
9 |
+
# Virtual environments
|
10 |
+
.venv
|
11 |
+
.env
|
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
3.11
|
README.md
ADDED
File without changes
|
app.py
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import gradio as gr
|
3 |
+
from urllib.parse import urlencode
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import os
|
6 |
+
|
7 |
+
# Load environment variables
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
|
11 |
+
def create_image(stats, username):
|
12 |
+
url = "https://argilla.imglab-cdn.net/dibt/dibt_v2.png"
|
13 |
+
|
14 |
+
total_stats = stats["Total Statistics"]
|
15 |
+
top_items = stats["Most Popular Items"]
|
16 |
+
|
17 |
+
text = f"""<span size="12pt" weight="bold">Hugging Face ❤️ {username} in 2024</span>
|
18 |
+
|
19 |
+
<span weight="bold">{total_stats['Model Downloads']:,}</span> model downloads
|
20 |
+
<span weight="bold">{total_stats['Model Likes']:,}</span> model likes
|
21 |
+
<span weight="bold">{total_stats['Dataset Downloads']:,}</span> dataset downloads
|
22 |
+
<span weight="bold">{total_stats['Dataset Likes']:,}</span> dataset likes
|
23 |
+
|
24 |
+
<span size="10pt">Most Popular Contributions:</span>
|
25 |
+
Model: <span weight="bold">{top_items['Top Model']['name']}</span>
|
26 |
+
({top_items['Top Model']['downloads']:,} downloads, {top_items['Top Model']['likes']} likes)
|
27 |
+
Dataset: <span weight="bold">{top_items['Top Dataset']['name']}</span>
|
28 |
+
({top_items['Top Dataset']['downloads']:,} downloads, {top_items['Top Dataset']['likes']} likes)
|
29 |
+
Space: <span weight="bold">{top_items['Top Space']['name']}</span>
|
30 |
+
({top_items['Top Space']['likes']} likes)"""
|
31 |
+
|
32 |
+
params = {
|
33 |
+
"width": "1200",
|
34 |
+
"text": text,
|
35 |
+
"text-width": "800",
|
36 |
+
"text-height": "600",
|
37 |
+
"text-padding": "60",
|
38 |
+
"text-color": "39,71,111",
|
39 |
+
"text-x": "460",
|
40 |
+
"text-y": "40",
|
41 |
+
"format": "png",
|
42 |
+
"dpr": "2",
|
43 |
+
}
|
44 |
+
|
45 |
+
return f"{url}?{urlencode(params)}"
|
46 |
+
|
47 |
+
|
48 |
+
def get_user_stats(username):
|
49 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
50 |
+
|
51 |
+
# Get models stats
|
52 |
+
models_response = requests.get(
|
53 |
+
"https://huggingface.co/api/models",
|
54 |
+
params={"author": username, "full": "True"},
|
55 |
+
headers=headers,
|
56 |
+
)
|
57 |
+
models = models_response.json()
|
58 |
+
|
59 |
+
# Get datasets stats
|
60 |
+
datasets_response = requests.get(
|
61 |
+
"https://huggingface.co/api/datasets",
|
62 |
+
params={"author": username, "full": "True"},
|
63 |
+
headers=headers,
|
64 |
+
)
|
65 |
+
datasets = datasets_response.json()
|
66 |
+
|
67 |
+
# Get spaces stats
|
68 |
+
spaces_response = requests.get(
|
69 |
+
"https://huggingface.co/api/spaces",
|
70 |
+
params={"author": username, "full": "True"},
|
71 |
+
headers=headers,
|
72 |
+
)
|
73 |
+
spaces = spaces_response.json()
|
74 |
+
|
75 |
+
# Calculate totals
|
76 |
+
total_model_downloads = sum(model.get("downloads", 0) for model in models)
|
77 |
+
total_model_likes = sum(model.get("likes", 0) for model in models)
|
78 |
+
total_dataset_downloads = sum(dataset.get("downloads", 0) for dataset in datasets)
|
79 |
+
total_dataset_likes = sum(dataset.get("likes", 0) for dataset in datasets)
|
80 |
+
total_space_likes = sum(space.get("likes", 0) for space in spaces)
|
81 |
+
|
82 |
+
# Find most liked items
|
83 |
+
most_liked_model = max(models, key=lambda x: x.get("likes", 0), default=None)
|
84 |
+
most_liked_dataset = max(datasets, key=lambda x: x.get("likes", 0), default=None)
|
85 |
+
most_liked_space = max(spaces, key=lambda x: x.get("likes", 0), default=None)
|
86 |
+
|
87 |
+
stats = {
|
88 |
+
"Total Statistics": {
|
89 |
+
"Model Downloads": total_model_downloads,
|
90 |
+
"Model Likes": total_model_likes,
|
91 |
+
"Dataset Downloads": total_dataset_downloads,
|
92 |
+
"Dataset Likes": total_dataset_likes,
|
93 |
+
"Space Likes": total_space_likes,
|
94 |
+
},
|
95 |
+
"Most Popular Items": {
|
96 |
+
"Top Model": {
|
97 |
+
"name": most_liked_model.get("modelId", "None")
|
98 |
+
if most_liked_model
|
99 |
+
else "None",
|
100 |
+
"likes": most_liked_model.get("likes", 0) if most_liked_model else 0,
|
101 |
+
"downloads": most_liked_model.get("downloads", 0)
|
102 |
+
if most_liked_model
|
103 |
+
else 0,
|
104 |
+
},
|
105 |
+
"Top Dataset": {
|
106 |
+
"name": most_liked_dataset.get("id", "None")
|
107 |
+
if most_liked_dataset
|
108 |
+
else "None",
|
109 |
+
"likes": most_liked_dataset.get("likes", 0)
|
110 |
+
if most_liked_dataset
|
111 |
+
else 0,
|
112 |
+
"downloads": most_liked_dataset.get("downloads", 0)
|
113 |
+
if most_liked_dataset
|
114 |
+
else 0,
|
115 |
+
},
|
116 |
+
"Top Space": {
|
117 |
+
"name": most_liked_space.get("id", "None")
|
118 |
+
if most_liked_space
|
119 |
+
else "None",
|
120 |
+
"likes": most_liked_space.get("likes", 0) if most_liked_space else 0,
|
121 |
+
},
|
122 |
+
},
|
123 |
+
}
|
124 |
+
|
125 |
+
# Generate image URL
|
126 |
+
image_url = create_image(stats, username)
|
127 |
+
|
128 |
+
return image_url
|
129 |
+
|
130 |
+
|
131 |
+
with gr.Blocks(title="Hugging Face Community Stats") as demo:
|
132 |
+
gr.Markdown("# Hugging Face Community Recap")
|
133 |
+
gr.Markdown(
|
134 |
+
"Enter a username to see their impact and top contributions across the Hugging Face Hub"
|
135 |
+
)
|
136 |
+
|
137 |
+
with gr.Row():
|
138 |
+
username_input = gr.Textbox(
|
139 |
+
label="Username", placeholder="Enter Hugging Face username...", scale=4
|
140 |
+
)
|
141 |
+
submit_btn = gr.Button("Get Stats", scale=1)
|
142 |
+
|
143 |
+
with gr.Row():
|
144 |
+
with gr.Column():
|
145 |
+
stats_image = gr.Markdown()
|
146 |
+
|
147 |
+
# Add example usernames
|
148 |
+
gr.Examples(
|
149 |
+
examples=[["merve"], ["mlabonne"], ["bartowski"]],
|
150 |
+
inputs=username_input,
|
151 |
+
label="Try these examples",
|
152 |
+
)
|
153 |
+
|
154 |
+
def format_markdown(image_url):
|
155 |
+
return f"![Hugging Face Stats]({image_url})"
|
156 |
+
|
157 |
+
# Handle submission
|
158 |
+
submit_btn.click(
|
159 |
+
fn=lambda x: format_markdown(get_user_stats(x)),
|
160 |
+
inputs=username_input,
|
161 |
+
outputs=stats_image,
|
162 |
+
api_name="get_stats",
|
163 |
+
)
|
164 |
+
# Also trigger on enter key
|
165 |
+
username_input.submit(
|
166 |
+
fn=lambda x: format_markdown(get_user_stats(x)),
|
167 |
+
inputs=username_input,
|
168 |
+
outputs=stats_image,
|
169 |
+
)
|
170 |
+
|
171 |
+
if __name__ == "__main__":
|
172 |
+
demo.launch()
|
pyproject.toml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[project]
|
2 |
+
name = "hub-recap"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = "Add your description here"
|
5 |
+
readme = "README.md"
|
6 |
+
requires-python = ">=3.11"
|
7 |
+
dependencies = [
|
8 |
+
"gradio>=5.9.1",
|
9 |
+
"requests>=2.32.3",
|
10 |
+
]
|
requirements.txt
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file was autogenerated by uv via the following command:
|
2 |
+
# uv export --format requirements-txt --no-hashes
|
3 |
+
aiofiles==23.2.1
|
4 |
+
annotated-types==0.7.0
|
5 |
+
anyio==4.7.0
|
6 |
+
audioop-lts==0.2.1 ; python_full_version >= '3.13'
|
7 |
+
certifi==2024.12.14
|
8 |
+
charset-normalizer==3.4.0
|
9 |
+
click==8.1.7 ; sys_platform != 'emscripten'
|
10 |
+
colorama==0.4.6 ; platform_system == 'Windows'
|
11 |
+
fastapi==0.115.6
|
12 |
+
ffmpy==0.4.0
|
13 |
+
filelock==3.16.1
|
14 |
+
fsspec==2024.10.0
|
15 |
+
gradio==5.9.1
|
16 |
+
gradio-client==1.5.2
|
17 |
+
h11==0.14.0
|
18 |
+
httpcore==1.0.7
|
19 |
+
httpx==0.28.1
|
20 |
+
huggingface-hub==0.27.0
|
21 |
+
idna==3.10
|
22 |
+
jinja2==3.1.4
|
23 |
+
markdown-it-py==3.0.0 ; sys_platform != 'emscripten'
|
24 |
+
markupsafe==2.1.5
|
25 |
+
mdurl==0.1.2 ; sys_platform != 'emscripten'
|
26 |
+
numpy==2.2.0
|
27 |
+
orjson==3.10.12
|
28 |
+
packaging==24.2
|
29 |
+
pandas==2.2.3
|
30 |
+
pillow==11.0.0
|
31 |
+
pydantic==2.10.4
|
32 |
+
pydantic-core==2.27.2
|
33 |
+
pydub==0.25.1
|
34 |
+
pygments==2.18.0 ; sys_platform != 'emscripten'
|
35 |
+
python-dateutil==2.9.0.post0
|
36 |
+
python-multipart==0.0.20
|
37 |
+
pytz==2024.2
|
38 |
+
pyyaml==6.0.2
|
39 |
+
requests==2.32.3
|
40 |
+
rich==13.9.4 ; sys_platform != 'emscripten'
|
41 |
+
ruff==0.8.3 ; sys_platform != 'emscripten'
|
42 |
+
safehttpx==0.1.6
|
43 |
+
semantic-version==2.10.0
|
44 |
+
shellingham==1.5.4 ; sys_platform != 'emscripten'
|
45 |
+
six==1.17.0
|
46 |
+
sniffio==1.3.1
|
47 |
+
starlette==0.41.3
|
48 |
+
tomlkit==0.13.2
|
49 |
+
tqdm==4.67.1
|
50 |
+
typer==0.15.1 ; sys_platform != 'emscripten'
|
51 |
+
typing-extensions==4.12.2
|
52 |
+
tzdata==2024.2
|
53 |
+
urllib3==2.2.3
|
54 |
+
uvicorn==0.34.0 ; sys_platform != 'emscripten'
|
55 |
+
websockets==14.1
|
uv.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|