File size: 4,063 Bytes
314bf31
a4303b2
314bf31
 
 
 
 
 
 
6952cd8
314bf31
 
 
 
6952cd8
314bf31
 
 
 
6952cd8
314bf31
 
6952cd8
314bf31
 
6952cd8
314bf31
 
6952cd8
f745765
 
6952cd8
f745765
 
6952cd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f745765
 
6952cd8
 
 
f745765
 
6952cd8
 
 
f745765
 
6952cd8
f745765
 
 
6952cd8
f745765
 
6952cd8
 
 
 
 
 
f745765
 
 
 
6952cd8
f745765
 
 
6952cd8
f745765
 
6952cd8
 
 
 
 
f745765
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6952cd8
f745765
 
 
 
 
6952cd8
f745765
 
 
 
 
6952cd8
f745765
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# app.py

import gradio as gr
from bs4 import BeautifulSoup
import requests
from transformers import pipeline
from sentence_transformers import SentenceTransformer
import faiss
import numpy as np
import pandas as pd

# Initialize models and variables
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
faiss_index = None
bookmarks = []
fetch_cache = {}

def parse_bookmarks(file_content):
    # [Same as before]

def fetch_url_info(bookmark):
    # [Same as before]

def generate_summary(bookmark):
    # [Same as before]

def vectorize_and_index(bookmarks):
    # [Same as before]

def display_bookmarks():
    data = []
    for i, bookmark in enumerate(bookmarks):
        status = "Dead Link" if bookmark.get('dead_link') else "Active"
        css_class = "dead-link" if bookmark.get('dead_link') else ""
        data.append({
            'Index': i,
            'Title': bookmark['title'],
            'URL': bookmark['url'],
            'Status': status,
            'ETag': bookmark.get('etag', 'N/A'),
            'Summary': bookmark.get('summary', ''),
            'css_class': css_class
        })
    df = pd.DataFrame(data)
    return df

def process_uploaded_file(file):
    # [Updated as per Step 3]

def chatbot_response(user_query):
    # [Same as before]

def edit_bookmark(bookmark_idx, new_title, new_url):
    # [Update outputs to include the updated bookmarks list]
    message, updated_df = "Bookmark updated successfully.", display_bookmarks()
    return message, updated_df

def delete_bookmark(bookmark_idx):
    # [Update outputs to include the updated bookmarks list]
    message, updated_df = "Bookmark deleted successfully.", display_bookmarks()
    return message, updated_df

def build_app():
    with gr.Blocks(css="app.css") as demo:
        gr.Markdown("# Bookmark Manager App")

        with gr.Tab("Upload and Process Bookmarks"):
            upload = gr.File(label="Upload Bookmarks HTML File", type='binary')
            process_button = gr.Button("Process Bookmarks")
            output_text = gr.Textbox(label="Output")
            bookmark_table = gr.Dataframe(
                label="Bookmarks",
                headers=["Index", "Title", "URL", "Status", "ETag", "Summary"],
                datatype=["number", "str", "str", "str", "str", "str"],
                interactive=False
            )

            process_button.click(
                process_uploaded_file,
                inputs=upload,
                outputs=[output_text, bookmark_table]
            )

        with gr.Tab("Chat with Bookmarks"):
            # [Same as before]

        with gr.Tab("Manage Bookmarks"):
            manage_output = gr.Textbox(label="Manage Output")
            bookmark_table_manage = gr.Dataframe(
                label="Bookmarks",
                headers=["Index", "Title", "URL", "Status", "ETag", "Summary"],
                datatype=["number", "str", "str", "str", "str", "str"],
                interactive=False
            )
            refresh_button = gr.Button("Refresh Bookmark List")

            with gr.Row():
                index_input = gr.Number(label="Bookmark Index")
                new_title_input = gr.Textbox(label="New Title")
                new_url_input = gr.Textbox(label="New URL")

            edit_button = gr.Button("Edit Bookmark")
            delete_button = gr.Button("Delete Bookmark")

            refresh_button.click(
                display_bookmarks,
                inputs=None,
                outputs=bookmark_table_manage
            )

            edit_button.click(
                edit_bookmark,
                inputs=[index_input, new_title_input, new_url_input],
                outputs=[manage_output, bookmark_table_manage]
            )

            delete_button.click(
                delete_bookmark,
                inputs=index_input,
                outputs=[manage_output, bookmark_table_manage]
            )

    demo.launch()

if __name__ == "__main__":
    build_app()