Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -442,7 +442,7 @@ def display_papers_in_sidebar(papers):
|
|
| 442 |
# 4. ZIP FUNCTION
|
| 443 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 444 |
|
| 445 |
-
def
|
| 446 |
"""
|
| 447 |
Zip up all relevant files, limiting the final zip name to ~20 chars
|
| 448 |
to avoid overly long base64 strings.
|
|
@@ -454,7 +454,10 @@ def create_zip_of_files_mp3(mp3_files, wav_files, input_question):
|
|
| 454 |
|
| 455 |
all_content = []
|
| 456 |
for f in all_files:
|
| 457 |
-
if f.endswith('.
|
|
|
|
|
|
|
|
|
|
| 458 |
basename = os.path.splitext(os.path.basename(f))[0]
|
| 459 |
words = basename.replace('_', ' ')
|
| 460 |
all_content.append(words)
|
|
@@ -472,35 +475,6 @@ def create_zip_of_files_mp3(mp3_files, wav_files, input_question):
|
|
| 472 |
z.write(f)
|
| 473 |
return short_zip_name
|
| 474 |
|
| 475 |
-
def create_zip_of_files_md(md_files, input_question):
|
| 476 |
-
"""
|
| 477 |
-
Zip up all relevant files, limiting the final zip name to ~20 chars
|
| 478 |
-
to avoid overly long base64 strings.
|
| 479 |
-
"""
|
| 480 |
-
md_files = [f for f in md_files if os.path.basename(f).lower() != 'readme.md']
|
| 481 |
-
all_files = md_files + mp3_files + wav_files
|
| 482 |
-
if not all_files:
|
| 483 |
-
return None
|
| 484 |
-
|
| 485 |
-
all_content = []
|
| 486 |
-
for f in all_files:
|
| 487 |
-
if f.endswith('.md'):
|
| 488 |
-
with open(f, 'r', encoding='utf-8') as file:
|
| 489 |
-
all_content.append(file.read())
|
| 490 |
-
|
| 491 |
-
all_content.append(input_question)
|
| 492 |
-
combined_content = " ".join(all_content)
|
| 493 |
-
info_terms = get_high_info_terms(combined_content, top_n=10)
|
| 494 |
-
|
| 495 |
-
timestamp = format_timestamp_prefix()
|
| 496 |
-
name_text = '-'.join(term for term in info_terms[:5])
|
| 497 |
-
short_zip_name = (timestamp + "_" + name_text)[:20] + ".zip"
|
| 498 |
-
|
| 499 |
-
with zipfile.ZipFile(short_zip_name, 'w') as z:
|
| 500 |
-
for f in all_files:
|
| 501 |
-
z.write(f)
|
| 502 |
-
return short_zip_name
|
| 503 |
-
|
| 504 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 505 |
# 5. MAIN LOGIC: AI LOOKUP & VOICE INPUT
|
| 506 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -633,33 +607,16 @@ def display_file_history_in_sidebar():
|
|
| 633 |
col1, col4 = st.sidebar.columns(2)
|
| 634 |
with col1:
|
| 635 |
if st.button("π Delete All"):
|
| 636 |
-
for f in
|
| 637 |
os.remove(f)
|
| 638 |
-
|
| 639 |
-
#st.session_state.should_rerun = True
|
| 640 |
-
st.rerun()
|
| 641 |
-
if st.button("π Delete All MD"):
|
| 642 |
-
for f in md_files:
|
| 643 |
os.remove(f)
|
| 644 |
-
|
| 645 |
-
#st.session_state.should_rerun = True
|
| 646 |
-
st.rerun()
|
| 647 |
-
if st.button("π Delete All MP3"):
|
| 648 |
-
for f in mp3_files:
|
| 649 |
os.remove(f)
|
| 650 |
-
|
| 651 |
-
for f in wav_files:
|
| 652 |
-
os.remove(f)
|
| 653 |
-
st.write('Deleted: ' + f)
|
| 654 |
-
#st.session_state.should_rerun = True
|
| 655 |
-
st.rerun()
|
| 656 |
with col4:
|
| 657 |
-
if st.button("β¬οΈ Zip All
|
| 658 |
-
zip_name =
|
| 659 |
-
if zip_name:
|
| 660 |
-
st.sidebar.markdown(get_download_link(zip_name, "zip"), unsafe_allow_html=True)
|
| 661 |
-
if st.button("β¬οΈ Zip All MP3"):
|
| 662 |
-
zip_name = create_zip_of_files_mp3(mp3_files, wav_files, st.session_state.get('last_query', ''))
|
| 663 |
if zip_name:
|
| 664 |
st.sidebar.markdown(get_download_link(zip_name, "zip"), unsafe_allow_html=True)
|
| 665 |
|
|
|
|
| 442 |
# 4. ZIP FUNCTION
|
| 443 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 444 |
|
| 445 |
+
def create_zip_of_files(md_files, mp3_files, wav_files, input_question):
|
| 446 |
"""
|
| 447 |
Zip up all relevant files, limiting the final zip name to ~20 chars
|
| 448 |
to avoid overly long base64 strings.
|
|
|
|
| 454 |
|
| 455 |
all_content = []
|
| 456 |
for f in all_files:
|
| 457 |
+
if f.endswith('.md'):
|
| 458 |
+
with open(f, 'r', encoding='utf-8') as file:
|
| 459 |
+
all_content.append(file.read())
|
| 460 |
+
elif f.endswith('.mp3') or f.endswith('.wav'):
|
| 461 |
basename = os.path.splitext(os.path.basename(f))[0]
|
| 462 |
words = basename.replace('_', ' ')
|
| 463 |
all_content.append(words)
|
|
|
|
| 475 |
z.write(f)
|
| 476 |
return short_zip_name
|
| 477 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 479 |
# 5. MAIN LOGIC: AI LOOKUP & VOICE INPUT
|
| 480 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 607 |
col1, col4 = st.sidebar.columns(2)
|
| 608 |
with col1:
|
| 609 |
if st.button("π Delete All"):
|
| 610 |
+
for f in all_md:
|
| 611 |
os.remove(f)
|
| 612 |
+
for f in all_mp3:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
os.remove(f)
|
| 614 |
+
for f in all_wav:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
os.remove(f)
|
| 616 |
+
st.session_state.should_rerun = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
with col4:
|
| 618 |
+
if st.button("β¬οΈ Zip All"):
|
| 619 |
+
zip_name = create_zip_of_files(md_files, mp3_files, wav_files, st.session_state.get('last_query', ''))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 620 |
if zip_name:
|
| 621 |
st.sidebar.markdown(get_download_link(zip_name, "zip"), unsafe_allow_html=True)
|
| 622 |
|