kolaslab commited on
Commit
51a3e6d
·
verified ·
1 Parent(s): c315193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -53
app.py CHANGED
@@ -53,6 +53,7 @@ def get_trending_accounts(limit=100):
53
  timeout=30)
54
 
55
  # Process spaces data
 
56
  if spaces_response.status_code == 200:
57
  spaces = spaces_response.json()
58
 
@@ -70,8 +71,10 @@ def get_trending_accounts(limit=100):
70
  # Get top owners by count for spaces
71
  top_owners_spaces = sorted(owner_counts_spaces.items(), key=lambda x: x[1], reverse=True)[:limit]
72
  trending_data["spaces"] = top_owners_spaces
 
73
 
74
  # Process models data
 
75
  if models_response.status_code == 200:
76
  models = models_response.json()
77
 
@@ -89,30 +92,22 @@ def get_trending_accounts(limit=100):
89
  # Get top owners by count for models
90
  top_owners_models = sorted(owner_counts_models.items(), key=lambda x: x[1], reverse=True)[:limit]
91
  trending_data["models"] = top_owners_models
 
92
 
93
- # Combine rankings for overall trending (weighted average)
94
- combined_scores = {}
95
-
96
- # Add scores from spaces
97
- for owner, count in trending_data["spaces"]:
98
- if owner not in combined_scores:
99
- combined_scores[owner] = {"spaces": 0, "models": 0, "total": 0}
100
- combined_scores[owner]["spaces"] = count
101
-
102
- # Add scores from models
103
- for owner, count in trending_data["models"]:
104
- if owner not in combined_scores:
105
- combined_scores[owner] = {"spaces": 0, "models": 0, "total": 0}
106
- combined_scores[owner]["models"] = count
107
-
108
- # Calculate total score (spaces + models)
109
- for owner in combined_scores:
110
- combined_scores[owner]["total"] = combined_scores[owner]["spaces"] + combined_scores[owner]["models"]
111
-
112
- # Sort by total score
113
- sorted_combined = sorted(combined_scores.items(), key=lambda x: x[1]["total"], reverse=True)[:limit]
114
 
115
- # Extract just the owner names for dropdown
 
116
  trending_authors = [owner for owner, _ in sorted_combined]
117
 
118
  return trending_authors, trending_data["spaces"], trending_data["models"]
@@ -274,34 +269,62 @@ with st.sidebar:
274
  st.title("👤 Contributor")
275
 
276
  # Create tabs for Spaces and Models rankings
277
- tab1, tab2 = st.tabs(["Spaces Ranking", "Models Ranking"])
278
 
279
  with tab1:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  # Show trending accounts list by Spaces
281
- st.subheader("🚀 Top 30 by Spaces")
282
 
283
- # Display the top 30 accounts list with their scores
284
  st.markdown("### Spaces Contributors Ranking")
285
 
286
  # Create a data frame for the table
287
  if top_owners_spaces:
288
- ranking_data_spaces = pd.DataFrame(top_owners_spaces[:30], columns=["Contributor", "Spaces Count"])
289
  ranking_data_spaces.index = ranking_data_spaces.index + 1 # Start index from 1 for ranking
290
 
