siddhartharya commited on
Commit
813db16
Β·
verified Β·
1 Parent(s): 1a82ad7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -56
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 state to store bookmarks
455
  state_bookmarks = gr.State([])
 
456
 
457
  # General Overview
458
  gr.Markdown("""
459
- # πŸ“š SmartMarks - AI Browser Bookmarks Manager
460
 
461
- 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.
462
 
463
- ---
464
 
465
- ## πŸš€ **How to Use SmartMarks**
466
 
467
- SmartMarks is divided into three main sections:
468
 
469
- 1. **πŸ“‚ Upload and Process Bookmarks:** Import your existing bookmarks and let SmartMarks analyze and categorize them for you.
470
- 2. **πŸ’¬ Chat with Bookmarks:** Interact with your bookmarks using natural language queries to find relevant links effortlessly.
471
- 3. **πŸ› οΈ Manage Bookmarks:** View, edit, delete, and export your bookmarks with ease.
472
 
473
- Navigate through the tabs to explore each feature in detail.
474
- """)
475
 
476
  # Upload and Process Bookmarks Tab
477
  with gr.Tab("Upload and Process Bookmarks"):
478
  gr.Markdown("""
479
- ## πŸ“‚ **Upload and Process Bookmarks**
480
 
481
- ### πŸ“ **Steps to Upload and Process:**
482
 
483
- 1. **πŸ”½ Upload Bookmarks File:**
484
- - Click on the **"πŸ“ Upload Bookmarks HTML File"** button.
485
- - Select your browser's exported bookmarks HTML file from your device.
486
 
487
- 2. **βš™οΈ Process Bookmarks:**
488
- - After uploading, click on the **"βš™οΈ Process Bookmarks"** button.
489
- - SmartMarks will parse your bookmarks, fetch additional information, generate summaries, and categorize each link based on predefined categories.
490
 
491
- 3. **πŸ“„ View Processed Bookmarks:**
492
- - Once processing is complete, your bookmarks will be displayed in an organized and visually appealing format below.
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
- ## πŸ’¬ **Chat with Bookmarks**
510
 
511
- ### πŸ€– **How to Interact:**
512
 
513
- 1. **✍️ Enter Your Query:**
514
- - 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?"
515
 
516
- 2. **πŸ“¨ Submit Your Query:**
517
- - Click the **"πŸ“¨ Send"** button to submit your query.
518
 
519
- 3. **πŸ“ˆ Receive AI-Driven Responses:**
520
- - SmartMarks will analyze your query and provide relevant bookmarks that match your request, making it easier to find specific links without manual searching.
521
- """)
522
 
523
- user_input = gr.Textbox(label="✍️ Ask about your bookmarks", placeholder="e.g., Do I have any bookmarks about GenerativeAI?")
524
- chat_output = gr.Textbox(label="πŸ’¬ Chatbot Response", interactive=False)
525
- chat_button = gr.Button("πŸ“¨ Send")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
 
 
527
  chat_button.click(
528
- chatbot_response,
529
- inputs=[user_input, state_bookmarks],
530
- outputs=chat_output
531
  )
532
 
533
  # Manage Bookmarks Tab
534
  with gr.Tab("Manage Bookmarks"):
535
  gr.Markdown("""
536
- ## πŸ› οΈ **Manage Bookmarks**
537
 
538
- ### πŸ—‚οΈ **Features:**
539
 
540
- 1. **πŸ‘οΈ View Bookmarks:**
541
- - All your processed bookmarks are displayed here with their respective categories and summaries.
542
 
543
- 2. **βœ… Select Bookmarks:**
544
- - Use the checkboxes next to each bookmark to select one, multiple, or all bookmarks you wish to manage.
545
 
546
- 3. **πŸ—‘οΈ Delete Selected Bookmarks:**
547
- - After selecting the desired bookmarks, click the **"πŸ—‘οΈ Delete Selected Bookmarks"** button to remove them from your list.
548
 
549
- 4. **✏️ Edit Categories:**
550
- - Select the bookmarks you want to re-categorize.
551
- - Choose a new category from the dropdown menu labeled **"πŸ†• New Category"**.
552
- - Click the **"✏️ Edit Category of Selected Bookmarks"** button to update their categories.
553
 
554
- 5. **πŸ’Ύ Export Bookmarks:**
555
- - Click the **"πŸ’Ύ Export Bookmarks"** button to download your updated bookmarks as an HTML file.
556
- - This file can be uploaded back to your browser to reflect the changes made within SmartMarks.
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
- refresh_button.click(
 
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
- logger.info("Launching Gradio app")
606
- demo.launch(debug=True)
 
 
 
 
 
 
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}")