Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,7 +77,7 @@ def download_and_save_abstract(url, title):
|
|
| 77 |
def download_and_save_pdf(url, title):
|
| 78 |
response = requests.get(url)
|
| 79 |
if response.status_code == 200:
|
| 80 |
-
filename = f"{title.replace(' ', '_')}.pdf"
|
| 81 |
with open(filename, 'wb') as f:
|
| 82 |
f.write(response.content)
|
| 83 |
return filename
|
|
@@ -543,6 +543,7 @@ def compare_and_delete_files(files):
|
|
| 543 |
def get_file_size(file_path):
|
| 544 |
return os.path.getsize(file_path)
|
| 545 |
|
|
|
|
| 546 |
def FileSidebar():
|
| 547 |
# File Sidebar for files 🌐View, 📂Open, ▶️Run, and 🗑Delete per file
|
| 548 |
all_files = glob.glob("*.md") + glob.glob("*_abstract.html") + glob.glob("*.pdf")
|
|
@@ -566,9 +567,12 @@ def FileSidebar():
|
|
| 566 |
|
| 567 |
# Add files 🌐View, 📂Open, ▶️Run, and 🗑Delete per file
|
| 568 |
for file in all_files:
|
|
|
|
|
|
|
|
|
|
| 569 |
col1, col2, col3, col4, col5 = st.sidebar.columns([1,6,1,1,1]) # adjust the ratio as needed
|
| 570 |
with col1:
|
| 571 |
-
if st.button("🌐", key="view_"
|
| 572 |
file_contents = load_file(file)
|
| 573 |
file_name=file
|
| 574 |
next_action='md'
|
|
@@ -576,7 +580,7 @@ def FileSidebar():
|
|
| 576 |
with col2:
|
| 577 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
| 578 |
with col3:
|
| 579 |
-
if st.button("📂", key="open_"
|
| 580 |
file_contents = load_file(file)
|
| 581 |
file_name=file
|
| 582 |
next_action='open'
|
|
@@ -585,19 +589,20 @@ def FileSidebar():
|
|
| 585 |
st.session_state['filetext'] = file_contents
|
| 586 |
st.session_state['next_action'] = next_action
|
| 587 |
with col4:
|
| 588 |
-
if st.button("▶️", key="read_"
|
| 589 |
file_contents = load_file(file)
|
| 590 |
file_name=file
|
| 591 |
next_action='search'
|
| 592 |
st.session_state['next_action'] = next_action
|
| 593 |
with col5:
|
| 594 |
-
if st.button("🗑", key="delete_"
|
| 595 |
os.remove(file)
|
| 596 |
file_name=file
|
| 597 |
st.rerun()
|
| 598 |
next_action='delete'
|
| 599 |
st.session_state['next_action'] = next_action
|
| 600 |
|
|
|
|
| 601 |
|
| 602 |
|
| 603 |
# 🚩File duplicate detector - useful to prune and view all. Pruning works well by file size detection of two similar and flags the duplicate.
|
|
|
|
| 77 |
def download_and_save_pdf(url, title):
|
| 78 |
response = requests.get(url)
|
| 79 |
if response.status_code == 200:
|
| 80 |
+
filename = f"{title.replace(' ', '_')}_abstract.pdf" # Changed to match HTML naming
|
| 81 |
with open(filename, 'wb') as f:
|
| 82 |
f.write(response.content)
|
| 83 |
return filename
|
|
|
|
| 543 |
def get_file_size(file_path):
|
| 544 |
return os.path.getsize(file_path)
|
| 545 |
|
| 546 |
+
|
| 547 |
def FileSidebar():
|
| 548 |
# File Sidebar for files 🌐View, 📂Open, ▶️Run, and 🗑Delete per file
|
| 549 |
all_files = glob.glob("*.md") + glob.glob("*_abstract.html") + glob.glob("*.pdf")
|
|
|
|
| 567 |
|
| 568 |
# Add files 🌐View, 📂Open, ▶️Run, and 🗑Delete per file
|
| 569 |
for file in all_files:
|
| 570 |
+
# Generate a unique timestamp for each iteration
|
| 571 |
+
timestamp = time.strftime("%H%M%S%f")[:-4] # HHMMSSNN format
|
| 572 |
+
|
| 573 |
col1, col2, col3, col4, col5 = st.sidebar.columns([1,6,1,1,1]) # adjust the ratio as needed
|
| 574 |
with col1:
|
| 575 |
+
if st.button("🌐", key=f"view_{timestamp}_{file}"): # view emoji button
|
| 576 |
file_contents = load_file(file)
|
| 577 |
file_name=file
|
| 578 |
next_action='md'
|
|
|
|
| 580 |
with col2:
|
| 581 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
| 582 |
with col3:
|
| 583 |
+
if st.button("📂", key=f"open_{timestamp}_{file}"): # open emoji button
|
| 584 |
file_contents = load_file(file)
|
| 585 |
file_name=file
|
| 586 |
next_action='open'
|
|
|
|
| 589 |
st.session_state['filetext'] = file_contents
|
| 590 |
st.session_state['next_action'] = next_action
|
| 591 |
with col4:
|
| 592 |
+
if st.button("▶️", key=f"read_{timestamp}_{file}"): # search emoji button
|
| 593 |
file_contents = load_file(file)
|
| 594 |
file_name=file
|
| 595 |
next_action='search'
|
| 596 |
st.session_state['next_action'] = next_action
|
| 597 |
with col5:
|
| 598 |
+
if st.button("🗑", key=f"delete_{timestamp}_{file}"):
|
| 599 |
os.remove(file)
|
| 600 |
file_name=file
|
| 601 |
st.rerun()
|
| 602 |
next_action='delete'
|
| 603 |
st.session_state['next_action'] = next_action
|
| 604 |
|
| 605 |
+
|
| 606 |
|
| 607 |
|
| 608 |
# 🚩File duplicate detector - useful to prune and view all. Pruning works well by file size detection of two similar and flags the duplicate.
|