singhsidhukuldeep
commited on
Commit
•
442b62f
1
Parent(s):
ebd6079
Add application file
Browse files
app.py
CHANGED
@@ -1,4 +1,66 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
st.set_page_config(layout="wide")
|
6 |
+
|
7 |
+
st.header("HuggingFace 🤗 Posts leaderboard")
|
8 |
+
|
9 |
+
st.write(
|
10 |
+
"""Data Source: https://huggingface.co/datasets/maxiw/hf-posts \t Created by: https://huggingface.co/singhsidhukuldeep"""
|
11 |
+
)
|
12 |
+
|
13 |
+
df = pd.read_json("hf://datasets/maxiw/hf-posts/posts.jsonl", lines=True)
|
14 |
+
|
15 |
+
df["publishedAt"] = pd.to_datetime(df.publishedAt)
|
16 |
+
print(df.columns)
|
17 |
+
|
18 |
+
# Get min and max dates from the DataFrame
|
19 |
+
min_date = df["publishedAt"].min().to_pydatetime()
|
20 |
+
max_date = df["publishedAt"].max().to_pydatetime()
|
21 |
+
|
22 |
+
# Create the double-ended slider
|
23 |
+
date_range = st.slider(
|
24 |
+
"Select Date Range",
|
25 |
+
min_value=min_date,
|
26 |
+
max_value=max_date,
|
27 |
+
value=(min_date, max_date),
|
28 |
+
format="DD/MMM/YYYY",
|
29 |
+
)
|
30 |
+
metrics = ["totalUniqueImpressions", "totalReactions", "numComments", "Num of posts"]
|
31 |
+
selected_metric = st.selectbox(
|
32 |
+
"Sort by:",
|
33 |
+
options=metrics,
|
34 |
+
index=0,
|
35 |
+
)
|
36 |
+
# Filter the DataFrame based on selected date range
|
37 |
+
mask = df["publishedAt"].between(*date_range)
|
38 |
+
df = df[mask]
|
39 |
+
|
40 |
+
|
41 |
+
df["Name"] = df.author.apply(lambda x: x["fullname"])
|
42 |
+
df["username"] = df.author.apply(lambda x: x["name"])
|
43 |
+
df["totalReactions"] = df.reactions.apply(lambda x: sum([_["count"] for _ in x]))
|
44 |
+
df["Num of posts"] = 1
|
45 |
+
data = (
|
46 |
+
df.groupby(["username", "Name"])[metrics]
|
47 |
+
.sum()
|
48 |
+
.sort_values(selected_metric, ascending=False)
|
49 |
+
.reset_index()
|
50 |
+
)
|
51 |
+
data.index = np.arange(1, len(data) + 1)
|
52 |
+
data.index.name = "Rank"
|
53 |
+
|
54 |
+
|
55 |
+
def make_clickable(val):
|
56 |
+
return f'<a target="_blank" href="https://huggingface.co/{val}">{val}</a>'
|
57 |
+
|
58 |
+
|
59 |
+
df_styled = data.style.format({"username": make_clickable})
|
60 |
+
st.write(
|
61 |
+
f"""<center>{df_styled.to_html(escape=False, index=False)}""",
|
62 |
+
unsafe_allow_html=True,
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
# st.dataframe(data=df_styled, width=100_000)
|