nielsr HF staff commited on
Commit
570845b
1 Parent(s): 57c87c9

Big improvements to simplify code

Browse files
Files changed (1) hide show
  1. app.py +68 -56
app.py CHANGED
@@ -10,62 +10,74 @@ import pandas as pd
10
  def main():
11
  st.title("Hugging Face Papers KPI Dashboard")
12
 
13
- # TODO use this instead
14
- # df = get_data()
15
- df = pd.read_csv('/Users/nielsrogge/Downloads/daily_papers_enriched (1).csv')
16
- df = df.drop(['Unnamed: 0'], axis=1)
17
- # Use date as index
18
- # Note that it's a string, not a datetime
19
- df = df.set_index('date')
20
- df.index = pd.to_datetime(df.index).strftime('%d-%m-%Y')
21
- df = df.sort_index()
22
-
23
- # Button to select day, month or week
24
- # Add streamlit selectbox.
25
- view_level = st.selectbox(label="View data per day, week or month", options=["day", "week", "month"])
26
-
27
- if view_level == "day":
28
- # make a button to select the day, defaulting to today
29
- day = st.date_input("Select day", value="today", format="DD/MM/YYYY")
30
- # convert to the day of a Pandas Timestamp
31
- day = pd.Timestamp(day)
32
-
33
- print("Day:", day)
34
-
35
- df = df.loc[day.strftime('%d-%m-%Y'):day.strftime('%d-%m-%Y')]
36
-
37
- st.write(f"Showing data for {day.strftime('%d/%m/%Y')}")
38
-
39
- st.markdown(f"""
40
- ## Number of papers: {df.shape[0]}
41
- #### Number of papers with a Github link: {df['github'].notnull().sum()}
42
- #### Number of papers with at least one HF artifact: {df['num_models'].sum()}
43
- """)
44
-
45
- st.dataframe(df,
46
- hide_index=True,
47
- column_order=("paper_page", "title", "github", "num_models", "num_datasets", "num_spaces"),
48
- column_config={"github": st.column_config.LinkColumn(),
49
- "paper_page": st.column_config.LinkColumn()},
50
- width=2000)
51
-
52
- elif view_level == "week":
53
- # make a button to select the week
54
- week = st.sidebar.date_input("Select week", value=pd.Timestamp.today().isocalendar())
55
-
56
- df = df.loc[df['date'].dt.isocalendar().week == week.isocalendar().week]
57
-
58
- st.write(f"Showing data for {day}")
59
- st.dataframe(df)
60
-
61
- elif view_level == "month":
62
- # make a button to select the month, defaulting to current month
63
- month = st.sidebar.date_input("Select month", value=pd.Timestamp.today().month_name())
64
-
65
- df = df.loc[df['date'].dt.month_name() == month]
66
-
67
- st.write(f"Showing data for {day}")
68
- st.dataframe(df)
 
 
 
 
 
 
 
 
 
 
 
 
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