Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -561,7 +561,6 @@ def compare_and_delete_files(files):
|
|
561 |
def get_file_size(file_path):
|
562 |
return os.path.getsize(file_path)
|
563 |
|
564 |
-
|
565 |
def FileSidebar():
|
566 |
# File Sidebar for files ๐View, ๐Edit, and ๐Delete per file
|
567 |
all_files = glob.glob("*.md") + glob.glob("*_abstract.html") + glob.glob("*_abstract.pdf")
|
@@ -571,15 +570,15 @@ def FileSidebar():
|
|
571 |
# โฌ๏ธ Download
|
572 |
Files1, Files2 = st.sidebar.columns(2)
|
573 |
with Files1:
|
574 |
-
if st.button("๐ Delete All"):
|
575 |
for file in all_files:
|
576 |
try:
|
577 |
os.remove(file)
|
578 |
except Exception as e:
|
579 |
-
st.error(f"Error deleting {file}: {str(e)}")
|
580 |
st.rerun()
|
581 |
with Files2:
|
582 |
-
if st.button("โฌ๏ธ Download"):
|
583 |
zip_file = create_zip_of_files(all_files)
|
584 |
st.sidebar.markdown(get_zip_download_link(zip_file), unsafe_allow_html=True)
|
585 |
|
@@ -589,23 +588,33 @@ def FileSidebar():
|
|
589 |
|
590 |
col1, col2, col3, col4 = st.sidebar.columns([3,1,1,1])
|
591 |
with col1:
|
592 |
-
st.markdown(f"**{file}**")
|
593 |
with col2:
|
594 |
-
if st.button("๐", key=f"view_{timestamp}_{file}"):
|
595 |
-
|
|
|
596 |
with col3:
|
597 |
-
if st.button("๐", key=f"edit_{timestamp}_{file}"):
|
598 |
-
|
|
|
599 |
with col4:
|
600 |
-
if st.button("๐", key=f"delete_{timestamp}_{file}"):
|
601 |
try:
|
602 |
os.remove(file)
|
603 |
-
st.success(f"Deleted {file}")
|
604 |
except Exception as e:
|
605 |
-
st.error(f"Error deleting {file}: {str(e)}")
|
606 |
st.rerun()
|
607 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
608 |
def view_file(file):
|
|
|
609 |
file_extension = os.path.splitext(file)[1].lower()
|
610 |
try:
|
611 |
if file_extension == '.pdf':
|
@@ -620,6 +629,7 @@ def view_file(file):
|
|
620 |
st.error(f"Error viewing {file}: {str(e)}")
|
621 |
|
622 |
def edit_file(file):
|
|
|
623 |
file_extension = os.path.splitext(file)[1].lower()
|
624 |
try:
|
625 |
if file_extension == '.pdf':
|
|
|
561 |
def get_file_size(file_path):
|
562 |
return os.path.getsize(file_path)
|
563 |
|
|
|
564 |
def FileSidebar():
|
565 |
# File Sidebar for files ๐View, ๐Edit, and ๐Delete per file
|
566 |
all_files = glob.glob("*.md") + glob.glob("*_abstract.html") + glob.glob("*_abstract.pdf")
|
|
|
570 |
# โฌ๏ธ Download
|
571 |
Files1, Files2 = st.sidebar.columns(2)
|
572 |
with Files1:
|
573 |
+
if st.sidebar.button("๐ Delete All"):
|
574 |
for file in all_files:
|
575 |
try:
|
576 |
os.remove(file)
|
577 |
except Exception as e:
|
578 |
+
st.sidebar.error(f"Error deleting {file}: {str(e)}")
|
579 |
st.rerun()
|
580 |
with Files2:
|
581 |
+
if st.sidebar.button("โฌ๏ธ Download"):
|
582 |
zip_file = create_zip_of_files(all_files)
|
583 |
st.sidebar.markdown(get_zip_download_link(zip_file), unsafe_allow_html=True)
|
584 |
|
|
|
588 |
|
589 |
col1, col2, col3, col4 = st.sidebar.columns([3,1,1,1])
|
590 |
with col1:
|
591 |
+
st.sidebar.markdown(f"**{file}**")
|
592 |
with col2:
|
593 |
+
if st.sidebar.button("๐", key=f"view_{timestamp}_{file}"):
|
594 |
+
st.session_state.current_file = file
|
595 |
+
st.session_state.action = 'view'
|
596 |
with col3:
|
597 |
+
if st.sidebar.button("๐", key=f"edit_{timestamp}_{file}"):
|
598 |
+
st.session_state.current_file = file
|
599 |
+
st.session_state.action = 'edit'
|
600 |
with col4:
|
601 |
+
if st.sidebar.button("๐", key=f"delete_{timestamp}_{file}"):
|
602 |
try:
|
603 |
os.remove(file)
|
604 |
+
st.sidebar.success(f"Deleted {file}")
|
605 |
except Exception as e:
|
606 |
+
st.sidebar.error(f"Error deleting {file}: {str(e)}")
|
607 |
st.rerun()
|
608 |
|
609 |
+
# Display content in main area
|
610 |
+
if 'current_file' in st.session_state and 'action' in st.session_state:
|
611 |
+
if st.session_state.action == 'view':
|
612 |
+
view_file(st.session_state.current_file)
|
613 |
+
elif st.session_state.action == 'edit':
|
614 |
+
edit_file(st.session_state.current_file)
|
615 |
+
|
616 |
def view_file(file):
|
617 |
+
st.header(f"Viewing: {file}")
|
618 |
file_extension = os.path.splitext(file)[1].lower()
|
619 |
try:
|
620 |
if file_extension == '.pdf':
|
|
|
629 |
st.error(f"Error viewing {file}: {str(e)}")
|
630 |
|
631 |
def edit_file(file):
|
632 |
+
st.header(f"Editing: {file}")
|
633 |
file_extension = os.path.splitext(file)[1].lower()
|
634 |
try:
|
635 |
if file_extension == '.pdf':
|