Spaces:
Sleeping
Sleeping
Commit
·
5fe7079
1
Parent(s):
8b6987d
added more sources
Browse files
app.py
CHANGED
|
@@ -4,16 +4,36 @@ import pandas as pd
|
|
| 4 |
|
| 5 |
st.set_page_config(layout="wide")
|
| 6 |
|
| 7 |
-
st.
|
| 8 |
|
| 9 |
-
|
| 10 |
-
"
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Define the metrics
|
| 19 |
metrics = ["totalUniqueImpressions", "totalReactions", "numComments", "Num of posts"]
|
|
@@ -48,8 +68,6 @@ mask = df["publishedAt"].between(*date_range)
|
|
| 48 |
df = df[mask]
|
| 49 |
|
| 50 |
|
| 51 |
-
df["Name"] = df.author.apply(lambda x: x["fullname"])
|
| 52 |
-
df["username"] = df.author.apply(lambda x: x["name"])
|
| 53 |
df["totalReactions"] = df.reactions.apply(lambda x: sum([_["count"] for _ in x]))
|
| 54 |
df["Num of posts"] = 1
|
| 55 |
|
|
@@ -68,6 +86,7 @@ data.index.name = "Rank"
|
|
| 68 |
# Format metrics columns with commas
|
| 69 |
data[metrics] = data[metrics].applymap(lambda x: f"{x:,}")
|
| 70 |
|
|
|
|
| 71 |
def make_clickable(val):
|
| 72 |
return f'<a target="_blank" href="https://huggingface.co/{val}">{val}</a>'
|
| 73 |
|
|
@@ -77,6 +96,3 @@ st.write(
|
|
| 77 |
f"""<center>{df_styled.to_html(escape=False, index=False)}""",
|
| 78 |
unsafe_allow_html=True,
|
| 79 |
)
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
# st.dataframe(data=df_styled, width=100_000)
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(layout="wide")
|
| 6 |
|
| 7 |
+
col1, col2 = st.columns([2, 3]) # Adjust the width ratio as needed
|
| 8 |
|
| 9 |
+
sources = [
|
| 10 |
+
"https://huggingface.co/datasets/cfahlgren1/hub-stats",
|
| 11 |
+
"https://huggingface.co/datasets/maxiw/hf-posts",
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
with col1:
|
| 15 |
+
st.header("HuggingFace 🤗 Posts leaderboard")
|
| 16 |
|
| 17 |
+
with col2:
|
| 18 |
+
selected_source = st.selectbox(
|
| 19 |
+
"Data Source:",
|
| 20 |
+
options=sources,
|
| 21 |
+
index=0,
|
| 22 |
+
)
|
| 23 |
|
| 24 |
+
if selected_source == sources[0]:
|
| 25 |
+
df = pd.read_parquet("hf://datasets/cfahlgren1/hub-stats/posts.parquet")
|
| 26 |
+
df["Name"] = df.fullname
|
| 27 |
+
df["username"] = df.name
|
| 28 |
+
|
| 29 |
+
if selected_source == sources[1]:
|
| 30 |
+
df = pd.read_json("hf://datasets/maxiw/hf-posts/posts.jsonl", lines=True)
|
| 31 |
+
|
| 32 |
+
df["publishedAt"] = pd.to_datetime(df.publishedAt)
|
| 33 |
+
print(">>> ", df.columns)
|
| 34 |
+
|
| 35 |
+
df["Name"] = df.author.apply(lambda x: x["fullname"])
|
| 36 |
+
df["username"] = df.author.apply(lambda x: x["name"])
|
| 37 |
|
| 38 |
# Define the metrics
|
| 39 |
metrics = ["totalUniqueImpressions", "totalReactions", "numComments", "Num of posts"]
|
|
|
|
| 68 |
df = df[mask]
|
| 69 |
|
| 70 |
|
|
|
|
|
|
|
| 71 |
df["totalReactions"] = df.reactions.apply(lambda x: sum([_["count"] for _ in x]))
|
| 72 |
df["Num of posts"] = 1
|
| 73 |
|
|
|
|
| 86 |
# Format metrics columns with commas
|
| 87 |
data[metrics] = data[metrics].applymap(lambda x: f"{x:,}")
|
| 88 |
|
| 89 |
+
|
| 90 |
def make_clickable(val):
|
| 91 |
return f'<a target="_blank" href="https://huggingface.co/{val}">{val}</a>'
|
| 92 |
|
|
|
|
| 96 |
f"""<center>{df_styled.to_html(escape=False, index=False)}""",
|
| 97 |
unsafe_allow_html=True,
|
| 98 |
)
|
|
|
|
|
|
|
|
|