euler314 commited on
Commit
39a7a36
·
verified ·
1 Parent(s): 92f91e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -37
app.py CHANGED
@@ -604,13 +604,14 @@ def main():
604
  st.title("Advanced File Downloader")
605
 
606
  # Mode Selection
607
- mode = st.radio("Select Mode", ["Manual URL", "Bing Search", "PDF Summarizer"])
608
 
609
  # Advanced Options
610
  with st.expander("Advanced Options"):
611
  custom_extensions = st.text_input(
612
  "Custom File Extensions",
613
- placeholder=".csv, .txt, .epub"
 
614
  )
615
  max_sublinks = st.number_input(
616
  "Maximum Sublinks to Process",
@@ -618,7 +619,8 @@ def main():
618
  max_value=10000,
619
  value=100,
620
  step=50,
621
- help="Maximum number of sublinks to process from the main page"
 
622
  )
623
  sublink_timeout = st.number_input(
624
  "Search Timeout (seconds per sublink)",
@@ -626,37 +628,37 @@ def main():
626
  max_value=3000,
627
  value=30,
628
  step=5,
629
- help="Maximum time to spend searching each sublink"
 
630
  )
631
- use_proxy = st.checkbox("Use Proxy")
632
- proxy = st.text_input("Proxy URL", placeholder="http://proxy:port")
633
 
634
  # Google Drive Integration
635
  with st.expander("Google Drive Integration"):
636
- if st.button("Start Google Sign-In"):
637
  auth_url = get_google_auth_url()
638
  st.markdown(f"[Click here to authorize]({auth_url})")
639
 
640
- auth_code = st.text_input("Enter authorization code")
641
- if st.button("Complete Sign-In") and auth_code:
642
  creds, msg = exchange_code_for_credentials(auth_code)
643
  st.session_state.google_creds = creds
644
  st.write(msg)
645
 
646
- url = st.text_input("Enter URL", placeholder="https://example.com")
647
-
648
  if mode == "Manual URL":
649
  st.header("Manual URL Mode")
650
- url = st.text_input("Enter URL", placeholder="https://example.com")
651
 
652
- if st.button("Deep Search", use_container_width=True):
653
  if url:
654
  async def run_deep_search():
655
  async with DownloadManager(use_proxy=use_proxy, proxy=proxy) as dm:
656
  files = await dm.deep_search(
657
  url=url,
658
  custom_ext_list=custom_extensions.split(',') if custom_extensions else [],
659
- sublink_limit=max_sublinks
 
660
  )
661
  if files:
662
  st.session_state.discovered_files = files
@@ -670,10 +672,10 @@ def main():
670
  # Select All/Clear Selection buttons
671
  col1, col2 = st.columns([1, 4])
672
  with col1:
673
- if st.button("Select All"):
674
  st.session_state.selected_files = list(range(len(files)))
675
  st.experimental_rerun()
676
- if st.button("Clear Selection"):
677
  st.session_state.selected_files = []
678
  st.experimental_rerun()
679
 
@@ -682,7 +684,8 @@ def main():
682
  "Select files to download",
683
  options=list(range(len(files))),
684
  default=st.session_state.selected_files,
685
- format_func=lambda x: f"{files[x]['filename']} ({files[x]['size']})"
 
686
  )
687
 
688
  # Update session state
@@ -691,15 +694,15 @@ def main():
691
  if selected_files:
692
  col1, col2, col3, col4 = st.columns(4)
693
  with col1:
694
- download_dir = st.text_input("Download Directory", value="./downloads")
695
  with col2:
696
- create_zip = st.checkbox("Create ZIP file", value=True)
697
  with col3:
698
- delete_after = st.checkbox("Delete after creating ZIP")
699
  with col4:
700
- upload_to_drive = st.checkbox("Upload to Google Drive")
701
 
702
- if st.button("Download Selected"):
703
  if not os.path.exists(download_dir):
704
  os.makedirs(download_dir)
705
 
@@ -763,10 +766,10 @@ def main():
763
  # Select All/Clear Selection buttons
764
  col1, col2 = st.columns([1, 4])
765
  with col1:
766
- if st.button("Select All"):
767
  st.session_state.selected_files = list(range(len(files)))
768
  st.experimental_rerun()
769
- if st.button("Clear Selection"):
770
  st.session_state.selected_files = []
771
  st.experimental_rerun()
772
 
@@ -775,7 +778,8 @@ def main():
775
  "Select files to download",
776
  options=list(range(len(files))),
777
  default=st.session_state.selected_files,
