EasySci commited on
Commit
f930455
·
1 Parent(s): 3a8a1ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -67
app.py CHANGED
@@ -1,40 +1,75 @@
1
  import panel as pn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # Create buttons for the toggleable sidebar
4
- button1 = pn.widgets.Button(icon='home', name="Home", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140)
5
- button2 = pn.widgets.Button(icon='file-analytics', name='My papers', icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140)
6
- button3 = pn.widgets.Button(icon='settings', icon_size='1.5em', name='Settings', button_type = 'primary', button_style = 'outline', width = 140)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Create a column layout for the buttons inside the toggleable sidebar
9
- buttons = pn.Column(button1, button2, button3 , css_classes=['hidden'])
10
-
11
- instructions = """
12
- ## Modified-gravity wormholes without exotic matter
13
- ### Tiberiu Harko, Francisco S. N. Lobo, M. K. Mak, and Sergey V. Sushkov
14
- A fundamental ingredient in wormhole physics is the flaring-out condition at the throat which,
15
- in classical general relativity, entails the violation of the null energy condition. In this work, we
16
- present the most general conditions.....
17
- """
18
-
19
- instructions2 = """
20
- ## Viability of Bouncing Cosmology in Energy-Momentum-Squared
21
- ### Ahmed H. Barbar, Adel M. Awad, and Mohammad T. AlFiky
22
- We analyze the early-time isotropic cosmology in the so-called energy-momentum-squared gravity
23
- (EMSG). In this theory, a FORMATAÇAO term is added to the Einstein-Hilbert action, which has been
24
- shown to replace the initial singularity by a regular bounce. We show that this is not the case,
25
- and the bouncing solution obtained does.....
26
- """
27
-
28
- text = pn.pane.Markdown(instructions)
29
- text2 = pn.pane.Markdown(instructions2)
30
 
31
  # List to store the entered options
32
- entered_options = [
33
- "Astrophysics",
34
- "Condensed Matter",
35
- "Mathematical Physics",
36
- "Nuclear Experiment"
37
- ]
38
 
39
  # Create buttons for the header
40
  header_buttons = pn.Row(sizing_mode='stretch_width', css_classes=['header-buttons'])
