Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -548,21 +548,19 @@ def create_zip_of_files(md_files, mp3_files, wav_files, input_question):
|
|
548 |
return zip_name
|
549 |
|
550 |
def load_files_for_sidebar():
|
551 |
-
"""Load and group files for sidebar display"""
|
552 |
md_files = glob.glob("*.md")
|
553 |
mp3_files = glob.glob("*.mp3")
|
554 |
-
wav_files = glob.glob("*.wav")
|
555 |
|
556 |
md_files = [f for f in md_files if os.path.basename(f).lower() != 'readme.md']
|
557 |
all_files = md_files + mp3_files + wav_files
|
558 |
|
559 |
groups = defaultdict(list)
|
560 |
for f in all_files:
|
561 |
-
#
|
562 |
-
|
563 |
-
|
564 |
-
keywords = get_high_info_terms(' '.join(words), top_n=5)
|
565 |
-
group_name = '_'.join(keywords) if keywords else 'Miscellaneous'
|
566 |
groups[group_name].append(f)
|
567 |
|
568 |
# Sort groups based on latest file modification time
|
@@ -579,12 +577,12 @@ def extract_keywords_from_md(files):
|
|
579 |
return get_high_info_terms(text, top_n=5)
|
580 |
|
581 |
def display_file_manager_sidebar(groups_sorted):
|
582 |
-
"""Display file manager in sidebar"""
|
583 |
st.sidebar.title("🎵 Audio & Docs Manager")
|
584 |
|
585 |
all_md = []
|
586 |
all_mp3 = []
|
587 |
-
all_wav = []
|
588 |
for group_name, files in groups_sorted:
|
589 |
for f in files:
|
590 |
if f.endswith(".md"):
|
@@ -592,9 +590,9 @@ def display_file_manager_sidebar(groups_sorted):
|
|
592 |
elif f.endswith(".mp3"):
|
593 |
all_mp3.append(f)
|
594 |
elif f.endswith(".wav"):
|
595 |
-
all_wav.append(f)
|
596 |
|
597 |
-
top_bar = st.sidebar.columns(4)
|
598 |
with top_bar[0]:
|
599 |
if st.button("🗑 DelAllMD"):
|
600 |
for f in all_md:
|
@@ -617,8 +615,10 @@ def display_file_manager_sidebar(groups_sorted):
|
|
617 |
st.sidebar.markdown(get_download_link(zip_name, file_type="zip"), unsafe_allow_html=True)
|
618 |
|
619 |
for group_name, files in groups_sorted:
|
620 |
-
|
621 |
-
|
|
|
|
|
622 |
c1,c2 = st.columns(2)
|
623 |
with c1:
|
624 |
if st.button("👀ViewGrp", key="view_group_"+group_name):
|
@@ -632,8 +632,10 @@ def display_file_manager_sidebar(groups_sorted):
|
|
632 |
|
633 |
for f in files:
|
634 |
fname = os.path.basename(f)
|
635 |
-
|
636 |
-
|
|
|
|
|
637 |
|
638 |
# 🎯 11. Main Application
|
639 |
def main():
|
|
|
548 |
return zip_name
|
549 |
|
550 |
def load_files_for_sidebar():
|
551 |
+
"""Load and group files for sidebar display based on first 9 characters of filename"""
|
552 |
md_files = glob.glob("*.md")
|
553 |
mp3_files = glob.glob("*.mp3")
|
554 |
+
wav_files = glob.glob("*.wav")
|
555 |
|
556 |
md_files = [f for f in md_files if os.path.basename(f).lower() != 'readme.md']
|
557 |
all_files = md_files + mp3_files + wav_files
|
558 |
|
559 |
groups = defaultdict(list)
|
560 |
for f in all_files:
|
561 |
+
# Get first 9 characters of filename (timestamp) as group name
|
562 |
+
basename = os.path.basename(f)
|
563 |
+
group_name = basename[:9] if len(basename) >= 9 else 'Other'
|
|
|
|
|
564 |
groups[group_name].append(f)
|
565 |
|
566 |
# Sort groups based on latest file modification time
|
|
|
577 |
return get_high_info_terms(text, top_n=5)
|
578 |
|
579 |
def display_file_manager_sidebar(groups_sorted):
|
580 |
+
"""Display file manager in sidebar with timestamp-based groups"""
|
581 |
st.sidebar.title("🎵 Audio & Docs Manager")
|
582 |
|
583 |
all_md = []
|
584 |
all_mp3 = []
|
585 |
+
all_wav = []
|
586 |
for group_name, files in groups_sorted:
|
587 |
for f in files:
|
588 |
if f.endswith(".md"):
|
|
|
590 |
elif f.endswith(".mp3"):
|
591 |
all_mp3.append(f)
|
592 |
elif f.endswith(".wav"):
|
593 |
+
all_wav.append(f)
|
594 |
|
595 |
+
top_bar = st.sidebar.columns(4)
|
596 |
with top_bar[0]:
|
597 |
if st.button("🗑 DelAllMD"):
|
598 |
for f in all_md:
|
|
|
615 |
st.sidebar.markdown(get_download_link(zip_name, file_type="zip"), unsafe_allow_html=True)
|
616 |
|
617 |
for group_name, files in groups_sorted:
|
618 |
+
timestamp_dt = datetime.strptime(group_name, "%y%m_%H%M") if len(group_name) == 9 else None
|
619 |
+
group_label = timestamp_dt.strftime("%Y-%m-%d %H:%M") if timestamp_dt else group_name
|
620 |
+
|
621 |
+
with st.sidebar.expander(f"📁 {group_label} ({len(files)})", expanded=True):
|
622 |
c1,c2 = st.columns(2)
|
623 |
with c1:
|
624 |
if st.button("👀ViewGrp", key="view_group_"+group_name):
|
|
|
632 |
|
633 |
for f in files:
|
634 |
fname = os.path.basename(f)
|
635 |
+
ext = os.path.splitext(fname)[1].lower()
|
636 |
+
emoji = FILE_EMOJIS.get(ext.strip('.'), '')
|
637 |
+
ctime = datetime.fromtimestamp(os.path.getmtime(f)).strftime("%H:%M:%S")
|
638 |
+
st.write(f"{emoji} **{fname}** - {ctime}")
|
639 |
|
640 |
# 🎯 11. Main Application
|
641 |
def main():
|