Update app.py
Browse files
app.py
CHANGED
@@ -50,18 +50,13 @@ def cached_list_items(username, kind):
|
|
50 |
@lru_cache(maxsize=1)
|
51 |
def get_trending_accounts(limit=100):
|
52 |
try:
|
53 |
-
trending_data = {"spaces": []
|
54 |
|
55 |
# Get spaces for stats calculation
|
56 |
spaces_response = requests.get("https://huggingface.co/api/spaces",
|
57 |
params={"limit": 10000},
|
58 |
timeout=30)
|
59 |
|
60 |
-
# Get models for stats calculation
|
61 |
-
models_response = requests.get("https://huggingface.co/api/models",
|
62 |
-
params={"limit": 10000},
|
63 |
-
timeout=30)
|
64 |
-
|
65 |
# Process spaces data
|
66 |
spaces_owners = []
|
67 |
if spaces_response.status_code == 200:
|
@@ -83,48 +78,14 @@ def get_trending_accounts(limit=100):
|
|
83 |
trending_data["spaces"] = top_owners_spaces
|
84 |
spaces_owners = [owner for owner, _ in top_owners_spaces]
|
85 |
|
86 |
-
#
|
87 |
-
|
88 |
-
if models_response.status_code == 200:
|
89 |
-
models = models_response.json()
|
90 |
-
|
91 |
-
# Count models by owner
|
92 |
-
owner_counts_models = {}
|
93 |
-
for model in models:
|
94 |
-
if '/' in model.get('id', ''):
|
95 |
-
owner, _ = model.get('id', '').split('/', 1)
|
96 |
-
else:
|
97 |
-
owner = model.get('owner', '')
|
98 |
-
|
99 |
-
if owner != 'None':
|
100 |
-
owner_counts_models[owner] = owner_counts_models.get(owner, 0) + 1
|
101 |
-
|
102 |
-
# Get top owners by count for models
|
103 |
-
top_owners_models = sorted(owner_counts_models.items(), key=lambda x: x[1], reverse=True)[:limit]
|
104 |
-
trending_data["models"] = top_owners_models
|
105 |
-
models_owners = [owner for owner, _ in top_owners_models]
|
106 |
-
|
107 |
-
# Combine rankings for overall trending based on appearance in both lists
|
108 |
-
combined_score = {}
|
109 |
-
for i, owner in enumerate(spaces_owners):
|
110 |
-
if owner not in combined_score:
|
111 |
-
combined_score[owner] = 0
|
112 |
-
combined_score[owner] += (limit - i) # Higher rank gives more points
|
113 |
-
|
114 |
-
for i, owner in enumerate(models_owners):
|
115 |
-
if owner not in combined_score:
|
116 |
-
combined_score[owner] = 0
|
117 |
-
combined_score[owner] += (limit - i) # Higher rank gives more points
|
118 |
-
|
119 |
-
# Sort by combined score
|
120 |
-
sorted_combined = sorted(combined_score.items(), key=lambda x: x[1], reverse=True)[:limit]
|
121 |
-
trending_authors = [owner for owner, _ in sorted_combined]
|
122 |
|
123 |
-
return trending_authors, trending_data["spaces"],
|
124 |
except Exception as e:
|
125 |
st.error(f"Error fetching trending accounts: {str(e)}")
|
126 |
fallback_authors = ["ritvik77", "facebook", "google", "stabilityai", "Salesforce", "tiiuae", "bigscience"]
|
127 |
-
return fallback_authors, [(author, 0) for author in fallback_authors], [
|
128 |
|
129 |
|
130 |
# Rate limiting
|
@@ -278,12 +239,10 @@ with st.spinner("Loading trending accounts..."):
|
|
278 |
with st.sidebar:
|
279 |
st.title("👤 Contributor")
|
280 |
|
281 |
-
# Create tabs for Spaces
|
282 |
-
tab1, tab2
|
283 |
"SPACES TOP 30",
|
284 |
-
"SPACES TOP 100"
|
285 |
-
"MODELS TOP 30",
|
286 |
-
"MODELS TOP 100"
|
287 |
])
|
288 |
|
289 |
with tab1:
|
@@ -451,24 +410,6 @@ if username:
|
|
451 |
spaces_rank = i+1
|
452 |
st.info(f"🚀 Spaces Ranking: #{spaces_rank} with {count} spaces")
|
453 |
break
|
454 |
-
|
455 |
-
# Find user in models ranking
|
456 |
-
models_rank = None
|
457 |
-
for i, (owner, count) in enumerate(top_owners_models):
|
458 |
-
if owner == username:
|
459 |
-
models_rank = i+1
|
460 |
-
st.info(f"🧠 Models Ranking: #{models_rank} with {count} models")
|
461 |
-
break
|
462 |
-
|
463 |
-
# Display combined ranking info
|
464 |
-
combined_info = []
|
465 |
-
if spaces_rank and spaces_rank <= 100:
|
466 |
-
combined_info.append(f"Spaces: #{spaces_rank}")
|
467 |
-
if models_rank and models_rank <= 100:
|
468 |
-
combined_info.append(f"Models: #{models_rank}")
|
469 |
-
|
470 |
-
if combined_info:
|
471 |
-
st.success(f"Combined Rankings (Top 100): {', '.join(combined_info)}")
|
472 |
|
473 |
# Create a dictionary to store commits by type
|
474 |
commits_by_type = {}
|
|
|
50 |
@lru_cache(maxsize=1)
|
51 |
def get_trending_accounts(limit=100):
|
52 |
try:
|
53 |
+
trending_data = {"spaces": []}
|
54 |
|
55 |
# Get spaces for stats calculation
|
56 |
spaces_response = requests.get("https://huggingface.co/api/spaces",
|
57 |
params={"limit": 10000},
|
58 |
timeout=30)
|
59 |
|
|
|
|
|
|
|
|
|
|
|
60 |
# Process spaces data
|
61 |
spaces_owners = []
|
62 |
if spaces_response.status_code == 200:
|
|
|
78 |
trending_data["spaces"] = top_owners_spaces
|
79 |
spaces_owners = [owner for owner, _ in top_owners_spaces]
|
80 |
|
81 |
+
# Use the spaces ranking as the overall trending
|
82 |
+
trending_authors = spaces_owners
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
+
return trending_authors, trending_data["spaces"], [] # Empty list for models as we don't need it
|
85 |
except Exception as e:
|
86 |
st.error(f"Error fetching trending accounts: {str(e)}")
|
87 |
fallback_authors = ["ritvik77", "facebook", "google", "stabilityai", "Salesforce", "tiiuae", "bigscience"]
|
88 |
+
return fallback_authors, [(author, 0) for author in fallback_authors], []
|
89 |
|
90 |
|
91 |
# Rate limiting
|
|
|
239 |
with st.sidebar:
|
240 |
st.title("👤 Contributor")
|
241 |
|
242 |
+
# Create tabs for Spaces rankings only
|
243 |
+
tab1, tab2 = st.tabs([
|
244 |
"SPACES TOP 30",
|
245 |
+
"SPACES TOP 100"
|
|
|
|
|
246 |
])
|
247 |
|
248 |
with tab1:
|
|
|
410 |
spaces_rank = i+1
|
411 |
st.info(f"🚀 Spaces Ranking: #{spaces_rank} with {count} spaces")
|
412 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
413 |
|
414 |
# Create a dictionary to store commits by type
|
415 |
commits_by_type = {}
|