@@ -45,30 +80,50 @@ add_to_header_button = pn.widgets.Button(name="", icon='search', icon_size='1.5e
45
  # List to store the names of buttons to be added to the header
46
  buttons_to_add = []
47
 
 
 
48
  # Callback for adding selected options to the list
49
  def add_to_header(event):
 
 
50
  selected_options = filter_list.value
51
  if selected_options:
52
  for option in selected_options:
53
  if option not in buttons_to_add: # Check if option is already in header
54
  buttons_to_add.append(option) # Add to header if not already present
 
 
 
55
  filter_list.value = [] # Clear the selected options after adding them to the header
56
  update_header() # Update the header after adding options
57
 
 
58
  add_to_header_button.on_click(add_to_header)
59
 
60
  # Function to update the header layout with the newly created buttons
61
  def update_header():
 
62
  header_buttons.clear() # Clear the existing buttons
 
63
  for button_name in buttons_to_add:
64
  header_button = pn.widgets.Button(name=button_name, button_type = 'primary', button_style = 'outline')
65
  header_button.on_click(remove_from_header) # Add callback to remove the header button
66
  header_buttons.append(header_button)
67
-
68
- print(buttons_to_add, flush = True)
69
  # Update the filter list options to exclude buttons that are already in the header
70
  filter_list.options = [option for option in entered_options if option not in buttons_to_add]
71
-
 
 
 
 
 
 
 
 
 
 
 
72
  # MultiChoice widget to display the filter options with delete buttons
73
  filter_list = pn.widgets.MultiChoice(
74
  name='',
@@ -80,49 +135,20 @@ filter_list = pn.widgets.MultiChoice(
80
  styles={'background': '#f0f0f0'},
81
  placeholder="Search Topics"
82
  )
83
-
84
- # Callback to remove the clicked header button
85
- def remove_from_header(event):
86
- button = event.obj # Get the clicked button
87
- if button.name in buttons_to_add:
88
- buttons_to_add.remove(button.name) # Remove from the header buttons list
89
- filter_list.options.append(button.name) # Add back to the filter list options
90
- update_header() # Update the header and filter list
91
-
92
  # Layout using Template
93
  template = pn.template.FastListTemplate(
94
  title="EasySciRead",
95
- header=[pn.Row(header_buttons, width=800, sizing_mode='fixed'), pn.Row(filter_list, width=250), pn.Row(add_to_header_button, width=55)],
96
- main=[
97
- # First row of the grid
98
- pn.Row(pn.pane.Markdown("# Cosmology"),
99
- pn.Column(text, text2, sizing_mode='stretch_width'),
100
- pn.Column(text2, text, sizing_mode='stretch_width'),
101
- sizing_mode='stretch_width',
102
- ),
103
- # Second row of the grid
104
- pn.Row(pn.pane.Markdown("# Astrophysics"),
105
- pn.Column(text, text2, sizing_mode='stretch_width'),
106
- sizing_mode='stretch_width',
107
- ),
108
- ],
109
  sidebar=[buttons],
110
  accent_base_color="#88d8b0",
111
  header_background="#FFFFFF",
112
  header_color="#000000",
113
  text_align='center',
114
- sidebar_width=150
 
115
  )
116
 
117
-
118
- def run_code(event):
119
- # Add your desired Python code here
120
- # For example, let's print "Hello, Panel!" when the button is clicked
121
- print("Hello, Panel!", flush = True)
122
-
123
-
124
- # Attach the function to the button's on_click event
125
- button3.on_click(run_code)
126
-
127
  # Run the app
128
  template.servable()
 
1
  import panel as pn
2
+ pn.extension('katex')
3
+
4
+ import pytz
5
+ from datetime import date
6
+ from datetime import datetime
7
+ from dateutil.relativedelta import relativedelta, MO
8
+ import param
9
+
10
+ import TLDR
11
+ from src.search import Search_Papers
12
+
13
+ class MainBody(param.Parameterized):
14
+ main_body = param.List(default=[pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})])
15
+
16
+ @param.depends("main_body")
17
+ def update(self):
18
+ return pn.Column(*self.main_body)
19
+
20
+ main_body_instance = MainBody()
21
+
22
+ paper_list = [] # Add this line to initialize paper_list as an empty list
23
+
24
+ main_body = [pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})]
25
+
26
+ # Create buttons for the toggleable sidebar
27
+ # button1 = pn.widgets.Button(name="🏠 Home", button_type='default', button_style='outline', width=140)
28
+ # button2 = pn.widgets.Button(name='📁 My papers', button_type='default', button_style='outline', width=140)
29
+ # button3 = pn.widgets.Toggle(name='⚙️ Settings', button_type='default', button_style='outline', width=140, value=False)
30
 
31
  # Create buttons for the toggleable sidebar
32
+ button1 = pn.widgets.Button(icon='home', name="Daily papers", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140)
33
+ button2 = pn.widgets.Button(icon='calendar-filled', name="Search papers", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140)
34
+ button3 = pn.widgets.Button(icon='file-analytics', name='My papers', icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140)
35
+ button4 = pn.widgets.Toggle(name='Accessibility',icon='settings', icon_size='1.5em', button_type='default', button_style='outline', width=140, value=False)
36
+
37
+ # Custom RadioButtonGroup widget
38
+ select = pn.widgets.RadioButtonGroup(value="Scientic", options=["General", "Scientic"], name='String', align='center', button_type='default') # , align='center'
39
+ select2 = pn.widgets.RadioButtonGroup(value="Normal", options=["Bionic", "Normal"], name='String', align='center', button_type='default')
40
+
41
+ # Define a callback to display the selected value
42
+ def display_selected_value(event):
43
+ print(f"Selected value: {event.new}", flush=True)
44
+
45
+ # Attach the callback to the value_change event of the RadioButtonGroup
46
+ select.param.watch(display_selected_value, 'value')
47
+ select2.param.watch(display_selected_value, 'value')
48
+
49
 
