awacke1 commited on
Commit
9e10f5c
·
verified ·
1 Parent(s): 03b9d85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -2
app.py CHANGED
@@ -274,6 +274,15 @@ def search_arxiv(query):
274
  st.write(f"Elapsed time: {elapsed_seconds:.2f} seconds")
275
  filename = generate_filename(query, "md")
276
  create_file(filename, query, results, should_save)
 
 
 
 
 
 
 
 
 
277
  return results
278
 
279
  def download_pdfs_and_generate_html(urls):
@@ -614,6 +623,17 @@ def FileSidebar():
614
  elif st.session_state.action == 'edit':
615
  edit_file(st.session_state.current_file)
616
 
 
 
 
 
 
 
 
 
 
 
 
617
  def view_file(file):
618
  st.header(f"Viewing: {file}")
619
  file_extension = os.path.splitext(file)[1].lower()
@@ -634,7 +654,12 @@ def edit_file(file):
634
  file_extension = os.path.splitext(file)[1].lower()
635
  try:
636
  if file_extension == '.pdf':
637
- st.warning("PDF files cannot be edited directly. Please download and edit locally.")
 
 
 
 
 
638
  elif file_extension == '.html':
639
  with open(file, 'r', encoding='utf-8') as f:
640
  content = f.read()
@@ -651,7 +676,18 @@ def edit_file(file):
651
  st.success(f"File updated successfully! New file: {new_file_path}")
652
  except Exception as e:
653
  st.error(f"Error editing {file}: {str(e)}")
654
-
 
 
 
 
 
 
 
 
 
 
 
655
  def display_pdf(file_path):
656
  try:
657
  with open(file_path, "rb") as f:
 
274
  st.write(f"Elapsed time: {elapsed_seconds:.2f} seconds")
275
  filename = generate_filename(query, "md")
276
  create_file(filename, query, results, should_save)
277
+
278
+
279
+ # After search completes and generates results
280
+ result = "Your search results in Markdown format" # Replace with actual results
281
+
282
+ # Call the function to redraw sidebar and show results
283
+ redraw_sidebar_after_search(result)
284
+
285
+
286
  return results
287
 
288
  def download_pdfs_and_generate_html(urls):
 
623
  elif st.session_state.action == 'edit':
624
  edit_file(st.session_state.current_file)
625
 
626
+ # Show the result MD from the search
627
+ if 'search_result' in st.session_state:
628
+ st.markdown("## Search Result")
629
+ st.markdown(st.session_state.search_result)
630
+
631
+ # Function to be called after search completes
632
+ def redraw_sidebar_after_search(search_result):
633
+ st.session_state.search_result = search_result
634
+ st.rerun()
635
+
636
+
637
  def view_file(file):
638
  st.header(f"Viewing: {file}")
639
  file_extension = os.path.splitext(file)[1].lower()
 
654
  file_extension = os.path.splitext(file)[1].lower()
655
  try:
656
  if file_extension == '.pdf':
657
+ md_content = pdf_to_markdown(file)
658
+ md_file = file.replace('.pdf', '.md')
659
+ new_content = st.text_area("Edit PDF content (as Markdown)", md_content, height=400)
660
+ if st.button("Save as Markdown"):
661
+ new_file_path = update_file_with_timestamp(md_file, new_content)
662
+ st.success(f"File saved as Markdown! New file: {new_file_path}")
663
  elif file_extension == '.html':
664
  with open(file, 'r', encoding='utf-8') as f:
665
  content = f.read()
 
676
  st.success(f"File updated successfully! New file: {new_file_path}")
677
  except Exception as e:
678
  st.error(f"Error editing {file}: {str(e)}")
679
+
680
+ def pdf_to_markdown(file_path):
681
+ try:
682
+ with open(file_path, "rb") as f:
683
+ pdf_reader = PyPDF2.PdfReader(f)
684
+ markdown_content = ""
685
+ for page in pdf_reader.pages:
686
+ markdown_content += page.extract_text() + "\n\n"
687
+ return markdown_content
688
+ except Exception as e:
689
+ st.error(f"Error converting PDF to Markdown: {str(e)}")
690
+ return ""
691
  def display_pdf(file_path):
692
  try:
693
  with open(file_path, "rb") as f: