burtenshaw commited on
Commit
be34010
β€’
1 Parent(s): 5126148

add percentile

Browse files
Files changed (1) hide show
  1. app.py +44 -10
app.py CHANGED
@@ -7,6 +7,9 @@ from datetime import datetime
7
  # Load environment variables
8
 
9
  DEFAULT_IMAGE = "https://hub-recap.imglab-cdn.net/default.jpg?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%3E2%2C020%2C552%3C%2Fspan%3E+model+downloads%0A%3Cspan+weight%3D%22bold%22%3E5%2C407%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++%2843%2C949+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):
@@ -16,20 +19,33 @@ def create_image(stats, username):
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 everything is 0, we show the empty image
21
  if model_activity == 0 and dataset_activity == 0 and space_activity == 0:
22
  url = "https://hub-recap.imglab-cdn.net/images/empty.png"
23
  avatar = "new! We couldn't find your stats on the Hub, maybe in 2025?"
24
  elif model_activity >= max(dataset_activity, space_activity):
25
- url = "https://hub-recap.imglab-cdn.net/images/model.png"
26
- avatar = "Model Pro"
27
  elif dataset_activity >= max(model_activity, space_activity):
28
- url = "https://hub-recap.imglab-cdn.net/images/dataset.png"
29
- avatar = "Dataset Guru"
30
  else:
31
- url = "https://hub-recap.imglab-cdn.net/images/space.png"
32
- avatar = "Space Artiste"
33
 
34
  # Build text content with proper formatting
35
  text_parts = []
@@ -71,7 +87,9 @@ def create_image(stats, username):
71
  if any(
72
  item["likes"] > 0 or item.get("downloads", 0) > 0 for item in top_items.values()
73
  ):
74
- text_parts.append('<span size="9pt" weight="bold">Most Popular Contributions:</span>')
 
 
75
 
76
  if top_items["Top Model"]["downloads"] > 0:
77
  text_parts.append(
@@ -93,11 +111,27 @@ def create_image(stats, username):
93
  text_parts.append(
94
  f'<span size="9pt">Space: <span weight="bold">{top_items["Top Space"]["name"]}</span></span>'
95
  )
96
- text_parts.append(f'<span size="9pt"> ({top_items["Top Space"]["likes"]} likes)</span>')
 
 
97
 
98
- # Add avatar type at the end
99
  text_parts.append("") # Empty line for spacing
100
- text_parts.append(f"<span size='9pt'>You are {avatar}! πŸŽ‰</span>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  # Join all parts with newlines
103
  text = "\n".join(text_parts)
 
7
  # Load environment variables
8
 
9
  DEFAULT_IMAGE = "https://hub-recap.imglab-cdn.net/default.jpg?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%3E2%2C020%2C552%3C%2Fspan%3E+model+downloads%0A%3Cspan+weight%3D%22bold%22%3E5%2C407%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++%2843%2C949+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
+ MAX_MODEL_ACTIVITY = 7354
11
+ MAX_DATASET_ACTIVITY = 6564
12
+ MAX_SPACE_ACTIVITY = 12026
13
 
14
 
15
  def create_image(stats, username):
 
19
  dataset_activity = total_stats["Dataset Downloads"] + total_stats["Dataset Likes"]
20
  space_activity = total_stats["Space Likes"]
21
 
22
+ # Calculate percentiles based on max values (removed min(100,...))
23
+ top_items = stats["Most Popular Items"]
24
+ model_percentile = round(
25
+ (top_items["Top Model"]["likes"] / MAX_MODEL_ACTIVITY) * 100, 2
26
+ )
27
+ dataset_percentile = round(
28
+ (top_items["Top Dataset"]["likes"] / MAX_DATASET_ACTIVITY) * 100, 2
29
+ )
30
+ space_percentile = round(
31
+ (top_items["Top Space"]["likes"] / MAX_SPACE_ACTIVITY) * 100, 2
32
+ )
33
+
34
  # Choose base image URL based on highest activity
35
+ # check if no activity in any category
36
  # if everything is 0, we show the empty image
37
  if model_activity == 0 and dataset_activity == 0 and space_activity == 0:
38
  url = "https://hub-recap.imglab-cdn.net/images/empty.png"
39
  avatar = "new! We couldn't find your stats on the Hub, maybe in 2025?"
40
  elif model_activity >= max(dataset_activity, space_activity):
41
+ url = "https://hub-recap.imglab-cdn.net/images/models.png"
42
+ avatar = f"Model Pro (top {model_percentile}%)"
43
  elif dataset_activity >= max(model_activity, space_activity):
44
+ url = "https://hub-recap.imglab-cdn.net/images/datasets.png"
45
+ avatar = f"Dataset Guru (top {dataset_percentile}%)"
46
  else:
47
+ url = "https://hub-recap.imglab-cdn.net/images/spaces.png"
48
+ avatar = f"Space Artiste (top {space_percentile}%)"
49
 
50
  # Build text content with proper formatting
51
  text_parts = []
 
87
  if any(
88
  item["likes"] > 0 or item.get("downloads", 0) > 0 for item in top_items.values()
89
  ):
90
+ text_parts.append(
91
+ '<span size="9pt" weight="bold">Most Popular Contributions:</span>'
92
+ )
93
 
94
  if top_items["Top Model"]["downloads"] > 0:
95
  text_parts.append(
 
111
  text_parts.append(
112
  f'<span size="9pt">Space: <span weight="bold">{top_items["Top Space"]["name"]}</span></span>'
113
  )
114
+ text_parts.append(
115
+ f'<span size="9pt"> ({top_items["Top Space"]["likes"]} likes)</span>'
116
+ )
117
 
118
+ # Update the avatar message with percentile
119
  text_parts.append("") # Empty line for spacing
120
+ text_parts.append(f'<span size="9pt">You are a {avatar}! πŸŽ‰</span>')
121
+
122
+ # Add additional percentile info if other categories are significant
123
+ other_percentiles = []
124
+ if model_percentile > 0 and "model" not in avatar.lower():
125
+ other_percentiles.append(f"top {model_percentile}% in models")
126
+ if dataset_percentile > 0 and "dataset" not in avatar.lower():
127
+ other_percentiles.append(f"top {dataset_percentile}% in datasets")
128
+ if space_percentile > 0 and "space" not in avatar.lower():
129
+ other_percentiles.append(f"top {space_percentile}% in spaces")
130
+
131
+ if other_percentiles:
132
+ text_parts.append(
133
+ f'<span size="9pt">Also {" and ".join(other_percentiles)}!</span>'
134
+ )
135
 
136
  # Join all parts with newlines
137
  text = "\n".join(text_parts)