778
- format_func=lambda x: f"{files[x]['filename']} ({files[x]['size']})"
 
779
  )
780
 
781
  # Update session state
@@ -784,15 +788,15 @@ def main():
784
  if selected_files:
785
  col1, col2, col3, col4 = st.columns(4)
786
  with col1:
787
- download_dir = st.text_input("Download Directory", value="./downloads")
788
  with col2:
789
- create_zip = st.checkbox("Create ZIP file", value=True)
790
  with col3:
791
- delete_after = st.checkbox("Delete after creating ZIP")
792
  with col4:
793
- upload_to_drive = st.checkbox("Upload to Google Drive")
794
 
795
- if st.button("Download Selected"):
796
  if not os.path.exists(download_dir):
797
  os.makedirs(download_dir)
798
 
@@ -848,10 +852,10 @@ def main():
848
 
849
  elif mode == "Bing Search":
850
  st.header("Bing Search Mode")
851
- query = st.text_input("Enter search query")
852
- num_results = st.slider("Number of results", 1, 50, 5)
853
 
854
- if st.button("Search"):
855
  if query:
856
  async def run_search():
857
  async with DownloadManager(
@@ -866,11 +870,12 @@ def main():
866
  st.success(f"Found {len(urls)} results!")
867
  for i, url in enumerate(urls, 1):
868
  with st.expander(f"Result {i}: {url}", expanded=i==1):
869
- if st.button(f"Deep Search Result {i}"):
870
  files = await dm.deep_search(
871
  url=url,
872
  custom_ext_list=custom_extensions.split(',') if custom_extensions else [],
873
- sublink_limit=max_sublinks
 
874
  )
875
  if files:
876
  st.session_state.discovered_files = files
@@ -889,9 +894,9 @@ def main():
889
  st.error("PDF summarization is not available due to model loading errors.")
890
  else:
891
  st.header("PDF Summarizer")
892
- pdf_url = st.text_input("Enter PDF URL")
893
 
894
- if st.button("Summarize"):
895
  if pdf_url:
896
  with st.spinner("Generating summary..."):
897
  try:
 
604
  st.title("Advanced File Downloader")
605
 
606
  # Mode Selection
607
+ mode = st.radio("Select Mode", ["Manual URL", "Bing Search", "PDF Summarizer"], key="mode_select")
608
 
609
  # Advanced Options
610
  with st.expander("Advanced Options"):
611
  custom_extensions = st.text_input(
612
  "Custom File Extensions",
613
+ placeholder=".csv, .txt, .epub",
614
+ key="custom_ext_input"
615
  )
616
  max_sublinks = st.number_input(
617
  "Maximum Sublinks to Process",
 
619
  max_value=10000,
620
  value=100,
621
  step=50,
622
+ help="Maximum number of sublinks to process from the main page",
623
+ key="max_sublinks_input"
624
  )
625
  sublink_timeout = st.number_input(
626
  "Search Timeout (seconds per sublink)",
 
628
  max_value=3000,
629
  value=30,
630
  step=5,
631
+ help="Maximum time to spend searching each sublink",
632
+ key="timeout_input"
633
  )
634
+ use_proxy = st.checkbox("Use Proxy", key="proxy_checkbox")
635
+ proxy = st.text_input("Proxy URL", placeholder="http://proxy:port", key="proxy_input")
636
 
637
  # Google Drive Integration
638
  with st.expander("Google Drive Integration"):
639
+ if st.button("Start Google Sign-In", key="google_signin_btn"):
640
  auth_url = get_google_auth_url()
641
  st.markdown(f"[Click here to authorize]({auth_url})")
642
 
643
+ auth_code = st.text_input("Enter authorization code", key="auth_code_input")
644
+ if st.button("Complete Sign-In", key="complete_signin_btn") and auth_code:
645
  creds, msg = exchange_code_for_credentials(auth_code)
646
  st.session_state.google_creds = creds
647
  st.write(msg)
648
 
 
 
649
  if mode == "Manual URL":
650
  st.header("Manual URL Mode")
651
+ url = st.text_input("Enter URL", placeholder="https://example.com", key="url_input")
652
 
653
+ if st.button("Deep Search", use_container_width=True, key="deep_search_btn"):
654
  if url:
655
  async def run_deep_search():
656
  async with DownloadManager(use_proxy=use_proxy, proxy=proxy) as dm:
657
  files = await dm.deep_search(
658
  url=url,
659
  custom_ext_list=custom_extensions.split(',') if custom_extensions else [],
660
+ sublink_limit=max_sublinks,
661
+ timeout=sublink_timeout
662
  )
663
  if files:
664
  st.session_state.discovered_files = files
 
672
  # Select All/Clear Selection buttons
673
  col1, col2 = st.columns([1, 4])
674
  with col1:
675
+ if st.button("Select All", key="select_all_btn"):
676
  st.session_state.selected_files = list(range(len(files)))
677
  st.experimental_rerun()
678
+ if st.button("Clear Selection", key="clear_selection_btn"):
679
  st.session_state.selected_files = []
680
  st.experimental_rerun()
681
 
 
684
  "Select files to download",
685
  options=list(range(len(files))),
686
  default=st.session_state.selected_files,
687
+ format_func=lambda x: f"{files[x]['filename']} ({files[x]['size']})",
688
+ key="file_multiselect"
689
  )
