patrickvonplaten
commited on
Commit
•
4cb150c
1
Parent(s):
568085d
up
Browse files
app.py
CHANGED
@@ -1,10 +1,38 @@
|
|
1 |
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
import numpy as np
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
)
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
+
from huggingface_hub import HfApi
|
4 |
+
import pandas
|
5 |
+
from transformers.models.auto.configuration_auto import CONFIG_MAPPING_NAMES
|
|
|
6 |
|
7 |
+
hf_api = HfApi()
|
8 |
+
all_stats = {}
|
9 |
+
total_downloads = 0
|
10 |
+
|
11 |
+
for model_name in list(CONFIG_MAPPING_NAMES.keys())[:2]:
|
12 |
+
model_stats = {"num_downloads": 0, "%_of_all_downloads": 0, "num_models": 0, "download_per_model": 0}
|
13 |
+
models = hf_api.list_models(filter=model_name)
|
14 |
+
|
15 |
+
model_stats["num_models"] = len(models)
|
16 |
+
model_stats["num_downloads"] = sum([m.downloads for m in models if hasattr(m, "downloads")])
|
17 |
+
if len(models) > 0:
|
18 |
+
model_stats["download_per_model"] = round(model_stats["num_downloads"] / len(models), 2)
|
19 |
+
total_downloads += model_stats["num_downloads"]
|
20 |
+
|
21 |
+
# save in overall dict
|
22 |
+
all_stats[model_name] = model_stats
|
23 |
+
|
24 |
+
|
25 |
+
for model_name in list(CONFIG_MAPPING_NAMES.keys()):
|
26 |
+
all_stats[model_name]["%_of_all_downloads"] = round(all_stats[model_name]["num_downloads"] / total_downloads, 5) * 100 # noqa: E501
|
27 |
+
downloads = all_stats[model_name]["num_downloads"]
|
28 |
+
all_stats[model_name]["num_downloads"] = f"{downloads:,}"
|
29 |
+
|
30 |
+
|
31 |
+
sorted_results = dict(reversed(sorted(all_stats.items(), key=lambda d: d[1]["%_of_all_downloads"])))
|
32 |
+
dataframe = pandas.DataFrame.from_dict(sorted_results, orient="index")
|
33 |
+
result = dataframe.to_string()
|
34 |
+
|
35 |
+
with open("result.txt", "w") as f:
|
36 |
+
f.write(result)
|
37 |
+
|
38 |
+
st.table(dataframe)
|