awacke1 commited on
Commit
5c46c71
Β·
verified Β·
1 Parent(s): a2098d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -7
app.py CHANGED
@@ -442,7 +442,7 @@ def display_papers_in_sidebar(papers):
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,10 +454,7 @@ def create_zip_of_files(md_files, mp3_files, wav_files, input_question):
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,6 +472,35 @@ def create_zip_of_files(md_files, mp3_files, wav_files, input_question):
475
  z.write(f)
476
  return short_zip_name
477
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  # ─────────────────────────────────────────────────────────
479
  # 5. MAIN LOGIC: AI LOOKUP & VOICE INPUT
480
  # ─────────────────────────────────────────────────────────
@@ -614,9 +640,23 @@ def display_file_history_in_sidebar():
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
 
 
442
  # 4. ZIP FUNCTION
443
  # ─────────────────────────────────────────────────────────
444
 
445
+ def create_zip_of_files_mp3(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('.mp3') or f.endswith('.wav'):
 
 
 
458
  basename = os.path.splitext(os.path.basename(f))[0]
459
  words = basename.replace('_', ' ')
460
  all_content.append(words)
 
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
  # ─────────────────────────────────────────────────────────
 
640
  for f in all_wav:
641
  os.remove(f)
642
  st.session_state.should_rerun = True
643
+ if st.button("πŸ—‘ Delete All MD"):
644
+ for f in all_md:
645
+ os.remove(f)
646
+ st.session_state.should_rerun = True
647
+ if st.button("πŸ—‘ Delete All MP3"):
648
+ for f in all_mp3:
649
+ os.remove(f)
650
+ for f in all_wav:
651
+ os.remove(f)
652
+ st.session_state.should_rerun = True
653
  with col4:
654
+ if st.button("⬇️ Zip All MD"):
655
+ zip_name = create_zip_of_files_md(md_files, st.session_state.get('last_query', ''))
656
+ if zip_name:
657
+ st.sidebar.markdown(get_download_link(zip_name, "zip"), unsafe_allow_html=True)
658
+ if st.button("⬇️ Zip All MP3"):
659
+ zip_name = create_zip_of_files_mp3(mp3_files, wav_files, st.session_state.get('last_query', ''))
660
  if zip_name:
661
  st.sidebar.markdown(get_download_link(zip_name, "zip"), unsafe_allow_html=True)
662