Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -266,6 +266,25 @@ def display_bookmarks(bookmarks_list):
|
|
266 |
logger.info("HTML display generated")
|
267 |
return cards
|
268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
# Process the uploaded file
|
270 |
def process_uploaded_file(file, state_bookmarks):
|
271 |
logger.info("Processing uploaded file")
|
@@ -451,46 +470,47 @@ def build_app():
|
|
451 |
try:
|
452 |
logger.info("Building Gradio app")
|
453 |
with gr.Blocks(theme=gr.themes.Default(), css="app.css") as demo:
|
454 |
-
# Shared
|
455 |
state_bookmarks = gr.State([])
|
|
|
456 |
|
457 |
# General Overview
|
458 |
gr.Markdown("""
|
459 |
-
|
460 |
|
461 |
-
|
462 |
|
463 |
-
|
464 |
|
465 |
-
|
466 |
|
467 |
-
|
468 |
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
|
473 |
-
|
474 |
-
|
475 |
|
476 |
# Upload and Process Bookmarks Tab
|
477 |
with gr.Tab("Upload and Process Bookmarks"):
|
478 |
gr.Markdown("""
|
479 |
-
|
480 |
|
481 |
-
|
482 |
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
|
495 |
upload = gr.File(label="π Upload Bookmarks HTML File", type='binary')
|
496 |
process_button = gr.Button("βοΈ Process Bookmarks")
|
@@ -506,55 +526,72 @@ def build_app():
|
|
506 |
# Chat with Bookmarks Tab
|
507 |
with gr.Tab("Chat with Bookmarks"):
|
508 |
gr.Markdown("""
|
509 |
-
|
510 |
|
511 |
-
|
512 |
|
513 |
-
|
514 |
-
|
515 |
|
516 |
-
|
517 |
-
|
518 |
|
519 |
-
|
520 |
-
|
521 |
-
""")
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
526 |
|
|
|
527 |
chat_button.click(
|
528 |
-
|
529 |
-
inputs=[
|
530 |
-
outputs=
|
531 |
)
|
532 |
|
533 |
# Manage Bookmarks Tab
|
534 |
with gr.Tab("Manage Bookmarks"):
|
535 |
gr.Markdown("""
|
536 |
-
|
537 |
|
538 |
-
|
539 |
|
540 |
-
|
541 |
-
|
542 |
|
543 |
-
|
544 |
-
|
545 |
|
546 |
-
|
547 |
-
|
548 |
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
|
559 |
manage_output = gr.Textbox(label="π Manage Output", interactive=False)
|
560 |
bookmark_selector = gr.CheckboxGroup(label="β
Select Bookmarks", choices=[])
|
@@ -577,7 +614,8 @@ def build_app():
|
|
577 |
else:
|
578 |
return [], ""
|
579 |
|
580 |
-
|
|
|
581 |
refresh_manage_tab,
|
582 |
inputs=[state_bookmarks],
|
583 |
outputs=[bookmark_selector, bookmark_display_manage]
|
@@ -602,8 +640,14 @@ def build_app():
|
|
602 |
outputs=download_link
|
603 |
)
|
604 |
|
605 |
-
|
606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
607 |
except Exception as e:
|
608 |
logger.error(f"Error building the app: {e}")
|
609 |
print(f"Error building the app: {e}")
|
|
|
266 |
logger.info("HTML display generated")
|
267 |
return cards
|
268 |
|
269 |
+
# Function to handle sending messages in chat
|
270 |
+
def send_message(user_message, chat_history, state_bookmarks):
|
271 |
+
if not user_message:
|
272 |
+
return chat_history, chat_history
|
273 |
+
|
274 |
+
# Append user message to chat history
|
275 |
+
chat_history = chat_history + [(user_message, None)]
|
276 |
+
|
277 |
+
# Generate chatbot response
|
278 |
+
try:
|
279 |
+
response = chatbot_response(user_message, state_bookmarks)
|
280 |
+
except Exception as e:
|
281 |
+
response = f"β οΈ Error: {str(e)}"
|
282 |
+
|
283 |
+
# Append assistant response to chat history
|
284 |
+
chat_history[-1] = (user_message, response)
|
285 |
+
|
286 |
+
return chat_history, chat_history
|
287 |
+
|
288 |
# Process the uploaded file
|
289 |
def process_uploaded_file(file, state_bookmarks):
|
290 |
logger.info("Processing uploaded file")
|
|
|
470 |
try:
|
471 |
logger.info("Building Gradio app")
|
472 |
with gr.Blocks(theme=gr.themes.Default(), css="app.css") as demo:
|
473 |
+
# Shared states
|
474 |
state_bookmarks = gr.State([])
|
475 |
+
chat_history = gr.State([])
|
476 |
|
477 |
# General Overview
|
478 |
gr.Markdown("""
|
479 |
+
# π SmartMarks - AI Browser Bookmarks Manager
|
480 |
|
481 |
+
Welcome to **SmartMarks**, your intelligent assistant for managing browser bookmarks. SmartMarks leverages AI to help you organize, search, and interact with your bookmarks seamlessly. Whether you're looking to categorize your links, retrieve information quickly, or maintain an updated list, SmartMarks has you covered.
|
482 |
|
483 |
+
---
|
484 |
|
485 |
+
## π **How to Use SmartMarks**
|
486 |
|
487 |
+
SmartMarks is divided into three main sections:
|
488 |
|
489 |
+
1. **π Upload and Process Bookmarks:** Import your existing bookmarks and let SmartMarks analyze and categorize them for you.
|
490 |
+
2. **π¬ Chat with Bookmarks:** Interact with your bookmarks using natural language queries to find relevant links effortlessly.
|
491 |
+
3. **π οΈ Manage Bookmarks:** View, edit, delete, and export your bookmarks with ease.
|
492 |
|
493 |
+
Navigate through the tabs to explore each feature in detail.
|
494 |
+
""")
|
495 |
|
496 |
# Upload and Process Bookmarks Tab
|
497 |
with gr.Tab("Upload and Process Bookmarks"):
|
498 |
gr.Markdown("""
|
499 |
+
## π **Upload and Process Bookmarks**
|
500 |
|
501 |
+
### π **Steps to Upload and Process:**
|
502 |
|
503 |
+
1. **π½ Upload Bookmarks File:**
|
504 |
+
- Click on the **"π Upload Bookmarks HTML File"** button.
|
505 |
+
- Select your browser's exported bookmarks HTML file from your device.
|
506 |
|
507 |
+
2. **βοΈ Process Bookmarks:**
|
508 |
+
- After uploading, click on the **"βοΈ Process Bookmarks"** button.
|
509 |
+
- SmartMarks will parse your bookmarks, fetch additional information, generate summaries, and categorize each link based on predefined categories.
|
510 |
|
511 |
+
3. **π View Processed Bookmarks:**
|
512 |
+
- Once processing is complete, your bookmarks will be displayed in an organized and visually appealing format below.
|
513 |
+
""")
|
514 |
|
515 |
upload = gr.File(label="π Upload Bookmarks HTML File", type='binary')
|
516 |
process_button = gr.Button("βοΈ Process Bookmarks")
|
|
|
526 |
# Chat with Bookmarks Tab
|
527 |
with gr.Tab("Chat with Bookmarks"):
|
528 |
gr.Markdown("""
|
529 |
+
## π¬ **Chat with Bookmarks**
|
530 |
|
531 |
+
### π€ **How to Interact:**
|
532 |
|
533 |
+
1. **βοΈ Enter Your Query:**
|
534 |
+
- In the **"βοΈ Ask about your bookmarks"** textbox, type your question or keyword related to your bookmarks. For example, "Do I have any bookmarks about GenerativeAI?"
|
535 |
|
536 |
+
2. **π¨ Submit Your Query:**
|
537 |
+
- You can either press the **"π¨ Send"** button or simply press the **Enter** key to submit your query.
|
538 |
|
539 |
+
3. **π Receive AI-Driven Responses:**
|
540 |
+
- SmartMarks will analyze your query and provide relevant bookmarks that match your request, making it easier to find specific links without manual searching.
|
|
|
541 |
|
542 |
+
4. **ποΈ View Chat History:**
|
543 |
+
- All your queries and the corresponding AI responses are displayed in the chat history for your reference.
|
544 |
+
""")
|
545 |
+
|
546 |
+
with gr.Row():
|
547 |
+
chat_history_display = gr.Chatbot(label="π¨οΈ Chat History")
|
548 |
+
chat_input = gr.Textbox(
|
549 |
+
label="βοΈ Ask about your bookmarks",
|
550 |
+
placeholder="e.g., Do I have any bookmarks about GenerativeAI?",
|
551 |
+
lines=1,
|
552 |
+
interactive=True
|
553 |
+
)
|
554 |
+
chat_button = gr.Button("π¨ Send")
|
555 |
+
|
556 |
+
# When user presses Enter in chat_input
|
557 |
+
chat_input.submit(
|
558 |
+
send_message,
|
559 |
+
inputs=[chat_input, chat_history, state_bookmarks],
|
560 |
+
outputs=[chat_history_display, chat_history_display]
|
561 |
+
)
|
562 |
|
563 |
+
# When user clicks Send button
|
564 |
chat_button.click(
|
565 |
+
send_message,
|
566 |
+
inputs=[chat_input, chat_history, state_bookmarks],
|
567 |
+
outputs=[chat_history_display, chat_history_display]
|
568 |
)
|
569 |
|
570 |
# Manage Bookmarks Tab
|
571 |
with gr.Tab("Manage Bookmarks"):
|
572 |
gr.Markdown("""
|
573 |
+
## π οΈ **Manage Bookmarks**
|
574 |
|
575 |
+
### ποΈ **Features:**
|
576 |
|
577 |
+
1. **ποΈ View Bookmarks:**
|
578 |
+
- All your processed bookmarks are displayed here with their respective categories and summaries.
|
579 |
|
580 |
+
2. **β
Select Bookmarks:**
|
581 |
+
- Use the checkboxes next to each bookmark to select one, multiple, or all bookmarks you wish to manage.
|
582 |
|
583 |
+
3. **ποΈ Delete Selected Bookmarks:**
|
584 |
+
- After selecting the desired bookmarks, click the **"ποΈ Delete Selected Bookmarks"** button to remove them from your list.
|
585 |
|
586 |
+
4. **βοΈ Edit Categories:**
|
587 |
+
- Select the bookmarks you want to re-categorize.
|
588 |
+
- Choose a new category from the dropdown menu labeled **"π New Category"**.
|
589 |
+
- Click the **"βοΈ Edit Category of Selected Bookmarks"** button to update their categories.
|
590 |
|
591 |
+
5. **πΎ Export Bookmarks:**
|
592 |
+
- Click the **"πΎ Export Bookmarks"** button to download your updated bookmarks as an HTML file.
|
593 |
+
- This file can be uploaded back to your browser to reflect the changes made within SmartMarks.
|
594 |
+
""")
|
595 |
|
596 |
manage_output = gr.Textbox(label="π Manage Output", interactive=False)
|
597 |
bookmark_selector = gr.CheckboxGroup(label="β
Select Bookmarks", choices=[])
|
|
|
614 |
else:
|
615 |
return [], ""
|
616 |
|
617 |
+
# Link process_uploaded_file to update Manage Bookmarks Tab
|
618 |
+
process_button.click(
|
619 |
refresh_manage_tab,
|
620 |
inputs=[state_bookmarks],
|
621 |
outputs=[bookmark_selector, bookmark_display_manage]
|
|
|
640 |
outputs=download_link
|
641 |
)
|
642 |
|
643 |
+
refresh_button.click(
|
644 |
+
refresh_manage_tab,
|
645 |
+
inputs=[state_bookmarks],
|
646 |
+
outputs=[bookmark_selector, bookmark_display_manage]
|
647 |
+
)
|
648 |
+
|
649 |
+
logger.info("Launching Gradio app")
|
650 |
+
demo.launch(debug=True)
|
651 |
except Exception as e:
|
652 |
logger.error(f"Error building the app: {e}")
|
653 |
print(f"Error building the app: {e}")
|