Spaces:
Sleeping
Sleeping
siddhartharya
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
# app.py
|
|
|
2 |
import gradio as gr
|
3 |
from bs4 import BeautifulSoup
|
4 |
import asyncio
|
@@ -246,19 +247,17 @@ def display_bookmarks(bookmarks_list):
|
|
246 |
# Assign CSS classes based on bookmark status
|
247 |
if bookmark.get('dead_link'):
|
248 |
card_classes = "card dead-link"
|
249 |
-
text_style = "color: #D32F2F;" # Red color for dead links
|
250 |
else:
|
251 |
card_classes = "card active-link"
|
252 |
-
text_style = "color: #000000;" # Black color for active links
|
253 |
|
254 |
card_html = f'''
|
255 |
-
<div class="{card_classes}"
|
256 |
<div class="card-content">
|
257 |
-
<h3
|
258 |
-
<p
|
259 |
-
<p
|
260 |
-
<p
|
261 |
-
<p
|
262 |
</div>
|
263 |
</div>
|
264 |
'''
|
@@ -401,7 +400,7 @@ def delete_selected_bookmarks(selected_indices, state_bookmarks):
|
|
401 |
# Update the shared state
|
402 |
updated_state = bookmarks.copy()
|
403 |
|
404 |
-
return message, gr.update(choices=choices), bookmarks_html
|
405 |
|
406 |
# Edit category of selected bookmarks
|
407 |
def edit_selected_bookmarks_category(selected_indices, new_category, state_bookmarks):
|
@@ -409,16 +408,14 @@ def edit_selected_bookmarks_category(selected_indices, new_category, state_bookm
|
|
409 |
return (
|
410 |
"β οΈ No bookmarks selected.",
|
411 |
gr.update(choices=[f"{i+1}. {bookmark['title']} (Category: {bookmark['category']})" for i, bookmark in enumerate(state_bookmarks)]),
|
412 |
-
display_bookmarks(state_bookmarks)
|
413 |
-
state_bookmarks
|
414 |
)
|
415 |
|
416 |
if not new_category:
|
417 |
return (
|
418 |
"β οΈ No new category selected.",
|
419 |
gr.update(choices=[f"{i+1}. {bookmark['title']} (Category: {bookmark['category']})" for i, bookmark in enumerate(state_bookmarks)]),
|
420 |
-
display_bookmarks(state_bookmarks)
|
421 |
-
state_bookmarks
|
422 |
)
|
423 |
|
424 |
bookmarks = state_bookmarks.copy()
|
@@ -449,7 +446,7 @@ def edit_selected_bookmarks_category(selected_indices, new_category, state_bookm
|
|
449 |
# Update the shared state
|
450 |
updated_state = bookmarks.copy()
|
451 |
|
452 |
-
return message, gr.update(choices=choices), bookmarks_html
|
453 |
|
454 |
# Export bookmarks to HTML
|
455 |
def export_bookmarks(state_bookmarks):
|
@@ -539,7 +536,7 @@ Please identify the most relevant bookmarks that match the user's query. Provide
|
|
539 |
def build_app():
|
540 |
try:
|
541 |
logger.info("Building Gradio app")
|
542 |
-
with gr.Blocks(
|
543 |
.card {
|
544 |
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
|
545 |
transition: 0.3s;
|
@@ -547,29 +544,62 @@ def build_app():
|
|
547 |
.card:hover {
|
548 |
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
|
549 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
""") as demo:
|
551 |
# Shared states
|
552 |
state_bookmarks = gr.State([])
|
553 |
-
chat_history = gr.State([])
|
554 |
|
555 |
# General Overview
|
556 |
gr.Markdown("""
|
557 |
-
# π SmartMarks - AI Browser Bookmarks Manager
|
558 |
|
559 |
-
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.
|
560 |
|
561 |
-
---
|
562 |
|
563 |
-
## π **How to Use SmartMarks**
|
564 |
|
565 |
-
SmartMarks is divided into three main sections:
|
566 |
|
567 |
-
1. **π Upload and Process Bookmarks:** Import your existing bookmarks and let SmartMarks analyze and categorize them for you.
|
568 |
-
2. **π¬ Chat with Bookmarks:** Interact with your bookmarks using natural language queries to find relevant links effortlessly.
|
569 |
-
3. **π οΈ Manage Bookmarks:** View, edit, delete, and export your bookmarks with ease.
|
570 |
|
571 |
-
Navigate through the tabs to explore each feature in detail.
|
572 |
-
""")
|
573 |
|
574 |
# Define Manage Bookmarks components outside the tab for global access
|
575 |
bookmark_selector = gr.CheckboxGroup(label="β
Select Bookmarks", choices=[])
|
@@ -578,21 +608,21 @@ Navigate through the tabs to explore each feature in detail.
|
|
578 |
# Upload and Process Bookmarks Tab
|
579 |
with gr.Tab("Upload and Process Bookmarks"):
|
580 |
gr.Markdown("""
|
581 |
-
## π **Upload and Process Bookmarks**
|
582 |
|
583 |
-
### π **Steps to Upload and Process:**
|
584 |
|
585 |
-
1. **π½ Upload Bookmarks File:**
|
586 |
-
|
587 |
-
|
588 |
|
589 |
-
2. **βοΈ Process Bookmarks:**
|
590 |
-
|
591 |
-
|
592 |
|
593 |
-
3. **π View Processed Bookmarks:**
|
594 |
-
|
595 |
-
""")
|
596 |
|
597 |
upload = gr.File(label="π Upload Bookmarks HTML File", type='binary')
|
598 |
process_button = gr.Button("βοΈ Process Bookmarks")
|
@@ -608,19 +638,22 @@ Navigate through the tabs to explore each feature in detail.
|
|
608 |
# Chat with Bookmarks Tab
|
609 |
with gr.Tab("Chat with Bookmarks"):
|
610 |
gr.Markdown("""
|
611 |
-
## π¬ **Chat with Bookmarks**
|
|
|
|
|
612 |
|
613 |
-
|
|
|
614 |
|
615 |
-
|
616 |
-
|
617 |
|
618 |
-
|
619 |
-
|
620 |
|
621 |
-
|
622 |
-
|
623 |
-
""")
|
624 |
|
625 |
with gr.Row():
|
626 |
chat_history_display = gr.Chatbot(label="π¨οΈ Chat History")
|
@@ -650,28 +683,28 @@ Navigate through the tabs to explore each feature in detail.
|
|
650 |
# Manage Bookmarks Tab
|
651 |
with gr.Tab("Manage Bookmarks"):
|
652 |
gr.Markdown("""
|
653 |
-
## π οΈ **Manage Bookmarks**
|
654 |
|
655 |
-
### ποΈ **Features:**
|
656 |
|
657 |
-
1. **ποΈ View Bookmarks:**
|
658 |
-
|
659 |
|
660 |
-
2. **β
Select Bookmarks:**
|
661 |
-
|
662 |
|
663 |
-
3. **ποΈ Delete Selected Bookmarks:**
|
664 |
-
|
665 |
|
666 |
-
4. **βοΈ Edit Categories:**
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
|
671 |
-
5. **πΎ Export Bookmarks:**
|
672 |
-
|
673 |
-
|
674 |
-
""")
|
675 |
|
676 |
manage_output = gr.Textbox(label="π Manage Output", interactive=False)
|
677 |
new_category_input = gr.Dropdown(label="π New Category", choices=CATEGORIES, value="Uncategorized")
|
@@ -686,13 +719,13 @@ Navigate through the tabs to explore each feature in detail.
|
|
686 |
delete_button.click(
|
687 |
delete_selected_bookmarks,
|
688 |
inputs=[bookmark_selector, state_bookmarks],
|
689 |
-
outputs=[manage_output, bookmark_selector, bookmark_display_manage
|
690 |
)
|
691 |
|
692 |
edit_category_button.click(
|
693 |
edit_selected_bookmarks_category,
|
694 |
inputs=[bookmark_selector, new_category_input, state_bookmarks],
|
695 |
-
outputs=[manage_output, bookmark_selector, bookmark_display_manage
|
696 |
)
|
697 |
|
698 |
export_button.click(
|
|
|
1 |
# app.py
|
2 |
+
|
3 |
import gradio as gr
|
4 |
from bs4 import BeautifulSoup
|
5 |
import asyncio
|
|
|
247 |
# Assign CSS classes based on bookmark status
|
248 |
if bookmark.get('dead_link'):
|
249 |
card_classes = "card dead-link"
|
|
|
250 |
else:
|
251 |
card_classes = "card active-link"
|
|
|
252 |
|
253 |
card_html = f'''
|
254 |
+
<div class="{card_classes}">
|
255 |
<div class="card-content">
|
256 |
+
<h3>{index}. {title} {status}</h3>
|
257 |
+
<p><strong>Category:</strong> {category}</p>
|
258 |
+
<p><strong>URL:</strong> <a href="{url}" target="_blank">{url}</a></p>
|
259 |
+
<p><strong>ETag:</strong> {etag}</p>
|
260 |
+
<p><strong>Summary:</strong> {summary}</p>
|
261 |
</div>
|
262 |
</div>
|
263 |
'''
|
|
|
400 |
# Update the shared state
|
401 |
updated_state = bookmarks.copy()
|
402 |
|
403 |
+
return message, gr.update(choices=choices), bookmarks_html
|
404 |
|
405 |
# Edit category of selected bookmarks
|
406 |
def edit_selected_bookmarks_category(selected_indices, new_category, state_bookmarks):
|
|
|
408 |
return (
|
409 |
"β οΈ No bookmarks selected.",
|
410 |
gr.update(choices=[f"{i+1}. {bookmark['title']} (Category: {bookmark['category']})" for i, bookmark in enumerate(state_bookmarks)]),
|
411 |
+
display_bookmarks(state_bookmarks)
|
|
|
412 |
)
|
413 |
|
414 |
if not new_category:
|
415 |
return (
|
416 |
"β οΈ No new category selected.",
|
417 |
gr.update(choices=[f"{i+1}. {bookmark['title']} (Category: {bookmark['category']})" for i, bookmark in enumerate(state_bookmarks)]),
|
418 |
+
display_bookmarks(state_bookmarks)
|
|
|
419 |
)
|
420 |
|
421 |
bookmarks = state_bookmarks.copy()
|
|
|
446 |
# Update the shared state
|
447 |
updated_state = bookmarks.copy()
|
448 |
|
449 |
+
return message, gr.update(choices=choices), bookmarks_html
|
450 |
|
451 |
# Export bookmarks to HTML
|
452 |
def export_bookmarks(state_bookmarks):
|
|
|
536 |
def build_app():
|
537 |
try:
|
538 |
logger.info("Building Gradio app")
|
539 |
+
with gr.Blocks(css="""
|
540 |
.card {
|
541 |
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
|
542 |
transition: 0.3s;
|
|
|
544 |
.card:hover {
|
545 |
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
|
546 |
}
|
547 |
+
|
548 |
+
/* Dynamic Theme Styling */
|
549 |
+
@media (prefers-color-scheme: dark) {
|
550 |
+
body {
|
551 |
+
color: white;
|
552 |
+
background-color: #121212;
|
553 |
+
}
|
554 |
+
.card {
|
555 |
+
background-color: #1e1e1e;
|
556 |
+
}
|
557 |
+
a {
|
558 |
+
color: #bb86fc;
|
559 |
+
}
|
560 |
+
h1, h2, h3, p, strong {
|
561 |
+
color: inherit;
|
562 |
+
}
|
563 |
+
}
|
564 |
+
|
565 |
+
@media (prefers-color-scheme: light) {
|
566 |
+
body {
|
567 |
+
color: black;
|
568 |
+
background-color: white;
|
569 |
+
}
|
570 |
+
.card {
|
571 |
+
background-color: #fff;
|
572 |
+
}
|
573 |
+
a {
|
574 |
+
color: #1a0dab;
|
575 |
+
}
|
576 |
+
h1, h2, h3, p, strong {
|
577 |
+
color: inherit;
|
578 |
+
}
|
579 |
+
}
|
580 |
""") as demo:
|
581 |
# Shared states
|
582 |
state_bookmarks = gr.State([])
|
583 |
+
chat_history = gr.State([])
|
584 |
|
585 |
# General Overview
|
586 |
gr.Markdown("""
|
587 |
+
# π SmartMarks - AI Browser Bookmarks Manager
|
588 |
|
589 |
+
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.
|
590 |
|
591 |
+
---
|
592 |
|
593 |
+
## π **How to Use SmartMarks**
|
594 |
|
595 |
+
SmartMarks is divided into three main sections:
|
596 |
|
597 |
+
1. **π Upload and Process Bookmarks:** Import your existing bookmarks and let SmartMarks analyze and categorize them for you.
|
598 |
+
2. **π¬ Chat with Bookmarks:** Interact with your bookmarks using natural language queries to find relevant links effortlessly.
|
599 |
+
3. **π οΈ Manage Bookmarks:** View, edit, delete, and export your bookmarks with ease.
|
600 |
|
601 |
+
Navigate through the tabs to explore each feature in detail.
|
602 |
+
""")
|
603 |
|
604 |
# Define Manage Bookmarks components outside the tab for global access
|
605 |
bookmark_selector = gr.CheckboxGroup(label="β
Select Bookmarks", choices=[])
|
|
|
608 |
# Upload and Process Bookmarks Tab
|
609 |
with gr.Tab("Upload and Process Bookmarks"):
|
610 |
gr.Markdown("""
|
611 |
+
## π **Upload and Process Bookmarks**
|
612 |
|
613 |
+
### π **Steps to Upload and Process:**
|
614 |
|
615 |
+
1. **π½ Upload Bookmarks File:**
|
616 |
+
- Click on the **"π Upload Bookmarks HTML File"** button.
|
617 |
+
- Select your browser's exported bookmarks HTML file from your device.
|
618 |
|
619 |
+
2. **βοΈ Process Bookmarks:**
|
620 |
+
- After uploading, click on the **"βοΈ Process Bookmarks"** button.
|
621 |
+
- SmartMarks will parse your bookmarks, fetch additional information, generate summaries, and categorize each link based on predefined categories.
|
622 |
|
623 |
+
3. **π View Processed Bookmarks:**
|
624 |
+
- Once processing is complete, your bookmarks will be displayed in an organized and visually appealing format below.
|
625 |
+
""")
|
626 |
|
627 |
upload = gr.File(label="π Upload Bookmarks HTML File", type='binary')
|
628 |
process_button = gr.Button("βοΈ Process Bookmarks")
|
|
|
638 |
# Chat with Bookmarks Tab
|
639 |
with gr.Tab("Chat with Bookmarks"):
|
640 |
gr.Markdown("""
|
641 |
+
## π¬ **Chat with Bookmarks**
|
642 |
+
|
643 |
+
### π€ **How to Interact:**
|
644 |
|
645 |
+
1. **βοΈ Enter Your Query:**
|
646 |
+
- 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?"
|
647 |
|
648 |
+
2. **π¨ Submit Your Query:**
|
649 |
+
- Click the **"π¨ Send"** button to submit your query.
|
650 |
|
651 |
+
3. **π Receive AI-Driven Responses:**
|
652 |
+
- SmartMarks will analyze your query and provide relevant bookmarks that match your request, making it easier to find specific links without manual searching.
|
653 |
|
654 |
+
4. **ποΈ View Chat History:**
|
655 |
+
- All your queries and the corresponding AI responses are displayed in the chat history for your reference.
|
656 |
+
""")
|
657 |
|
658 |
with gr.Row():
|
659 |
chat_history_display = gr.Chatbot(label="π¨οΈ Chat History")
|
|
|
683 |
# Manage Bookmarks Tab
|
684 |
with gr.Tab("Manage Bookmarks"):
|
685 |
gr.Markdown("""
|
686 |
+
## π οΈ **Manage Bookmarks**
|
687 |
|
688 |
+
### ποΈ **Features:**
|
689 |
|
690 |
+
1. **ποΈ View Bookmarks:**
|
691 |
+
- All your processed bookmarks are displayed here with their respective categories and summaries.
|
692 |
|
693 |
+
2. **β
Select Bookmarks:**
|
694 |
+
- Use the checkboxes next to each bookmark to select one, multiple, or all bookmarks you wish to manage.
|
695 |
|
696 |
+
3. **ποΈ Delete Selected Bookmarks:**
|
697 |
+
- After selecting the desired bookmarks, click the **"ποΈ Delete Selected Bookmarks"** button to remove them from your list.
|
698 |
|
699 |
+
4. **βοΈ Edit Categories:**
|
700 |
+
- Select the bookmarks you want to re-categorize.
|
701 |
+
- Choose a new category from the dropdown menu labeled **"π New Category"**.
|
702 |
+
- Click the **"βοΈ Edit Category of Selected Bookmarks"** button to update their categories.
|
703 |
|
704 |
+
5. **πΎ Export Bookmarks:**
|
705 |
+
- Click the **"πΎ Export Bookmarks"** button to download your updated bookmarks as an HTML file.
|
706 |
+
- This file can be uploaded back to your browser to reflect the changes made within SmartMarks.
|
707 |
+
""")
|
708 |
|
709 |
manage_output = gr.Textbox(label="π Manage Output", interactive=False)
|
710 |
new_category_input = gr.Dropdown(label="π New Category", choices=CATEGORIES, value="Uncategorized")
|
|
|
719 |
delete_button.click(
|
720 |
delete_selected_bookmarks,
|
721 |
inputs=[bookmark_selector, state_bookmarks],
|
722 |
+
outputs=[manage_output, bookmark_selector, bookmark_display_manage]
|
723 |
)
|
724 |
|
725 |
edit_category_button.click(
|
726 |
edit_selected_bookmarks_category,
|
727 |
inputs=[bookmark_selector, new_category_input, state_bookmarks],
|
728 |
+
outputs=[manage_output, bookmark_selector, bookmark_display_manage]
|
729 |
)
|
730 |
|
731 |
export_button.click(
|