Spaces:
Sleeping
Sleeping
Big improvements to simplify code
Browse files
app.py
CHANGED
@@ -10,62 +10,74 @@ import pandas as pd
|
|
10 |
def main():
|
11 |
st.title("Hugging Face Papers KPI Dashboard")
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Display data based on aggregation level
|
71 |
|
|
|
10 |
def main():
|
11 |
st.title("Hugging Face Papers KPI Dashboard")
|
12 |
|
13 |
+
# 2 tabs: one for daily data, one for weekly data
|
14 |
+
st.sidebar.title("Navigation")
|
15 |
+
selection = st.sidebar.selectbox("Go to", ["Daily/weekly/monthly data", "Aggregated data"])
|
16 |
+
|
17 |
+
if selection == "Daily/weekly/monthly data":
|
18 |
+
# TODO use this instead
|
19 |
+
# df = get_data()
|
20 |
+
df = pd.read_csv('/Users/nielsrogge/Downloads/daily_papers_enriched (1).csv')
|
21 |
+
df = df.drop(['Unnamed: 0'], axis=1)
|
22 |
+
# Use date as index
|
23 |
+
df = df.set_index('date')
|
24 |
+
df.index = pd.to_datetime(df.index)
|
25 |
+
df = df.sort_index()
|
26 |
+
|
27 |
+
# Button to select day, month or week
|
28 |
+
# Add streamlit selectbox.
|
29 |
+
view_level = st.selectbox(label="View data per day, week or month", options=["day", "week", "month"])
|
30 |
+
|
31 |
+
if view_level == "day":
|
32 |
+
# make a button to select the day, defaulting to today
|
33 |
+
day = st.date_input("Select day", value="today", format="DD/MM/YYYY")
|
34 |
+
# convert to the day of a Pandas Timestamp
|
35 |
+
day = pd.Timestamp(day)
|
36 |
+
|
37 |
+
print("Day:", day)
|
38 |
+
|
39 |
+
df = df[df.index.date == day.date()]
|
40 |
+
|
41 |
+
st.write(f"Showing data for {day.strftime('%d/%m/%Y')}")
|
42 |
+
|
43 |
+
num_artifacts = df[(df['num_models'] > 0) | (df['num_datasets'] > 0) | (df['num_spaces'] > 0)].shape[0]
|
44 |
+
|
45 |
+
st.markdown(f"""
|
46 |
+
## Number of papers: {df.shape[0]}
|
47 |
+
#### Number of papers with a Github link: {df['github'].notnull().sum()}
|
48 |
+
#### Number of papers with at least one HF artifact: {num_artifacts}
|
49 |
+
""")
|
50 |
+
|
51 |
+
st.dataframe(df,
|
52 |
+
hide_index=True,
|
53 |
+
column_order=("paper_page", "title", "github", "num_models", "num_datasets", "num_spaces"),
|
54 |
+
column_config={"github": st.column_config.LinkColumn(),
|
55 |
+
"paper_page": st.column_config.LinkColumn()},
|
56 |
+
width=2000)
|
57 |
+
|
58 |
+
elif view_level == "week":
|
59 |
+
# make a button to select the week
|
60 |
+
week = st.number_input("Select week", value=datetime.today().isocalendar()[1], min_value=1, max_value=52)
|
61 |
+
|
62 |
+
df = df.loc[df['date'].dt.isocalendar().week == week.isocalendar().week]
|
63 |
+
|
64 |
+
st.write(f"Showing data for {day}")
|
65 |
+
st.dataframe(df)
|
66 |
+
|
67 |
+
elif view_level == "month":
|
68 |
+
# make a button to select the month, defaulting to current month
|
69 |
+
month = st.sidebar.date_input("Select month", value=pd.Timestamp.today().month_name())
|
70 |
+
|
71 |
+
df = df.loc[df['date'].dt.month_name() == month]
|
72 |
+
|
73 |
+
st.write(f"Showing data for {day}")
|
74 |
+
st.dataframe(df)
|
75 |
+
|
76 |
+
elif selection == "Aggregated data":
|
77 |
+
st.write("Aggregated data")
|
78 |
+
|
79 |
+
else:
|
80 |
+
st.write("Error: selection not recognized")
|
81 |
|
82 |
# Display data based on aggregation level
|
83 |
|