siddhartharya commited on
Commit
7fcb8db
·
verified ·
1 Parent(s): c425950

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -469,23 +469,23 @@ def process_uploaded_file(file, state_bookmarks):
469
 
470
  if file is None:
471
  logger.warning("No file uploaded")
472
- return "Please upload a bookmarks HTML file.", '', state_bookmarks, display_bookmarks()
473
 
474
  try:
475
  file_content = file.decode('utf-8')
476
  except UnicodeDecodeError as e:
477
  logger.error(f"Error decoding the file: {e}", exc_info=True)
478
- return "Error decoding the file. Please ensure it's a valid HTML file.", '', state_bookmarks, display_bookmarks()
479
 
480
  try:
481
  bookmarks = parse_bookmarks(file_content)
482
  except Exception as e:
483
  logger.error(f"Error parsing bookmarks: {e}", exc_info=True)
484
- return "Error parsing the bookmarks HTML file.", '', state_bookmarks, display_bookmarks()
485
 
486
  if not bookmarks:
487
  logger.warning("No bookmarks found in the uploaded file")
488
- return "No bookmarks found in the uploaded file.", '', state_bookmarks, display_bookmarks()
489
 
490
  # Assign unique IDs to bookmarks
491
  for idx, bookmark in enumerate(bookmarks):
@@ -505,7 +505,7 @@ def process_uploaded_file(file, state_bookmarks):
505
  faiss_index = vectorize_and_index(bookmarks)
506
  except Exception as e:
507
  logger.error(f"Error building FAISS index: {e}", exc_info=True)
508
- return "Error building search index.", '', state_bookmarks, display_bookmarks()
509
 
510
  message = f"✅ Successfully processed {len(bookmarks)} bookmarks."
511
  logger.info(message)
@@ -518,7 +518,7 @@ def process_uploaded_file(file, state_bookmarks):
518
  # Update state
519
  state_bookmarks = bookmarks.copy()
520
 
521
- return message, bookmark_html, state_bookmarks, bookmark_html
522
 
523
  def delete_selected_bookmarks(selected_indices, state_bookmarks):
524
  """
@@ -625,6 +625,9 @@ def chatbot_response(user_query, chat_history):
625
  logger.info(f"Chatbot received query: {user_query}")
626
 
627
  try:
 
 
 
628
  # Rate Limiting Logic
629
  with api_lock:
630
  global last_api_call_time
@@ -694,7 +697,7 @@ Provide a concise and helpful response.
694
  logger.info("Chatbot response generated")
695
  time.sleep(sleep_time)
696
 
697
- # Append the interaction to chat history
698
  chat_history.append({"role": "assistant", "content": answer})
699
  return chat_history
700
 
@@ -765,7 +768,7 @@ Navigate through the tabs to explore each feature in detail.
765
  process_button.click(
766
  process_uploaded_file,
767
  inputs=[upload, state_bookmarks],
768
- outputs=[output_text, bookmark_display, state_bookmarks, bookmark_display]
769
  )
770
 
771
  # Chat with Bookmarks Tab
 
469
 
470
  if file is None:
471
  logger.warning("No file uploaded")
472
+ return "Please upload a bookmarks HTML file.", '', state_bookmarks, display_bookmarks(), gr.update(choices=[])
473
 
474
  try:
475
  file_content = file.decode('utf-8')
476
  except UnicodeDecodeError as e:
477
  logger.error(f"Error decoding the file: {e}", exc_info=True)
478
+ return "Error decoding the file. Please ensure it's a valid HTML file.", '', state_bookmarks, display_bookmarks(), gr.update(choices=[])
479
 
480
  try:
481
  bookmarks = parse_bookmarks(file_content)
482
  except Exception as e:
483
  logger.error(f"Error parsing bookmarks: {e}", exc_info=True)
484
+ return "Error parsing the bookmarks HTML file.", '', state_bookmarks, display_bookmarks(), gr.update(choices=[])
485
 
486
  if not bookmarks:
487
  logger.warning("No bookmarks found in the uploaded file")
488
+ return "No bookmarks found in the uploaded file.", '', state_bookmarks, display_bookmarks(), gr.update(choices=[])
489
 
490
  # Assign unique IDs to bookmarks
491
  for idx, bookmark in enumerate(bookmarks):
 
505
  faiss_index = vectorize_and_index(bookmarks)
506
  except Exception as e:
507
  logger.error(f"Error building FAISS index: {e}", exc_info=True)
508
+ return "Error building search index.", '', state_bookmarks, display_bookmarks(), gr.update(choices=[])
509
 
510
  message = f"✅ Successfully processed {len(bookmarks)} bookmarks."
511
  logger.info(message)
 
518
  # Update state
519
  state_bookmarks = bookmarks.copy()
520
 
521
+ return message, bookmark_html, state_bookmarks, bookmark_html, gr.update(choices=choices)
522
 
523
  def delete_selected_bookmarks(selected_indices, state_bookmarks):
524
  """
 
625
  logger.info(f"Chatbot received query: {user_query}")
626
 
627
  try:
628
+ # Append user's message to chat history
629
+ chat_history.append({"role": "user", "content": user_query})
630
+
631
  # Rate Limiting Logic
632
  with api_lock:
633
  global last_api_call_time
 
697
  logger.info("Chatbot response generated")
698
  time.sleep(sleep_time)
699
 
700
+ # Append the assistant's response to chat history
701
  chat_history.append({"role": "assistant", "content": answer})
702
  return chat_history
703
 
 
768
  process_button.click(
769
  process_uploaded_file,
770
  inputs=[upload, state_bookmarks],
771
+ outputs=[output_text, bookmark_display, state_bookmarks, bookmark_display, gr.update()]
772
  )
773
 
774
  # Chat with Bookmarks Tab