Spaces:
Sleeping
Sleeping
| import panel as pn | |
| import pytz | |
| from datetime import date | |
| from datetime import datetime | |
| from dateutil.relativedelta import relativedelta, MO | |
| import param | |
| import TLDR | |
| from src.search import Search_Papers | |
| class MainBody(param.Parameterized): | |
| main_body = param.List(default=[pn.pane.Markdown("# Please select some tags!")]) | |
| def update(self): | |
| return pn.Column(*self.main_body) | |
| main_body_instance = MainBody() | |
| paper_list = [] # Add this line to initialize paper_list as an empty list | |
| main_body = [pn.Row(pn.pane.Markdown("# Please select some tags!"))] | |
| # Create binary slider buttons for the sidebar | |
| toggle_button = pn.widgets.Toggle(name="Filter", on_text="filter1", off_text="filter2", width=140) | |
| # Function to update the button name when toggled | |
| def update_button_name(event): | |
| if toggle_button.value: | |
| toggle_button.name = "filter1" | |
| else: | |
| toggle_button.name = "filter2" | |
| # Attach the update_button_name function to the button's on_click event | |
| toggle_button.on_click(update_button_name) | |
| # Create a column layout for the buttons inside the toggleable sidebar | |
| buttons = pn.Column( | |
| button1, button2, button3, | |
| toggle_button, | |
| css_classes=['hidden'] | |
| ) | |
| # List to store the entered options | |
| loaded_list = TLDR.load_categories() | |
| arxiv_tags = loaded_list[0] | |
| entered_options = loaded_list[1] | |
| # Create buttons for the header | |
| header_buttons = pn.Row(sizing_mode='stretch_width', css_classes=['header-buttons']) | |
| # "+" button to trigger the addition to the header | |
| add_to_header_button = pn.widgets.Button(name="", icon='search', icon_size='1.5em', button_style = 'outline',button_type = 'light') | |
| # List to store the names of buttons to be added to the header | |
| buttons_to_add = [] | |
| paper_list = [] | |
| # Callback for adding selected options to the list | |
| def add_to_header(event): | |
| global paper_list | |
| selected_options = filter_list.value | |
| if selected_options: | |
| for option in selected_options: | |
| if option not in buttons_to_add: # Check if option is already in header | |
| buttons_to_add.append(option) # Add to header if not already present | |
| paper_list_itr = TLDR.run_code(buttons_to_add, arxiv_tags) | |
| paper_list.append(paper_list_itr) | |
| filter_list.value = [] # Clear the selected options after adding them to the header | |
| update_header() # Update the header after adding options | |
| add_to_header_button.on_click(add_to_header) | |
| # Function to update the header layout with the newly created buttons | |
| def update_header(): | |
| header_buttons.clear() # Clear the existing buttons | |
| for button_name in buttons_to_add: | |
| header_button = pn.widgets.Button(name=button_name, button_type = 'primary', button_style = 'outline') | |
| header_button.on_click(remove_from_header) # Add callback to remove the header button | |
| header_buttons.append(header_button) | |
| main_body_instance.main_body = TLDR.update_mainTLDR(buttons_to_add, paper_list) | |
| # Update the filter list options to exclude buttons that are already in the header | |
| filter_list.options = [option for option in entered_options if option not in buttons_to_add] | |
| # Callback to remove the clicked header button | |
| def remove_from_header(event): | |
| button = event.obj # Get the clicked button | |
| if button.name in buttons_to_add: | |
| buttons_to_add.remove(button.name) # Remove from the header buttons list | |
| filter_list.options.append(button.name) # Add back to the filter list options | |
| update_header() # Update the header and filter list | |
| # MultiChoice widget to display the filter options with delete buttons | |
| filter_list = pn.widgets.MultiChoice( | |
| name='', | |
| value=[], | |
| options=entered_options, | |
| margin=(20, 10), | |
| sizing_mode='fixed', | |
| solid=False, | |
| styles={'background': '#f0f0f0'}, | |
| placeholder="Search Topics" | |
| ) | |
| # Layout using Template | |
| template = pn.template.FastListTemplate( | |
| title="EasySciRead", | |
| header=[pn.Row(header_buttons, width=750, sizing_mode='fixed'), pn.Row(filter_list, width=250), pn.Row(add_to_header_button, width=55)], | |
| main= main_body_instance.update, | |
| sidebar=[buttons], | |
| accent_base_color="#88d8b0", | |
| header_background="#FFFFFF", | |
| header_color="#000000", | |
| text_align='center', | |
| sidebar_width=150 | |
| ) | |
| # Run the app | |
| template.servable() |