291
- # Add a score column based on spaces count
292
- ranking_data_spaces["Score"] = ranking_data_spaces["Spaces Count"].apply(lambda x: x * 10) # Multiply by 10 for a score metric
293
-
294
  st.dataframe(
295
  ranking_data_spaces,
296
  column_config={
297
  "Contributor": st.column_config.TextColumn("Contributor"),
298
- "Spaces Count": st.column_config.NumberColumn("Spaces Count (based on top 500 spaces)", format="%d"),
299
- "Score": st.column_config.ProgressColumn(
300
- "Score (within TOP 500 SPACES)",
301
- min_value=0,
302
- max_value=ranking_data_spaces["Score"].max() * 1.1, # Add 10% to max for visual scale
303
- format="%d pts"
304
- )
305
  },
306
  use_container_width=True,
307
  hide_index=False
@@ -327,30 +350,21 @@ with st.sidebar:
327
 
328
  with tab2:
329
  # Show trending accounts list by Models
330
- st.subheader("🧠 Top 30 by Models")
331
 
332
- # Display the top 30 accounts list with their scores
333
  st.markdown("### Models Contributors Ranking")
334
 
335
  # Create a data frame for the table
336
  if top_owners_models:
337
- ranking_data_models = pd.DataFrame(top_owners_models[:30], columns=["Contributor", "Models Count"])
338
  ranking_data_models.index = ranking_data_models.index + 1 # Start index from 1 for ranking
339
 
340
- # Add a score column based on models count
341
- ranking_data_models["Score"] = ranking_data_models["Models Count"].apply(lambda x: x * 10) # Multiply by 10 for a score metric
342
-
343
  st.dataframe(
344
  ranking_data_models,
345
  column_config={
346
  "Contributor": st.column_config.TextColumn("Contributor"),
347
- "Models Count": st.column_config.NumberColumn("Models Count (based on top 500 models)", format="%d"),
348
- "Score": st.column_config.ProgressColumn(
349
- "Score (within TOP 500 MODELS)",
350
- min_value=0,
351
- max_value=ranking_data_models["Score"].max() * 1.1, # Add 10% to max for visual scale
352
- format="%d pts"
353
- )
354
  },
355
  use_container_width=True,
356
  hide_index=False
@@ -378,7 +392,7 @@ with st.sidebar:
378
  st.subheader("Select Contributor")
379
  selected_trending = st.selectbox(
380
  "Select trending account",
381
- options=trending_accounts[:30], # Limit to top 30
382
  index=0 if trending_accounts else None,
383
  key="trending_selectbox"
384
  )
@@ -411,21 +425,35 @@ st.title("🤗 Hugging Face Contributions")
411
  if username:
412
  with st.spinner(f"Fetching commit data for {username}..."):
413
  # Display contributor rank if in top 30
414
- if username in trending_accounts[:30]:
415
  rank = trending_accounts.index(username) + 1
416
  st.success(f"🏆 {username} is ranked #{rank} in the top trending contributors!")
417
 
418
  # Find user in spaces ranking
 
419
  for i, (owner, count) in enumerate(top_owners_spaces):
420
  if owner == username:
421
- st.info(f"🚀 Spaces Ranking: #{i+1} with {count} spaces")
 
422
  break
423
 
424
  # Find user in models ranking
 
425
  for i, (owner, count) in enumerate(top_owners_models):
426
  if owner == username:
427
- st.info(f"🧠 Models Ranking: #{i+1} with {count} models")
 
428
  break
 
 
 
 
 
 
 
 
 
 
429
 
430
  # Create a dictionary to store commits by type
431
  commits_by_type = {}
 
53
  timeout=30)
54
 
55
  # Process spaces data
56
+ spaces_owners = []
57
  if spaces_response.status_code == 200:
58
  spaces = spaces_response.json()
59
 
 
71
  # Get top owners by count for spaces
72
  top_owners_spaces = sorted(owner_counts_spaces.items(), key=lambda x: x[1], reverse=True)[:limit]
73
  trending_data["spaces"] = top_owners_spaces
74
+ spaces_owners = [owner for owner, _ in top_owners_spaces]
75
 
76
  # Process models data
77
+ models_owners = []
78
  if models_response.status_code == 200:
79
  models = models_response.json()
80
 
 
92
  # Get top owners by count for models
93
  top_owners_models = sorted(owner_counts_models.items(), key=lambda x: x[1], reverse=True)[:limit]
94
  trending_data["models"] = top_owners_models
95
+ models_owners = [owner for owner, _ in top_owners_models]
96
 
97
+ # Combine rankings for overall trending based on appearance in both lists
98
+ combined_score = {}
99
+ for i, owner in enumerate(spaces_owners):
100
+ if owner not in combined_score:
101
+ combined_score[owner] = 0
102
+ combined_score[owner] += (limit - i) # Higher rank gives more points
103
+
104
+ for i, owner in enumerate(models_owners):
105
+ if owner not in combined_score:
106
+ combined_score[owner] = 0
107
+ combined_score[owner] += (limit - i) # Higher rank gives more points
 
 
 
 
 
 
 
 
 
 
108
 
109
+ # Sort by combined score
110
+ sorted_combined = sorted(combined_score.items(), key=lambda x: x[1], reverse=True)[:limit]
111
  trending_authors = [owner for owner, _ in sorted_combined]
112
 
113
  return trending_authors, trending_data["spaces"], trending_data["models"]
 
269
  st.title("👤 Contributor")
270
 
271
  # Create tabs for Spaces and Models rankings
272
+ tab1, tab2, tab3 = st.tabs(["Overall Ranking", "Spaces Ranking", "Models Ranking"])
273
 
274
  with tab1:
275
+ # Show combined trending accounts list
276
+ st.subheader("🔥 Top 100 Overall Contributors")
277
+
278
+ # Display the top 100 accounts list
279
+ st.markdown("### Combined Contributors Ranking")
280
+
281
+ # Create a data frame for the table
282
+ if trending_accounts:
283
+ # Create a mapping from username to Spaces and Models rankings
284
+ spaces_rank = {owner: idx+1 for idx, (owner, _) in enumerate(top_owners_spaces)}
285
+ models_rank = {owner: idx+1 for idx, (owner, _) in enumerate(top_owners_models)}
286
+
287
+ # Create the overall ranking dataframe
288
+ overall_data = []
289
+ for idx, username in enumerate(trending_accounts[:100]):
290
+ spaces_position = spaces_rank.get(username, "-")
291
+ models_position = models_rank.get(username, "-")
292
+ overall_data.append([username, spaces_position, models_position])
293
+
294
+ ranking_data_overall = pd.DataFrame(
295
+ overall_data,
296
+ columns=["Contributor", "Spaces Rank", "Models Rank"]
297
+ )
298
+ ranking_data_overall.index = ranking_data_overall.index + 1 # Start index from 1 for ranking
299
+
300
+ st.dataframe(
301
+ ranking_data_overall,
302
+ column_config={
303
+ "Contributor": st.column_config.TextColumn("Contributor"),
304
+ "Spaces Rank": st.column_config.TextColumn("Spaces Rank (top 100)"),
305
+ "Models Rank": st.column_config.TextColumn("Models Rank (top 100)")
306
+ },
307
+ use_container_width=True,
308
+ hide_index=False
309
+ )
310
+
311
+ with tab2:
312
  # Show trending accounts list by Spaces
313
+ st.subheader("🚀 Top 100 by Spaces")
314
 
315
+ # Display the top 100 accounts list
316
  st.markdown("### Spaces Contributors Ranking")
317
 
318
  # Create a data frame for the table
319
  if top_owners_spaces:
320
+ ranking_data_spaces = pd.DataFrame(top_owners_spaces[:100], columns=["Contributor", "Spaces Count"])
321
  ranking_data_spaces.index = ranking_data_spaces.index + 1 # Start index from 1 for ranking
322
 
 
 
 
323
  st.dataframe(
324
  ranking_data_spaces,
325
  column_config={
326
  "Contributor": st.column_config.TextColumn("Contributor"),
327
+ "Spaces Count": st.column_config.NumberColumn("Spaces Count (based on top 500 spaces)", format="%d")
 
 
 
 
 
 
328
  },
329
  use_container_width=True,
330
  hide_index=False
 
350
 
351
  with tab2:
352
  # Show trending accounts list by Models
353
+ st.subheader("🧠 Top 100 by Models")
354
 
355
+ # Display the top 100 accounts list
356
  st.markdown("### Models Contributors Ranking")
357
 
358
  # Create a data frame for the table
359
  if top_owners_models:
360
+ ranking_data_models = pd.DataFrame(top_owners_models[:100], columns=["Contributor", "Models Count"])
361
  ranking_data_models.index = ranking_data_models.index + 1 # Start index from 1 for ranking
362
 
 
 
 
363
  st.dataframe(
364
  ranking_data_models,
365
  column_config={
366
  "Contributor": st.column_config.TextColumn("Contributor"),
367
+ "Models Count": st.column_config.NumberColumn("Models Count (based on top 500 models)", format="%d")
 
 
 
 
 
 
368
  },
369
  use_container_width=True,
370
  hide_index=False
 
392
  st.subheader("Select Contributor")
393
  selected_trending = st.selectbox(
394
  "Select trending account",
395
+ options=trending_accounts[:100], # Limit to top 100
396
  index=0 if trending_accounts else None,
397
  key="trending_selectbox"
398
  )
 
425
  if username:
426
  with st.spinner(f"Fetching commit data for {username}..."):
427
  # Display contributor rank if in top 30
428
+ if username in trending_accounts[:100]:
429
  rank = trending_accounts.index(username) + 1
430
  st.success(f"🏆 {username} is ranked #{rank} in the top trending contributors!")
431
 
432
  # Find user in spaces ranking
433
+ spaces_rank = None
434
  for i, (owner, count) in enumerate(top_owners_spaces):
435
  if owner == username:
436
+ spaces_rank = i+1
437
+ st.info(f"🚀 Spaces Ranking: #{spaces_rank} with {count} spaces")
438
  break
439
 
440
  # Find user in models ranking
441
+ models_rank = None
442
  for i, (owner, count) in enumerate(top_owners_models):
443
  if owner == username:
444
+ models_rank = i+1
445
+ st.info(f"🧠 Models Ranking: #{models_rank} with {count} models")
446
  break
447
+
448
+ # Display combined ranking info
449
+ combined_info = []
450
+ if spaces_rank and spaces_rank <= 100:
451
+ combined_info.append(f"Spaces: #{spaces_rank}")
452
+ if models_rank and models_rank <= 100:
453
+ combined_info.append(f"Models: #{models_rank}")
454
+
455
+ if combined_info:
456
+ st.success(f"Combined Rankings (Top 100): {', '.join(combined_info)}")
457
 
458
  # Create a dictionary to store commits by type
459
  commits_by_type = {}