Spaces:
Running
Running
Update app.py
Browse files
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
522 |
|
523 |
def delete_selected_bookmarks(selected_indices, state_bookmarks):
|
524 |
"""
|
@@ -581,7 +581,7 @@ def edit_selected_bookmarks_category(selected_indices, new_category, state_bookm
|
|
581 |
# Update state
|
582 |
state_bookmarks = bookmarks.copy()
|
583 |
|
584 |
-
return message, gr.update(choices=choices), display_bookmarks(), state_bookmarks
|
585 |
|
586 |
def export_bookmarks():
|
587 |
"""
|
@@ -722,6 +722,12 @@ def build_app():
|
|
722 |
# Initialize state
|
723 |
state_bookmarks = gr.State([])
|
724 |
|
|
|
|
|
|
|
|
|
|
|
|
|
725 |
# General Overview
|
726 |
gr.Markdown("""
|
727 |
# π SmartMarks - AI Browser Bookmarks Manager
|
@@ -767,7 +773,7 @@ Navigate through the tabs to explore each feature in detail.
|
|
767 |
process_button.click(
|
768 |
process_uploaded_file,
|
769 |
inputs=[upload, state_bookmarks],
|
770 |
-
outputs=[output_text, bookmark_display, state_bookmarks, bookmark_display,
|
771 |
)
|
772 |
|
773 |
with gr.Tab("Chat with Bookmarks"):
|
@@ -837,11 +843,8 @@ Navigate through the tabs to explore each feature in detail.
|
|
837 |
bookmark_display_manage = gr.HTML(label="π Bookmarks")
|
838 |
|
839 |
with gr.Row():
|
840 |
-
#
|
841 |
-
bookmark_selector
|
842 |
-
label="β
Select Bookmarks",
|
843 |
-
choices=[]
|
844 |
-
)
|
845 |
|
846 |
with gr.Row():
|
847 |
delete_button = gr.Button("ποΈ Delete Selected")
|
|
|
469 |
|
470 |
if file is None:
|
471 |
logger.warning("No file uploaded")
|
472 |
+
return "Please upload a bookmarks HTML file.", '', state_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, 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, 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, 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, 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, gr.update(choices=choices)
|
522 |
|
523 |
def delete_selected_bookmarks(selected_indices, state_bookmarks):
|
524 |
"""
|
|
|
581 |
# Update state
|
582 |
state_bookmarks = bookmarks.copy()
|
583 |
|
584 |
+
return message, gr.update(choices=choices), display_bookmarks(), state_bookmarks()
|
585 |
|
586 |
def export_bookmarks():
|
587 |
"""
|
|
|
722 |
# Initialize state
|
723 |
state_bookmarks = gr.State([])
|
724 |
|
725 |
+
# Define 'bookmark_selector' first
|
726 |
+
bookmark_selector = gr.CheckboxGroup(
|
727 |
+
label="β
Select Bookmarks",
|
728 |
+
choices=[]
|
729 |
+
)
|
730 |
+
|
731 |
# General Overview
|
732 |
gr.Markdown("""
|
733 |
# π SmartMarks - AI Browser Bookmarks Manager
|
|
|
773 |
process_button.click(
|
774 |
process_uploaded_file,
|
775 |
inputs=[upload, state_bookmarks],
|
776 |
+
outputs=[output_text, bookmark_display, state_bookmarks, bookmark_display, bookmark_selector]
|
777 |
)
|
778 |
|
779 |
with gr.Tab("Chat with Bookmarks"):
|
|
|
843 |
bookmark_display_manage = gr.HTML(label="π Bookmarks")
|
844 |
|
845 |
with gr.Row():
|
846 |
+
# Render 'bookmark_selector' inside the tab
|
847 |
+
bookmark_selector.render()
|
|
|
|
|
|
|
848 |
|
849 |
with gr.Row():
|
850 |
delete_button = gr.Button("ποΈ Delete Selected")
|