690
 
691
  # Update session state
 
694
  if selected_files:
695
  col1, col2, col3, col4 = st.columns(4)
696
  with col1:
697
+ download_dir = st.text_input("Download Directory", value="./downloads", key="download_dir_input")
698
  with col2:
699
+ create_zip = st.checkbox("Create ZIP file", value=True, key="create_zip_checkbox")
700
  with col3:
701
+ delete_after = st.checkbox("Delete after creating ZIP", key="delete_after_checkbox")
702
  with col4:
703
+ upload_to_drive = st.checkbox("Upload to Google Drive", key="upload_drive_checkbox")
704
 
705
+ if st.button("Download Selected", key="download_btn"):
706
  if not os.path.exists(download_dir):
707
  os.makedirs(download_dir)
708
 
 
766
  # Select All/Clear Selection buttons
767
  col1, col2 = st.columns([1, 4])
768
  with col1:
769
+ if st.button("Select All", key="select_all_btn2"):
770
  st.session_state.selected_files = list(range(len(files)))
771
  st.experimental_rerun()
772
+ if st.button("Clear Selection", key="clear_selection_btn2"):
773
  st.session_state.selected_files = []
774
  st.experimental_rerun()
775
 
 
778
  "Select files to download",
779
  options=list(range(len(files))),
780
  default=st.session_state.selected_files,
781
+ format_func=lambda x: f"{files[x]['filename']} ({files[x]['size']})",
782
+ key="file_multiselect2"
783
  )
784
 
785
  # Update session state
 
788
  if selected_files:
789
  col1, col2, col3, col4 = st.columns(4)
790
  with col1:
791
+ download_dir = st.text_input("Download Directory", value="./downloads", key="download_dir_input2")
792
  with col2:
793
+ create_zip = st.checkbox("Create ZIP file", value=True, key="create_zip_checkbox2")
794
  with col3:
795
+ delete_after = st.checkbox("Delete after creating ZIP", key="delete_after_checkbox2")
796
  with col4:
797
+ upload_to_drive = st.checkbox("Upload to Google Drive", key="upload_drive_checkbox2")
798
 
799
+ if st.button("Download Selected", key="download_btn2"):
800
  if not os.path.exists(download_dir):
801
  os.makedirs(download_dir)
802
 
 
852
 
853
  elif mode == "Bing Search":
854
  st.header("Bing Search Mode")
855
+ query = st.text_input("Enter search query", key="search_query_input")
856
+ num_results = st.slider("Number of results", 1, 50, 5, key="num_results_slider")
857
 
858
+ if st.button("Search", key="search_btn"):
859
  if query:
860
  async def run_search():
861
  async with DownloadManager(
 
870
  st.success(f"Found {len(urls)} results!")
871
  for i, url in enumerate(urls, 1):
872
  with st.expander(f"Result {i}: {url}", expanded=i==1):
873
+ if st.button(f"Deep Search Result {i}", key=f"deep_search_result_{i}"):
874
  files = await dm.deep_search(
875
  url=url,
876
  custom_ext_list=custom_extensions.split(',') if custom_extensions else [],
877
+ sublink_limit=max_sublinks,
878
+ timeout=sublink_timeout
879
  )
880
  if files:
881
  st.session_state.discovered_files = files
 
894
  st.error("PDF summarization is not available due to model loading errors.")
895
  else:
896
  st.header("PDF Summarizer")
897
+ pdf_url = st.text_input("Enter PDF URL", key="pdf_url_input")
898
 
899
+ if st.button("Summarize", key="summarize_btn"):
900
  if pdf_url:
901
  with st.spinner("Generating summary..."):
902
  try: