ale93111 commited on
Commit
5ecb57c
Β·
1 Parent(s): 85f9682
Files changed (1) hide show
  1. src/streamlit_app.py +71 -47
src/streamlit_app.py CHANGED
@@ -3,53 +3,77 @@ from datasets import load_dataset
3
 
4
  st.set_page_config(page_title="Paper Explorer", layout="wide")
5
 
6
- # 1. Initialize Session State for the page number
 
 
7
  if 'page_number' not in st.session_state:
8
  st.session_state.page_number = 0
9
 
10
- st.title("πŸ“š Papers with code Explorer")
11
-
12
- # 2. Setup constants
13
- PAGE_SIZE = 10
14
- dataset_name = "pwc-archive/papers-with-abstracts"
15
-
16
- # 3. Sidebar Navigation
17
- st.sidebar.header("Navigation")
18
-
19
- def next_page():
20
- st.session_state.page_number += 1
21
-
22
- def prev_page():
23
- if st.session_state.page_number > 0:
24
- st.session_state.page_number -= 1
25
-
26
- col1, col2, col3 = st.sidebar.columns([1, 2, 1])
27
-
28
- with col1:
29
- st.button("⬅️", on_click=prev_page, disabled=(st.session_state.page_number == 0))
30
- with col2:
31
- st.write(f"**Page {st.session_state.page_number + 1}**")
32
- with col3:
33
- st.button("➑️", on_click=next_page)
34
-
35
- # 4. Fetch Data based on page
36
- offset = st.session_state.page_number * PAGE_SIZE
37
-
38
- with st.spinner(f"Loading papers {offset} to {offset + PAGE_SIZE}..."):
39
- dataset = load_dataset(dataset_name, split="train", streaming=True)
40
- papers = list(dataset.skip(offset).take(PAGE_SIZE))
41
-
42
- # 5. Display the Results
43
- for p in papers:
44
- with st.container():
45
- st.subheader(p['title'])
46
- st.caption(f"ArXiv ID: {p.get('arxiv_id', 'N/A')}")
47
-
48
- # Display abstract (limiting length for readability)
49
- abstract = p.get('abstract', 'No abstract available.')
50
- st.write(abstract[:500] + ("..." if len(abstract) > 500 else ""))
51
-
52
- if p.get('arxiv_id'):
53
- st.link_button("View on ArXiv", f"https://arxiv.org/abs/{p['arxiv_id']}")
54
-
55
- st.divider()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  st.set_page_config(page_title="Paper Explorer", layout="wide")
5
 
6
+ # 1. Initialize Session States
7
+ if 'current_view' not in st.session_state:
8
+ st.session_state.current_view = "trending" # Default view
9
  if 'page_number' not in st.session_state:
10
  st.session_state.page_number = 0
11
 
12
+ # --- 2. Custom Top Navigation ---
13
+ nav_container = st.container()
14
+ with nav_container:
15
+ col1, col2, col3, col4, col5 = st.columns([1, 1.5, 2, 1, 1])
16
+
17
+ with col1:
18
+ st.markdown("### πŸ“š PWC")
19
+ with col2:
20
+ # When clicked, this button sets the view to "trending"
21
+ if st.button("πŸ”₯ Trending", use_container_width=True):
22
+ st.session_state.current_view = "trending"
23
+ with col3:
24
+ if st.button("πŸ† Browse SOTA", use_container_width=True):
25
+ st.session_state.current_view = "sota"
26
+ with col4:
27
+ if st.button("πŸ“Š Datasets", use_container_width=True):
28
+ st.session_state.current_view = "datasets"
29
+ with col5:
30
+ if st.button("🧩 Methods", use_container_width=True):
31
+ st.session_state.current_view = "methods"
32
+
33
+ st.divider()
34
+
35
+ # --- 3. View Logic ---
36
+
37
+ if st.session_state.current_view == "trending":
38
+ st.subheader("Trending Papers")
39
+
40
+ # Pagination UI
41
+ PAGE_SIZE = 10
42
+ c1, c2, c3 = st.columns([1, 2, 1])
43
+
44
+ with c1:
45
+ if st.button("⬅️ Previous", disabled=(st.session_state.page_number == 0)):
46
+ st.session_state.page_number -= 1
47
+ st.rerun() # Refresh to update data
48
+ with c2:
49
+ st.write(f"Center: Page {st.session_state.page_number + 1}")
50
+ with c3:
51
+ if st.button("Next ➑️"):
52
+ st.session_state.page_number += 1
53
+ st.rerun()
54
+
55
+ # Data Fetching
56
+ offset = st.session_state.page_number * PAGE_SIZE
57
+ with st.spinner("Loading papers..."):
58
+ dataset = load_dataset("pwc-archive/papers-with-abstracts", split="train", streaming=True)
59
+ papers = list(dataset.skip(offset).take(PAGE_SIZE))
60
+
61
+ # Display Papers
62
+ for p in papers:
63
+ with st.container():
64
+ st.markdown(f"### {p['title']}")
65
+ st.write(p['abstract'][:500] + "...")
66
+ if p.get('arxiv_id'):
67
+ st.link_button("View on ArXiv", f"https://arxiv.org/abs/{p['arxiv_id']}")
68
+ st.divider()
69
+
70
+ elif st.session_state.current_view == "sota":
71
+ st.title("πŸ† State-of-the-Art")
72
+ st.info("Leaderboards coming soon! This page will show rankings for different ML tasks.")
73
+ if st.button("Back to Trending"):
74
+ st.session_state.current_view = "trending"
75
+ st.rerun()
76
+
77
+ else:
78
+ st.title("Under Construction")
79
+ st.write(f"The **{st.session_state.current_view}** section is currently being indexed.")