euler314 commited on
Commit
d9324de
·
verified ·
1 Parent(s): 5b830c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -615,12 +615,12 @@ def main():
615
 
616
  files = asyncio.run(run_deep_search())
617
  if files:
618
- # Save all discovered files even if duplicated
619
  st.session_state.discovered_files = files
620
  st.session_state.current_url = url
621
  st.success(f"Found {len(files)} files!")
622
 
623
- # File selection block 1
624
  col1, col2 = st.columns([1, 4])
625
  with col1:
626
  if st.button("Select All", key="select_all_btn"):
@@ -664,7 +664,7 @@ def main():
664
  file_info = files[idx]
665
  status_text.text(f"Downloading {file_info['filename']}... ({i+1}/{len(selected_files)})")
666
  progress_bar.progress(progress)
667
- # In DownloadManager.download_file(), consider adding a fallback to requests if needed.
668
  path = await dm.download_file(file_info, download_dir, url)
669
  if path:
670
  downloaded_paths.append(path)
@@ -676,9 +676,14 @@ def main():
676
 
677
  if downloaded:
678
  st.success(f"Successfully downloaded {len(downloaded)} files")
679
- if create_zip or upload_to_drive:
 
680
  zip_path = create_zip_file(downloaded, download_dir)
681
  st.success(f"Created ZIP file: {zip_path}")
 
 
 
 
682
  if upload_to_drive and st.session_state.get('google_creds'):
683
  with st.spinner("Uploading to Google Drive..."):
684
  drive_id = google_drive_upload(zip_path, st.session_state.google_creds)
@@ -693,10 +698,16 @@ def main():
693
  except Exception as e:
694
  st.warning(f"Could not delete {path}: {e}")
695
  st.info("Deleted original files after ZIP creation")
 
 
 
 
 
 
696
  else:
697
  st.warning("No files found.")
698
 
699
- # File selection block 2 (if files have already been discovered)
700
  if st.session_state.discovered_files:
701
  files = st.session_state.discovered_files
702
  st.success(f"Found {len(files)} files!")
@@ -749,9 +760,12 @@ def main():
749
  downloaded = asyncio.run(download_files())
750
  if downloaded:
751
  st.success(f"Successfully downloaded {len(downloaded)} files")
752
- if create_zip or upload_to_drive:
753
  zip_path = create_zip_file(downloaded, download_dir)
754
  st.success(f"Created ZIP file: {zip_path}")
 
 
 
755
  if upload_to_drive and st.session_state.get('google_creds'):
756
  with st.spinner("Uploading to Google Drive..."):
757
  drive_id = google_drive_upload(zip_path, st.session_state.google_creds)
@@ -766,6 +780,11 @@ def main():
766
  except Exception as e:
767
  st.warning(f"Could not delete {path}: {e}")
768
  st.info("Deleted original files after ZIP creation")
 
 
 
 
 
769
 
770
  elif mode == "Bing Search":
771
  st.header("Bing Search Mode")
@@ -785,7 +804,7 @@ def main():
785
  if urls:
786
  st.success(f"Found {len(urls)} results!")
787
  for i, url in enumerate(urls, 1):
788
- with st.expander(f"Result {i}: {url}", expanded=i == 1):
789
  if st.button(f"Deep Search Result {i}", key=f"deep_search_result_{i}"):
790
  files = await dm.deep_search(
791
  url=url,
 
615
 
616
  files = asyncio.run(run_deep_search())
617
  if files:
618
+ # Save all discovered fileseven duplicates
619
  st.session_state.discovered_files = files
620
  st.session_state.current_url = url
621
  st.success(f"Found {len(files)} files!")
622
 
623
+ # File selection block (Select/Clear)
624
  col1, col2 = st.columns([1, 4])
625
  with col1:
626
  if st.button("Select All", key="select_all_btn"):
 
664
  file_info = files[idx]
665
  status_text.text(f"Downloading {file_info['filename']}... ({i+1}/{len(selected_files)})")
666
  progress_bar.progress(progress)
667
+ # Download the file (ensure DownloadManager.download_file downloads duplicates)
668
  path = await dm.download_file(file_info, download_dir, url)
669
  if path:
670
  downloaded_paths.append(path)
 
676
 
677
  if downloaded:
678
  st.success(f"Successfully downloaded {len(downloaded)} files")
679
+ # If the user chose to create a ZIP, generate it and offer a download button
680
+ if create_zip:
681
  zip_path = create_zip_file(downloaded, download_dir)
682
  st.success(f"Created ZIP file: {zip_path}")
683
+ with open(zip_path, "rb") as f:
684
+ zip_data = f.read()
685
+ st.download_button("Download ZIP", data=zip_data, file_name=os.path.basename(zip_path), mime="application/zip")
686
+
687
  if upload_to_drive and st.session_state.get('google_creds'):
688
  with st.spinner("Uploading to Google Drive..."):
689
  drive_id = google_drive_upload(zip_path, st.session_state.google_creds)
 
698
  except Exception as e:
699
  st.warning(f"Could not delete {path}: {e}")
700
  st.info("Deleted original files after ZIP creation")
701
+ else:
702
+ # Otherwise, generate an individual download button for each file
703
+ for path in downloaded:
704
+ with open(path, "rb") as f:
705
+ file_data = f.read()
706
+ st.download_button(f"Download {os.path.basename(path)}", data=file_data, file_name=os.path.basename(path))
707
  else:
708
  st.warning("No files found.")
709
 
710
+ # If files were discovered in a previous search, show them here as well.
711
  if st.session_state.discovered_files:
712
  files = st.session_state.discovered_files
713
  st.success(f"Found {len(files)} files!")
 
760
  downloaded = asyncio.run(download_files())
761
  if downloaded:
762
  st.success(f"Successfully downloaded {len(downloaded)} files")
763
+ if create_zip:
764
  zip_path = create_zip_file(downloaded, download_dir)
765
  st.success(f"Created ZIP file: {zip_path}")
766
+ with open(zip_path, "rb") as f:
767
+ zip_data = f.read()
768
+ st.download_button("Download ZIP", data=zip_data, file_name=os.path.basename(zip_path), mime="application/zip")
769
  if upload_to_drive and st.session_state.get('google_creds'):
770
  with st.spinner("Uploading to Google Drive..."):
771
  drive_id = google_drive_upload(zip_path, st.session_state.google_creds)
 
780
  except Exception as e:
781
  st.warning(f"Could not delete {path}: {e}")
782
  st.info("Deleted original files after ZIP creation")
783
+ else:
784
+ for path in downloaded:
785
+ with open(path, "rb") as f:
786
+ file_data = f.read()
787
+ st.download_button(f"Download {os.path.basename(path)}", data=file_data, file_name=os.path.basename(path))
788
 
789
  elif mode == "Bing Search":
790
  st.header("Bing Search Mode")
 
804
  if urls:
805
  st.success(f"Found {len(urls)} results!")
806
  for i, url in enumerate(urls, 1):
807
+ with st.expander(f"Result {i}: {url}", expanded=(i == 1)):
808
  if st.button(f"Deep Search Result {i}", key=f"deep_search_result_{i}"):
809
  files = await dm.deep_search(
810
  url=url,