50
  # Create a column layout for the buttons inside the toggleable sidebar
51
+ buttons = pn.Column(
52
+ button1, button2, button3,
53
+ pn.Column(
54
+ select,
55
+ select2,
56
+ visible=True,
57
+ sizing_mode='stretch_width',
58
+ ),
59
+ css_classes=['hidden']
60
+ )
61
+
62
+ # Define a callback to show/hide the select buttons when "Settings" button is toggled
63
+ def toggle_settings(event):
64
+ buttons[-1].visible = event.new
65
+
66
+ button3.param.watch(toggle_settings, 'value')
 
 
 
 
 
67
 
68
  # List to store the entered options
69
+ loaded_dict = TLDR.load_categories()
70
+
71
+ arxiv_tags = list(loaded_dict.keys())
72
+ entered_options = list(loaded_dict.values())
 
 
73
 
74
  # Create buttons for the header
75
  header_buttons = pn.Row(sizing_mode='stretch_width', css_classes=['header-buttons'])
 
80
  # List to store the names of buttons to be added to the header
81
  buttons_to_add = []
82
 
83
+ paper_list = []
84
+
85
  # Callback for adding selected options to the list
86
  def add_to_header(event):
87
+ global paper_list
88
+
89
  selected_options = filter_list.value
90
  if selected_options:
91
  for option in selected_options:
92
  if option not in buttons_to_add: # Check if option is already in header
93
  buttons_to_add.append(option) # Add to header if not already present
94
+
95
+ paper_list_itr = TLDR.run_code(option, loaded_dict)
96
+ paper_list.append(paper_list_itr)
97
  filter_list.value = [] # Clear the selected options after adding them to the header
98
  update_header() # Update the header after adding options
99
 
100
+
101
  add_to_header_button.on_click(add_to_header)
102
 
103
  # Function to update the header layout with the newly created buttons
104
  def update_header():
105
+ global paper_list
106
  header_buttons.clear() # Clear the existing buttons
107
+
108
  for button_name in buttons_to_add:
109
  header_button = pn.widgets.Button(name=button_name, button_type = 'primary', button_style = 'outline')
110
  header_button.on_click(remove_from_header) # Add callback to remove the header button
111
  header_buttons.append(header_button)
112
+ buttons_to_add
 
113
  # Update the filter list options to exclude buttons that are already in the header
114
  filter_list.options = [option for option in entered_options if option not in buttons_to_add]
115
+ main_body_instance.main_body = TLDR.update_mainTLDR(buttons_to_add, paper_list)
116
+
117
+ # Callback to remove the clicked header button
118
+ def remove_from_header(event):
119
+ global paper_list
120
+ button = event.obj # Get the clicked button
121
+ if button.name in buttons_to_add:
122
+ del paper_list[buttons_to_add.index(button.name)]
123
+ buttons_to_add.remove(button.name) # Remove from the header buttons list
124
+ filter_list.options.append(button.name) # Add back to the filter list options
125
+ update_header() # Update the header and filter list
126
+
127
  # MultiChoice widget to display the filter options with delete buttons
128
  filter_list = pn.widgets.MultiChoice(
129
  name='',
 
135
  styles={'background': '#f0f0f0'},
136
  placeholder="Search Topics"
137
  )
138
+
 
 
 
 
 
 
 
 
139
  # Layout using Template
140
  template = pn.template.FastListTemplate(
141
  title="EasySciRead",
142
+ header=[pn.Row(header_buttons, width=750, sizing_mode='stretch_width'), pn.Row(filter_list, width=250), pn.Row(add_to_header_button, width=55)],
143
+ main= main_body_instance.update,
 
 
 
 
 
 
 
 
 
 
 
 
144
  sidebar=[buttons],
145
  accent_base_color="#88d8b0",
146
  header_background="#FFFFFF",
147
  header_color="#000000",
148
  text_align='center',
149
+ sidebar_width=200,
150
+ sizing_mode = 'stretch_both'
151
  )
152
 
 
 
 
 
 
 
 
 
 
 
153
  # Run the app
154
  template.servable()