Update app.py
Browse files
app.py
CHANGED
@@ -265,71 +265,124 @@ def make_calendar_heatmap(df, title, year):
|
|
265 |
st.pyplot(fig)
|
266 |
|
267 |
|
|
|
|
|
|
|
|
|
268 |
# Sidebar
|
269 |
with st.sidebar:
|
270 |
st.title("π€ Contributor")
|
271 |
|
272 |
-
#
|
273 |
-
|
274 |
-
trending_accounts, top_owners = get_trending_accounts(limit=100)
|
275 |
-
|
276 |
-
# Show trending accounts list
|
277 |
-
st.subheader("π₯ Top 30 Trending Accounts")
|
278 |
-
|
279 |
-
# Display the top 30 accounts list with their scores
|
280 |
-
st.markdown("### Trending Contributors Ranking")
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
ranking_data.index = ranking_data.index + 1 # Start index from 1 for ranking
|
286 |
|
287 |
-
#
|
288 |
-
|
289 |
-
ranking_data["Score"] = ranking_data["Spaces Count"].apply(lambda x: x * 10) # Multiply by 10 for a score metric
|
290 |
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
min_value=0,
|
299 |
-
max_value=ranking_data["Score"].max() * 1.1, # Add 10% to max for visual scale
|
300 |
-
format="%d pts"
|
301 |
-
)
|
302 |
-
},
|
303 |
-
use_container_width=True,
|
304 |
-
hide_index=False
|
305 |
-
)
|
306 |
-
|
307 |
-
# Add stats expander with visualization
|
308 |
-
with st.expander("View Top 30 Contributor Chart"):
|
309 |
-
# Create a bar chart for top 30 contributors
|
310 |
-
if top_owners:
|
311 |
-
chart_data = pd.DataFrame(top_owners[:30], columns=["Owner", "Spaces Count"])
|
312 |
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
|
316 |
-
# Add
|
317 |
-
|
318 |
-
bar.set_color(plt.cm.viridis(i/len(bars)))
|
319 |
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
|
325 |
-
# Display trending accounts
|
|
|
326 |
selected_trending = st.selectbox(
|
327 |
"Select trending account",
|
328 |
options=trending_accounts[:30], # Limit to top 30
|
329 |
index=0 if trending_accounts else None,
|
330 |
key="trending_selectbox"
|
331 |
)
|
332 |
-
|
333 |
# Custom account input option
|
334 |
st.markdown("<div style='text-align: center; margin: 10px 0;'>OR</div>", unsafe_allow_html=True)
|
335 |
custom = st.text_input("", placeholder="Enter custom username/org")
|
@@ -357,7 +410,7 @@ with st.sidebar:
|
|
357 |
st.title("π€ Hugging Face Contributions")
|
358 |
if username:
|
359 |
with st.spinner(f"Fetching commit data for {username}..."):
|
360 |
-
# Display contributor rank if in top
|
361 |
if username in trending_accounts[:30]:
|
362 |
rank = trending_accounts.index(username) + 1
|
363 |
st.success(f"π {username} is ranked #{rank} in the top trending contributors!")
|
@@ -452,7 +505,7 @@ if username:
|
|
452 |
st.metric("Total Commits", total_commits)
|
453 |
|
454 |
# Show contributor rank if in top owners
|
455 |
-
for owner, count in
|
456 |
if owner.lower() == username.lower():
|
457 |
st.metric("Spaces Count", count)
|
458 |
break
|
|
|
265 |
st.pyplot(fig)
|
266 |
|
267 |
|
268 |
+
# Fetch trending accounts with a loading spinner (do this once at the beginning)
|
269 |
+
with st.spinner("Loading trending accounts..."):
|
270 |
+
trending_accounts, top_owners_spaces, top_owners_models = get_trending_accounts(limit=100)
|
271 |
+
|
272 |
# Sidebar
|
273 |
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
|
308 |
+
)
|
309 |
+
|
310 |
+
# Add stats expander with visualization
|
311 |
+
with st.expander("View Top 30 Spaces Contributors Chart"):
|
312 |
+
# Create a bar chart for top 30 contributors
|
313 |
+
if top_owners_spaces:
|
314 |
+
chart_data = pd.DataFrame(top_owners_spaces[:30], columns=["Owner", "Spaces Count"])
|
315 |
+
|
316 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
317 |
+
bars = ax.barh(chart_data["Owner"], chart_data["Spaces Count"])
|
318 |
+
|
319 |
+
# Add color gradient to bars
|
320 |
+
for i, bar in enumerate(bars):
|
321 |
+
bar.set_color(plt.cm.viridis(i/len(bars)))
|
322 |
+
|
323 |
+
ax.set_title("Top 30 Contributors by Number of Spaces")
|
324 |
+
ax.set_xlabel("Number of Spaces")
|
325 |
+
plt.tight_layout()
|
326 |
+
st.pyplot(fig)
|
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
|
357 |
+
)
|
358 |
+
|
359 |
+
# Add stats expander with visualization
|
360 |
+
with st.expander("View Top 30 Models Contributors Chart"):
|
361 |
+
# Create a bar chart for top 30 contributors
|
362 |
+
if top_owners_models:
|
363 |
+
chart_data = pd.DataFrame(top_owners_models[:30], columns=["Owner", "Models Count"])
|
364 |
+
|
365 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
366 |
+
bars = ax.barh(chart_data["Owner"], chart_data["Models Count"])
|
367 |
+
|
368 |
+
# Add color gradient to bars
|
369 |
+
for i, bar in enumerate(bars):
|
370 |
+
bar.set_color(plt.cm.plasma(i/len(bars))) # Use a different colormap for models
|
371 |
+
|
372 |
+
ax.set_title("Top 30 Contributors by Number of Models")
|
373 |
+
ax.set_xlabel("Number of Models")
|
374 |
+
plt.tight_layout()
|
375 |
+
st.pyplot(fig)
|
376 |
|
377 |
+
# Display trending accounts selection dropdown
|
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 |
)
|
385 |
+
|
386 |
# Custom account input option
|
387 |
st.markdown("<div style='text-align: center; margin: 10px 0;'>OR</div>", unsafe_allow_html=True)
|
388 |
custom = st.text_input("", placeholder="Enter custom username/org")
|
|
|
410 |
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!")
|
|
|
505 |
st.metric("Total Commits", total_commits)
|
506 |
|
507 |
# Show contributor rank if in top owners
|
508 |
+
for owner, count in top_owners_spaces:
|
509 |
if owner.lower() == username.lower():
|
510 |
st.metric("Spaces Count", count)
|
511 |
break
|