Spaces:
Build error
Build error
Commit
·
0acccaf
1
Parent(s):
60896b3
up
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
-
#import streamlit as st
|
| 2 |
-
|
| 3 |
from huggingface_hub import HfApi
|
| 4 |
-
import pandas
|
| 5 |
import os
|
| 6 |
import streamlit as st
|
|
|
|
|
|
|
| 7 |
import datetime
|
| 8 |
from transformers.models.auto.configuration_auto import CONFIG_MAPPING_NAMES
|
| 9 |
|
|
@@ -22,7 +22,7 @@ def retrieve_model_stats():
|
|
| 22 |
all_stats = {}
|
| 23 |
total_downloads = 0
|
| 24 |
|
| 25 |
-
for model_name in list(CONFIG_MAPPING_NAMES.keys())
|
| 26 |
model_stats = {"num_downloads": 0, "%_of_all_downloads": 0, "num_models": 0, "download_per_model": 0}
|
| 27 |
models = hf_api.list_models(filter=model_name)
|
| 28 |
|
|
@@ -35,15 +35,17 @@ def retrieve_model_stats():
|
|
| 35 |
# save in overall dict
|
| 36 |
all_stats[model_name] = model_stats
|
| 37 |
|
| 38 |
-
for model_name in list(CONFIG_MAPPING_NAMES.keys())
|
| 39 |
all_stats[model_name]["%_of_all_downloads"] = round(all_stats[model_name]["num_downloads"] / total_downloads, 5) * 100 # noqa: E501
|
| 40 |
downloads = all_stats[model_name]["num_downloads"]
|
| 41 |
all_stats[model_name]["num_downloads"] = f"{downloads:,}"
|
| 42 |
|
| 43 |
sorted_results = dict(reversed(sorted(all_stats.items(), key=lambda d: d[1]["%_of_all_downloads"])))
|
| 44 |
-
dataframe =
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
repo = Repository(local_dir="data", clone_from=DATASET_REPO_URL)
|
|
@@ -60,10 +62,34 @@ if not os.path.isfile(DATA_FILE):
|
|
| 60 |
print(commit_url)
|
| 61 |
|
| 62 |
with open(DATA_FILE, "r") as f:
|
| 63 |
-
dataframe =
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
st.table(dataframe)
|
|
|
|
|
|
|
|
|
|
| 1 |
from huggingface_hub import HfApi
|
| 2 |
+
import pandas as pd
|
| 3 |
import os
|
| 4 |
import streamlit as st
|
| 5 |
+
import altair as alt
|
| 6 |
+
import numpy as np
|
| 7 |
import datetime
|
| 8 |
from transformers.models.auto.configuration_auto import CONFIG_MAPPING_NAMES
|
| 9 |
|
|
|
|
| 22 |
all_stats = {}
|
| 23 |
total_downloads = 0
|
| 24 |
|
| 25 |
+
for model_name in list(CONFIG_MAPPING_NAMES.keys()):
|
| 26 |
model_stats = {"num_downloads": 0, "%_of_all_downloads": 0, "num_models": 0, "download_per_model": 0}
|
| 27 |
models = hf_api.list_models(filter=model_name)
|
| 28 |
|
|
|
|
| 35 |
# save in overall dict
|
| 36 |
all_stats[model_name] = model_stats
|
| 37 |
|
| 38 |
+
for model_name in list(CONFIG_MAPPING_NAMES.keys()):
|
| 39 |
all_stats[model_name]["%_of_all_downloads"] = round(all_stats[model_name]["num_downloads"] / total_downloads, 5) * 100 # noqa: E501
|
| 40 |
downloads = all_stats[model_name]["num_downloads"]
|
| 41 |
all_stats[model_name]["num_downloads"] = f"{downloads:,}"
|
| 42 |
|
| 43 |
sorted_results = dict(reversed(sorted(all_stats.items(), key=lambda d: d[1]["%_of_all_downloads"])))
|
| 44 |
+
dataframe = pd.DataFrame.from_dict(sorted_results, orient="index")
|
| 45 |
|
| 46 |
+
# give header to model names
|
| 47 |
+
result = "model_names" + dataframe.to_csv()
|
| 48 |
+
return result
|
| 49 |
|
| 50 |
|
| 51 |
repo = Repository(local_dir="data", clone_from=DATASET_REPO_URL)
|
|
|
|
| 62 |
print(commit_url)
|
| 63 |
|
| 64 |
with open(DATA_FILE, "r") as f:
|
| 65 |
+
dataframe = pd.read_csv(DATA_FILE)
|
| 66 |
+
|
| 67 |
+
int_downloads = np.array([int(x.replace(",", "")) for x in dataframe["num_downloads"].values])
|
| 68 |
+
|
| 69 |
+
# print top 20 downloads
|
| 70 |
+
source = pd.DataFrame({
|
| 71 |
+
'Number of total downloads': int_downloads[:20],
|
| 72 |
+
'Model architecture name': dataframe["model_names"].values[:20],
|
| 73 |
+
})
|
| 74 |
+
bar_chart = alt.Chart(source).mark_bar().encode(
|
| 75 |
+
y="Number of total downloads",
|
| 76 |
+
x=alt.X("Model architecture name", sort=None),
|
| 77 |
+
)
|
| 78 |
+
st.title(f'Top 20 downloads for year {year} and week {week}')
|
| 79 |
+
st.altair_chart(bar_chart, use_container_width=True)
|
| 80 |
+
|
| 81 |
+
# print bottom 20 downloads
|
| 82 |
+
source = pd.DataFrame({
|
| 83 |
+
'Number of total downloads': int_downloads[-20:],
|
| 84 |
+
'Model architecture name': dataframe["model_names"].values[-20:],
|
| 85 |
+
})
|
| 86 |
+
bar_chart = alt.Chart(source).mark_bar().encode(
|
| 87 |
+
y="Number of total downloads",
|
| 88 |
+
x=alt.X("Model architecture name", sort=None),
|
| 89 |
+
)
|
| 90 |
+
st.title(f'Bottom 20 downloads for year {year} and week {week}')
|
| 91 |
+
st.altair_chart(bar_chart, use_container_width=True)
|
| 92 |
+
|
| 93 |
+
# print all stats
|
| 94 |
+
st.title(f'All downloads for year {year} and week {week}')
|
| 95 |
st.table(dataframe)
|
data
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
Subproject commit bd0b98ff44210308e4a142bd71bd805fbd330f34
|
|
|
|
|
|