Ritvik
commited on
Commit
Β·
d129378
1
Parent(s):
111ee24
Updated app
Browse files- .idea/.gitignore +8 -0
- .idea/ContributionChartHuggingFace.iml +10 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +149 -0
- requirements.txt +5 -0
.idea/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
| 4 |
+
# Editor-based HTTP Client requests
|
| 5 |
+
/httpRequests/
|
| 6 |
+
# Datasource local storage ignored files
|
| 7 |
+
/dataSources/
|
| 8 |
+
/dataSources.local.xml
|
.idea/ContributionChartHuggingFace.iml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$">
|
| 5 |
+
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
| 6 |
+
</content>
|
| 7 |
+
<orderEntry type="jdk" jdkName="Python 3.12 (ContributionChartHuggingFace)" jdkType="Python SDK" />
|
| 8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 9 |
+
</component>
|
| 10 |
+
</module>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Black">
|
| 4 |
+
<option name="sdkName" value="Python 3.12 (ContributionChartHuggingFace)" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (ContributionChartHuggingFace)" project-jdk-type="Python SDK" />
|
| 7 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/ContributionChartHuggingFace.iml" filepath="$PROJECT_DIR$/.idea/ContributionChartHuggingFace.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
app.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import seaborn as sns
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 8 |
+
|
| 9 |
+
st.set_page_config(page_title="HF Contributions", layout="wide")
|
| 10 |
+
api = HfApi()
|
| 11 |
+
|
| 12 |
+
# Function to fetch commits for a repository (optimized)
|
| 13 |
+
def fetch_commits_for_repo(repo_id, repo_type, username, selected_year):
|
| 14 |
+
try:
|
| 15 |
+
# Skip private/gated repos upfront
|
| 16 |
+
repo_info = api.repo_info(repo_id=repo_id, repo_type=repo_type)
|
| 17 |
+
if repo_info.private or (hasattr(repo_info, 'gated') and repo_info.gated):
|
| 18 |
+
return []
|
| 19 |
+
|
| 20 |
+
commits = api.list_repo_commits(repo_id=repo_id, repo_type=repo_type)
|
| 21 |
+
commit_dates = [
|
| 22 |
+
pd.to_datetime(commit.created_at).tz_localize(None).date()
|
| 23 |
+
for commit in commits
|
| 24 |
+
if any(
|
| 25 |
+
(isinstance(author, str) and author.lower() == username.lower()) or
|
| 26 |
+
(isinstance(author, dict) and "user" in author and author["user"].lower() == username.lower())
|
| 27 |
+
for author in commit.authors
|
| 28 |
+
) and pd.to_datetime(commit.created_at).year == selected_year
|
| 29 |
+
]
|
| 30 |
+
return commit_dates
|
| 31 |
+
except Exception:
|
| 32 |
+
return [] # Silently skip inaccessible or errored repos
|
| 33 |
+
|
| 34 |
+
# Function to get commit events for a user
|
| 35 |
+
def get_commit_events(username, kind=None, selected_year=None):
|
| 36 |
+
commit_dates = []
|
| 37 |
+
items_with_type = []
|
| 38 |
+
kinds = [kind] if kind else ["model", "dataset", "space"]
|
| 39 |
+
|
| 40 |
+
for k in kinds:
|
| 41 |
+
try:
|
| 42 |
+
if k == "model":
|
| 43 |
+
items = list(api.list_models(author=username))
|
| 44 |
+
elif k == "dataset":
|
| 45 |
+
items = list(api.list_datasets(author=username))
|
| 46 |
+
elif k == "space":
|
| 47 |
+
items = list(api.list_spaces(author=username))
|
| 48 |
+
else:
|
| 49 |
+
items = []
|
| 50 |
+
|
| 51 |
+
items_with_type.extend((item, k) for item in items)
|
| 52 |
+
repo_ids = [item.id for item in items]
|
| 53 |
+
|
| 54 |
+
# Parallel fetch commits
|
| 55 |
+
with ThreadPoolExecutor(max_workers=10) as executor:
|
| 56 |
+
future_to_repo = {
|
| 57 |
+
executor.submit(fetch_commits_for_repo, repo_id, k, username, selected_year): repo_id
|
| 58 |
+
for repo_id in repo_ids
|
| 59 |
+
}
|
| 60 |
+
for future in as_completed(future_to_repo):
|
| 61 |
+
commit_dates.extend(future.result())
|
| 62 |
+
except Exception as e:
|
| 63 |
+
st.warning(f"Error fetching {k}s for {username}: {str(e)}")
|
| 64 |
+
|
| 65 |
+
return pd.DataFrame(commit_dates, columns=["date"]), items_with_type
|
| 66 |
+
|
| 67 |
+
# Calendar heatmap function
|
| 68 |
+
def make_calendar_heatmap(df, title, year, color_palette="Greens"):
|
| 69 |
+
if df.empty:
|
| 70 |
+
st.info(f"No {title.lower()} found for {year}.")
|
| 71 |
+
return
|
| 72 |
+
df["count"] = 1
|
| 73 |
+
df = df.groupby("date").sum().reset_index()
|
| 74 |
+
df["date"] = pd.to_datetime(df["date"])
|
| 75 |
+
start = pd.Timestamp(f"{year}-01-01")
|
| 76 |
+
end = pd.Timestamp(f"{year}-12-31")
|
| 77 |
+
all_days = pd.date_range(start=start, end=end)
|
| 78 |
+
heatmap_data = pd.DataFrame(index=all_days).assign(count=0)
|
| 79 |
+
heatmap_data.loc[df.set_index("date").index, "count"] = df.set_index("date")["count"]
|
| 80 |
+
heatmap_data["dow"] = heatmap_data.index.dayofweek
|
| 81 |
+
heatmap_data["week"] = ((heatmap_data.index - start).days // 7)
|
| 82 |
+
heatmap_data = heatmap_data.reset_index().rename(columns={"index": "date"})
|
| 83 |
+
pivot = heatmap_data.pivot(index="dow", columns="week", values="count").fillna(0)
|
| 84 |
+
month_labels = [d.strftime("%b") for d in pd.date_range(start, end, freq="MS")]
|
| 85 |
+
month_positions = [((pd.Timestamp(f"{year}-{i + 1}-01") - start).days // 7) for i in range(12)]
|
| 86 |
+
fig, ax = plt.subplots(figsize=(12, 1.2))
|
| 87 |
+
sns.heatmap(pivot, ax=ax, cmap=color_palette, linewidths=0.5, linecolor="white", square=True, cbar=False,
|
| 88 |
+
yticklabels=["M", "T", "W", "T", "F", "S", "S"])
|
| 89 |
+
ax.set_title(f"{title} ({year})", fontsize=12, pad=10)
|
| 90 |
+
ax.set_xlabel("")
|
| 91 |
+
ax.set_ylabel("")
|
| 92 |
+
ax.set_xticks(month_positions)
|
| 93 |
+
ax.set_xticklabels(month_labels, fontsize=8)
|
| 94 |
+
ax.set_yticklabels(ax.get_yticklabels(), rotation=0, fontsize=8)
|
| 95 |
+
st.pyplot(fig)
|
| 96 |
+
|
| 97 |
+
# Sidebar
|
| 98 |
+
with st.sidebar:
|
| 99 |
+
st.title("π€ Contributor")
|
| 100 |
+
username = st.selectbox(
|
| 101 |
+
"Select or type a username",
|
| 102 |
+
options=["ritvik77", "facebook", "google", "stabilityai", "Salesforce", "tiiuae", "bigscience"],
|
| 103 |
+
index=0
|
| 104 |
+
)
|
| 105 |
+
st.markdown("<div style='text-align: center; margin: 10px 0;'>OR</div>", unsafe_allow_html=True)
|
| 106 |
+
custom = st.text_input("", placeholder="Enter custom username/org")
|
| 107 |
+
if custom.strip():
|
| 108 |
+
username = custom.strip()
|
| 109 |
+
year_options = list(range(datetime.now().year, 2017, -1))
|
| 110 |
+
selected_year = st.selectbox("ποΈ Year", options=year_options)
|
| 111 |
+
|
| 112 |
+
# Main Content
|
| 113 |
+
st.title("π€ Hugging Face Contributions")
|
| 114 |
+
if username:
|
| 115 |
+
with st.spinner("Fetching commit data..."):
|
| 116 |
+
all_df, all_items = get_commit_events(username, selected_year=selected_year)
|
| 117 |
+
st.subheader(f"{username}'s Activity in {selected_year}")
|
| 118 |
+
st.metric("Total Commits", len(all_df))
|
| 119 |
+
make_calendar_heatmap(all_df, "All Commits", selected_year)
|
| 120 |
+
|
| 121 |
+
# Updated Color Scheme Legend with five shades
|
| 122 |
+
st.markdown("""
|
| 123 |
+
<div style='text-align: center; margin-top: -10px; margin-bottom: 20px;'>
|
| 124 |
+
<span style='font-size: 12px; margin-right: 10px;'>Less</span>
|
| 125 |
+
<span style='display: inline-block; width: 15px; height: 15px; background-color: #f0f7f0; border: 1px solid #ccc;'></span>
|
| 126 |
+
<span style='display: inline-block; width: 15px; height: 15px; background-color: #c6e0c6; border: 1px solid #ccc;'></span>
|
| 127 |
+
<span style='display: inline-block; width: 15px; height: 15px; background-color: #77b577; border: 1px solid #ccc;'></span>
|
| 128 |
+
<span style='display: inline-block; width: 15px; height: 15px; background-color: #2e6b2e; border: 1px solid #ccc;'></span>
|
| 129 |
+
<span style='display: inline-block; width: 15px; height: 15px; background-color: #1a3c1a; border: 1px solid #ccc;'></span>
|
| 130 |
+
<span style='font-size: 12px; margin-left: 10px;'>More</span>
|
| 131 |
+
</div>
|
| 132 |
+
""", unsafe_allow_html=True)
|
| 133 |
+
|
| 134 |
+
# Metrics and heatmaps for each type
|
| 135 |
+
col1, col2, col3 = st.columns(3)
|
| 136 |
+
for col, kind, emoji, label in [
|
| 137 |
+
(col1, "model", "π§ ", "Models"),
|
| 138 |
+
(col2, "dataset", "π¦", "Datasets"),
|
| 139 |
+
(col3, "space", "π", "Spaces")
|
| 140 |
+
]:
|
| 141 |
+
with col:
|
| 142 |
+
df_kind, _ = get_commit_events(username, kind=kind, selected_year=selected_year)
|
| 143 |
+
try:
|
| 144 |
+
total = len(list(getattr(api, f"list_{kind}s")(author=username)))
|
| 145 |
+
except Exception:
|
| 146 |
+
total = 0
|
| 147 |
+
st.metric(f"{emoji} {label}", total)
|
| 148 |
+
st.metric(f"Commits in {selected_year}", len(df_kind))
|
| 149 |
+
make_calendar_heatmap(df_kind, f"{label} Commits", selected_year)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.36.0
|
| 2 |
+
huggingface_hub==0.23.4
|
| 3 |
+
pandas==2.2.2
|
| 4 |
+
matplotlib==3.9.0
|
| 5 |
+
seaborn==0.13.2
|