Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -578,6 +578,36 @@ def display_file_history_in_sidebar():
|
|
578 |
st.sidebar.markdown("---")
|
579 |
st.sidebar.markdown("### π File History")
|
580 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
581 |
# Gather all files
|
582 |
md_files = glob.glob("*.md")
|
583 |
mp3_files = glob.glob("*.mp3")
|
@@ -588,29 +618,8 @@ def display_file_history_in_sidebar():
|
|
588 |
st.sidebar.write("No files found.")
|
589 |
return
|
590 |
|
591 |
-
# Sort newest first
|
592 |
-
all_files = sorted(all_files, key=os.path.getmtime, reverse=True)
|
593 |
|
594 |
-
|
595 |
-
fname = os.path.basename(f)
|
596 |
-
ext = os.path.splitext(fname)[1].lower().strip('.')
|
597 |
-
emoji = FILE_EMOJIS.get(ext, 'π¦')
|
598 |
-
time_str = datetime.fromtimestamp(os.path.getmtime(f)).strftime("%Y-%m-%d %H:%M:%S")
|
599 |
-
|
600 |
-
with st.sidebar.expander(f"{emoji} {fname}"):
|
601 |
-
st.write(f"**Modified:** {time_str}")
|
602 |
-
if ext == "md":
|
603 |
-
with open(f, "r", encoding="utf-8") as file_in:
|
604 |
-
snippet = file_in.read(200).replace("\n", " ")
|
605 |
-
if len(snippet) == 200:
|
606 |
-
snippet += "..."
|
607 |
-
st.write(snippet)
|
608 |
-
st.markdown(get_download_link(f, file_type="md"), unsafe_allow_html=True)
|
609 |
-
elif ext in ["mp3","wav"]:
|
610 |
-
st.audio(f)
|
611 |
-
st.markdown(get_download_link(f, file_type=ext), unsafe_allow_html=True)
|
612 |
-
else:
|
613 |
-
st.markdown(get_download_link(f), unsafe_allow_html=True)
|
614 |
|
615 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
616 |
# 7. MAIN APP
|
|
|
578 |
st.sidebar.markdown("---")
|
579 |
st.sidebar.markdown("### π File History")
|
580 |
|
581 |
+
# Add Delete All and Download All buttons in a row
|
582 |
+
col1, col2 = st.sidebar.columns(2)
|
583 |
+
with col1:
|
584 |
+
if st.button("ποΈ Delete All"):
|
585 |
+
# Delete all files except README.md
|
586 |
+
for pattern in ["*.md", "*.mp3", "*.mp4"]:
|
587 |
+
for f in glob.glob(pattern):
|
588 |
+
if f.lower() != "readme.md":
|
589 |
+
try:
|
590 |
+
os.remove(f)
|
591 |
+
except Exception as e:
|
592 |
+
st.warning(f"Error deleting {f}: {str(e)}")
|
593 |
+
st.rerun()
|
594 |
+
|
595 |
+
with col2:
|
596 |
+
# Get all files for potential zip
|
597 |
+
md_files = [f for f in glob.glob("*.md") if f.lower() != "readme.md"]
|
598 |
+
mp4_files = glob.glob("*.mp4")
|
599 |
+
if md_files or mp4_files:
|
600 |
+
# Use last query if available, otherwise generic name
|
601 |
+
zip_name = "Download.zip"
|
602 |
+
if 'last_query' in st.session_state and st.session_state['last_query']:
|
603 |
+
zip_name = f"{clean_text_for_filename(st.session_state['last_query'])[:30]}.zip"
|
604 |
+
|
605 |
+
if st.button("π¦ Download All"):
|
606 |
+
with zipfile.ZipFile(zip_name, 'w') as z:
|
607 |
+
for f in md_files + mp4_files:
|
608 |
+
z.write(f)
|
609 |
+
st.sidebar.markdown(get_download_link(zip_name), unsafe_allow_html=True)
|
610 |
+
|
611 |
# Gather all files
|
612 |
md_files = glob.glob("*.md")
|
613 |
mp3_files = glob.glob("*.mp3")
|
|
|
618 |
st.sidebar.write("No files found.")
|
619 |
return
|
620 |
|
|
|
|
|
621 |
|
622 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
623 |
|
624 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
625 |
# 7. MAIN APP
|