Spaces:
Running
Running
burtenshaw
commited on
Commit
β’
6da808e
1
Parent(s):
a145493
swap round images and share app changes
Browse files- app.py +83 -14
- images/{models.png β dataset.png} +0 -0
- images/{datasets.png β model.png} +0 -0
- images/{spaces.png β space.png} +0 -0
app.py
CHANGED
@@ -10,25 +10,94 @@ DEFAULT_IMAGE = "https://hub-recap.imglab-cdn.net/default.jpg?width=1200&text=%3
|
|
10 |
|
11 |
|
12 |
def create_image(stats, username):
|
13 |
-
|
14 |
-
|
15 |
total_stats = stats["Total Statistics"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
top_items = stats["Most Popular Items"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
<span weight="bold">{total_stats['Dataset Likes']:,}</span> dataset likes
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
({top_items['Top Model']['downloads']:,} downloads, {top_items['Top Model']['likes']} likes)
|
28 |
-
Dataset: <span weight="bold">{top_items['Top Dataset']['name']}</span>
|
29 |
-
({top_items['Top Dataset']['downloads']:,} downloads, {top_items['Top Dataset']['likes']} likes)
|
30 |
-
Space: <span weight="bold">{top_items['Top Space']['name']}</span>
|
31 |
-
({top_items['Top Space']['likes']} likes)"""
|
32 |
|
33 |
params = {
|
34 |
"width": "1200",
|
|
|
10 |
|
11 |
|
12 |
def create_image(stats, username):
|
13 |
+
# Determine which image to use based on highest value
|
|
|
14 |
total_stats = stats["Total Statistics"]
|
15 |
+
model_activity = total_stats["Model Downloads"] + total_stats["Model Likes"]
|
16 |
+
dataset_activity = total_stats["Dataset Downloads"] + total_stats["Dataset Likes"]
|
17 |
+
space_activity = total_stats["Space Likes"]
|
18 |
+
|
19 |
+
# Choose base image URL based on highest activity
|
20 |
+
if model_activity >= max(dataset_activity, space_activity):
|
21 |
+
url = "https://hub-recap.imglab-cdn.net/images/model.png"
|
22 |
+
avatar = "Model Pro"
|
23 |
+
elif dataset_activity >= max(model_activity, space_activity):
|
24 |
+
url = "https://hub-recap.imglab-cdn.net/images/dataset.png"
|
25 |
+
avatar = "Dataset Guru"
|
26 |
+
else:
|
27 |
+
url = "https://hub-recap.imglab-cdn.net/images/space.png"
|
28 |
+
avatar = "Space Artiste"
|
29 |
+
|
30 |
+
# Build text content with proper formatting
|
31 |
+
text_parts = []
|
32 |
+
|
33 |
+
# Header
|
34 |
+
text_parts.append(
|
35 |
+
f'<span size="12pt" weight="bold">Hugging Face β€οΈ {username} in 2024</span>'
|
36 |
+
)
|
37 |
+
text_parts.append("") # Empty line for spacing
|
38 |
+
|
39 |
+
# Stats section
|
40 |
+
stats_lines = []
|
41 |
+
if total_stats["Model Downloads"] > 0:
|
42 |
+
stats_lines.append(
|
43 |
+
f'<span weight="bold">{total_stats["Model Downloads"]:,}</span> model downloads'
|
44 |
+
)
|
45 |
+
if total_stats["Model Likes"] > 0:
|
46 |
+
stats_lines.append(
|
47 |
+
f'<span weight="bold">{total_stats["Model Likes"]:,}</span> model likes'
|
48 |
+
)
|
49 |
+
if total_stats["Dataset Downloads"] > 0:
|
50 |
+
stats_lines.append(
|
51 |
+
f'<span weight="bold">{total_stats["Dataset Downloads"]:,}</span> dataset downloads'
|
52 |
+
)
|
53 |
+
if total_stats["Dataset Likes"] > 0:
|
54 |
+
stats_lines.append(
|
55 |
+
f'<span weight="bold">{total_stats["Dataset Likes"]:,}</span> dataset likes'
|
56 |
+
)
|
57 |
+
if total_stats["Space Likes"] > 0:
|
58 |
+
stats_lines.append(
|
59 |
+
f'<span weight="bold">{total_stats["Space Likes"]:,}</span> space likes'
|
60 |
+
)
|
61 |
+
|
62 |
+
if stats_lines:
|
63 |
+
text_parts.extend(stats_lines)
|
64 |
+
text_parts.append("") # Empty line for spacing
|
65 |
+
|
66 |
+
# Popular items section
|
67 |
top_items = stats["Most Popular Items"]
|
68 |
+
if any(
|
69 |
+
item["likes"] > 0 or item.get("downloads", 0) > 0 for item in top_items.values()
|
70 |
+
):
|
71 |
+
text_parts.append('<span size="10pt">Most Popular Contributions:</span>')
|
72 |
+
|
73 |
+
if top_items["Top Model"]["downloads"] > 0:
|
74 |
+
text_parts.append(
|
75 |
+
f'Model: <span weight="bold">{top_items["Top Model"]["name"]}</span>'
|
76 |
+
)
|
77 |
+
text_parts.append(
|
78 |
+
f' ({top_items["Top Model"]["downloads"]:,} downloads, {top_items["Top Model"]["likes"]} likes)'
|
79 |
+
)
|
80 |
+
|
81 |
+
if top_items["Top Dataset"]["downloads"] > 0:
|
82 |
+
text_parts.append(
|
83 |
+
f'Dataset: <span weight="bold">{top_items["Top Dataset"]["name"]}</span>'
|
84 |
+
)
|
85 |
+
text_parts.append(
|
86 |
+
f' ({top_items["Top Dataset"]["downloads"]:,} downloads, {top_items["Top Dataset"]["likes"]} likes)'
|
87 |
+
)
|
88 |
|
89 |
+
if top_items["Top Space"]["likes"] > 0:
|
90 |
+
text_parts.append(
|
91 |
+
f'Space: <span weight="bold">{top_items["Top Space"]["name"]}</span>'
|
92 |
+
)
|
93 |
+
text_parts.append(f' ({top_items["Top Space"]["likes"]} likes)')
|
94 |
|
95 |
+
# Add avatar type at the end
|
96 |
+
text_parts.append("") # Empty line for spacing
|
97 |
+
text_parts.append(f"You are {avatar}! π")
|
|
|
98 |
|
99 |
+
# Join all parts with newlines
|
100 |
+
text = "\n".join(text_parts)
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
params = {
|
103 |
"width": "1200",
|
images/{models.png β dataset.png}
RENAMED
File without changes
|
images/{datasets.png β model.png}
RENAMED
File without changes
|
images/{spaces.png β space.png}
RENAMED
File without changes
|