Spaces:
Sleeping
Sleeping
siddhartharya
commited on
Commit
•
a3d35f9
1
Parent(s):
3262eda
Update app.py
Browse files
app.py
CHANGED
@@ -261,7 +261,7 @@ def generate_contextual_summary(context):
|
|
261 |
Type: {page_type}
|
262 |
Description: {context['description']}
|
263 |
Keywords: {context['keywords']}
|
264 |
-
|
265 |
Additional Content:
|
266 |
{context['content'][:3000]}
|
267 |
|
@@ -574,6 +574,60 @@ def display_bookmarks():
|
|
574 |
logger.info("HTML display generated")
|
575 |
return display_html
|
576 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
577 |
def process_uploaded_file(file):
|
578 |
"""
|
579 |
Process the uploaded bookmarks file with enhanced error handling and user feedback.
|
@@ -749,7 +803,21 @@ def export_bookmarks():
|
|
749 |
href = f'data:text/html;base64,{b64}'
|
750 |
|
751 |
logger.info("Bookmarks exported successfully")
|
752 |
-
return f'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
753 |
except Exception as e:
|
754 |
logger.error(f"Error exporting bookmarks: {e}")
|
755 |
return "⚠️ Error exporting bookmarks."
|
@@ -793,7 +861,7 @@ def chatbot_response(user_query):
|
|
793 |
User Query: {user_query}
|
794 |
|
795 |
Relevant Bookmarks:
|
796 |
-
{'
|
797 |
|
798 |
Please provide a helpful response that:
|
799 |
1. Identifies the most relevant bookmarks for the query
|
@@ -829,7 +897,64 @@ def build_app():
|
|
829 |
try:
|
830 |
logger.info("Building Gradio app")
|
831 |
with gr.Blocks(css="app.css") as demo:
|
832 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
|
834 |
logger.info("Launching Gradio app")
|
835 |
demo.launch(debug=True)
|
@@ -838,4 +963,4 @@ def build_app():
|
|
838 |
print(f"Error building the app: {e}")
|
839 |
|
840 |
if __name__ == "__main__":
|
841 |
-
build_app()
|
|
|
261 |
Type: {page_type}
|
262 |
Description: {context['description']}
|
263 |
Keywords: {context['keywords']}
|
264 |
+
|
265 |
Additional Content:
|
266 |
{context['content'][:3000]}
|
267 |
|
|
|
574 |
logger.info("HTML display generated")
|
575 |
return display_html
|
576 |
|
577 |
+
def assign_category(bookmark):
|
578 |
+
"""
|
579 |
+
Assign a category to a bookmark based on its title or summary.
|
580 |
+
This is a simple implementation and can be enhanced with more sophisticated methods.
|
581 |
+
"""
|
582 |
+
title = bookmark.get('title', '').lower()
|
583 |
+
summary = bookmark.get('summary', '').lower()
|
584 |
+
|
585 |
+
# Simple keyword-based categorization
|
586 |
+
if any(keyword in title or keyword in summary for keyword in ['facebook', 'twitter', 'instagram']):
|
587 |
+
bookmark['category'] = 'Social Media'
|
588 |
+
elif any(keyword in title or keyword in summary for keyword in ['news', 'media', 'huffpost', 'times']):
|
589 |
+
bookmark['category'] = 'News and Media'
|
590 |
+
elif any(keyword in title or keyword in summary for keyword in ['course', 'learning', 'education']):
|
591 |
+
bookmark['category'] = 'Education and Learning'
|
592 |
+
elif any(keyword in title or keyword in summary for keyword in ['movie', 'music', 'audio', 'video']):
|
593 |
+
bookmark['category'] = 'Entertainment'
|
594 |
+
elif any(keyword in title or keyword in summary for keyword in ['shop', 'e-commerce', 'buy', 'purchase']):
|
595 |
+
bookmark['category'] = 'Shopping and E-commerce'
|
596 |
+
elif any(keyword in title or keyword in summary for keyword in ['finance', 'banking', 'investment']):
|
597 |
+
bookmark['category'] = 'Finance and Banking'
|
598 |
+
elif any(keyword in title or keyword in summary for keyword in ['tech', 'technology', 'software']):
|
599 |
+
bookmark['category'] = 'Technology'
|
600 |
+
elif any(keyword in title or keyword in summary for keyword in ['health', 'fitness', 'wellness']):
|
601 |
+
bookmark['category'] = 'Health and Fitness'
|
602 |
+
elif any(keyword in title or keyword in summary for keyword in ['travel', 'tourism', 'flight', 'hotel']):
|
603 |
+
bookmark['category'] = 'Travel and Tourism'
|
604 |
+
elif any(keyword in title or keyword in summary for keyword in ['recipe', 'food', 'cooking']):
|
605 |
+
bookmark['category'] = 'Food and Recipes'
|
606 |
+
elif any(keyword in title or keyword in summary for keyword in ['sport', 'game', 'fitness']):
|
607 |
+
bookmark['category'] = 'Sports'
|
608 |
+
elif any(keyword in title or keyword in summary for keyword in ['art', 'culture', 'museum']):
|
609 |
+
bookmark['category'] = 'Arts and Culture'
|
610 |
+
elif any(keyword in title or keyword in summary for keyword in ['gov', 'government', 'politics']):
|
611 |
+
bookmark['category'] = 'Government and Politics'
|
612 |
+
elif any(keyword in title or keyword in summary for keyword in ['business', 'economy', 'market']):
|
613 |
+
bookmark['category'] = 'Business and Economy'
|
614 |
+
elif any(keyword in title or keyword in summary for keyword in ['science', 'research', 'study']):
|
615 |
+
bookmark['category'] = 'Science and Research'
|
616 |
+
elif any(keyword in title or keyword in summary for keyword in ['blog', 'journal']):
|
617 |
+
bookmark['category'] = 'Personal Blogs and Journals'
|
618 |
+
elif any(keyword in title or keyword in summary for keyword in ['job', 'career', 'employment']):
|
619 |
+
bookmark['category'] = 'Job Search and Careers'
|
620 |
+
elif any(keyword in title or keyword in summary for keyword in ['audio', 'music']):
|
621 |
+
bookmark['category'] = 'Music and Audio'
|
622 |
+
elif any(keyword in title or keyword in summary for keyword in ['video', 'movie']):
|
623 |
+
bookmark['category'] = 'Videos and Movies'
|
624 |
+
elif any(keyword in title or keyword in summary for keyword in ['reference', 'knowledge', 'wiki']):
|
625 |
+
bookmark['category'] = 'Reference and Knowledge Bases'
|
626 |
+
elif bookmark.get('dead_link'):
|
627 |
+
bookmark['category'] = 'Dead Link'
|
628 |
+
else:
|
629 |
+
bookmark['category'] = 'Uncategorized'
|
630 |
+
|
631 |
def process_uploaded_file(file):
|
632 |
"""
|
633 |
Process the uploaded bookmarks file with enhanced error handling and user feedback.
|
|
|
803 |
href = f'data:text/html;base64,{b64}'
|
804 |
|
805 |
logger.info("Bookmarks exported successfully")
|
806 |
+
return f'''
|
807 |
+
<div style="text-align: center;">
|
808 |
+
<a href="{href}"
|
809 |
+
download="bookmarks.html"
|
810 |
+
style="display: inline-block;
|
811 |
+
padding: 10px 20px;
|
812 |
+
background-color: #4CAF50;
|
813 |
+
color: white;
|
814 |
+
text-decoration: none;
|
815 |
+
border-radius: 5px;
|
816 |
+
margin: 10px;">
|
817 |
+
💾 Download Exported Bookmarks
|
818 |
+
</a>
|
819 |
+
</div>
|
820 |
+
'''
|
821 |
except Exception as e:
|
822 |
logger.error(f"Error exporting bookmarks: {e}")
|
823 |
return "⚠️ Error exporting bookmarks."
|
|
|
861 |
User Query: {user_query}
|
862 |
|
863 |
Relevant Bookmarks:
|
864 |
+
{'\\n\\n'.join(bookmark_descriptions)}
|
865 |
|
866 |
Please provide a helpful response that:
|
867 |
1. Identifies the most relevant bookmarks for the query
|
|
|
897 |
try:
|
898 |
logger.info("Building Gradio app")
|
899 |
with gr.Blocks(css="app.css") as demo:
|
900 |
+
gr.Markdown("# 📚 Bookmark Manager")
|
901 |
+
|
902 |
+
with gr.Row():
|
903 |
+
with gr.Column():
|
904 |
+
file_input = gr.File(label="Upload Bookmarks HTML File", file_types=["file"])
|
905 |
+
process_button = gr.Button("Process Bookmarks")
|
906 |
+
process_message = gr.Markdown("")
|
907 |
+
|
908 |
+
category_dropdown = gr.Dropdown(choices=CATEGORIES, label="New Category")
|
909 |
+
edit_button = gr.Button("Edit Selected Bookmarks Category")
|
910 |
+
|
911 |
+
delete_button = gr.Button("Delete Selected Bookmarks")
|
912 |
+
export_button = gr.Button("Export Bookmarks")
|
913 |
+
|
914 |
+
with gr.Column():
|
915 |
+
bookmarks_display = gr.HTML(label="Bookmarks")
|
916 |
+
|
917 |
+
with gr.Row():
|
918 |
+
chatbot_input = gr.Textbox(label="Ask about your bookmarks", placeholder="Enter your query here...")
|
919 |
+
chatbot_output = gr.Textbox(label="Chatbot Response", interactive=False)
|
920 |
+
|
921 |
+
# Processing File
|
922 |
+
process_button.click(
|
923 |
+
fn=process_uploaded_file,
|
924 |
+
inputs=file_input,
|
925 |
+
outputs=[process_message, bookmarks_display, gr.Dropdown.update(), bookmarks_display]
|
926 |
+
)
|
927 |
+
|
928 |
+
# Deleting Bookmarks
|
929 |
+
delete_button.click(
|
930 |
+
fn=delete_selected_bookmarks,
|
931 |
+
inputs=gr.CheckboxGroup(label="Select Bookmarks to Delete", choices=[]),
|
932 |
+
outputs=[process_message, gr.Dropdown.update(), bookmarks_display]
|
933 |
+
)
|
934 |
+
|
935 |
+
# Editing Categories
|
936 |
+
edit_button.click(
|
937 |
+
fn=edit_selected_bookmarks_category,
|
938 |
+
inputs=[
|
939 |
+
gr.CheckboxGroup(label="Select Bookmarks to Edit", choices=[]),
|
940 |
+
category_dropdown
|
941 |
+
],
|
942 |
+
outputs=[process_message, gr.Dropdown.update(), bookmarks_display]
|
943 |
+
)
|
944 |
+
|
945 |
+
# Exporting Bookmarks
|
946 |
+
export_button.click(
|
947 |
+
fn=export_bookmarks,
|
948 |
+
inputs=None,
|
949 |
+
outputs=gr.HTML(label="Export")
|
950 |
+
)
|
951 |
+
|
952 |
+
# Chatbot
|
953 |
+
chatbot_input.submit(
|
954 |
+
fn=chatbot_response,
|
955 |
+
inputs=chatbot_input,
|
956 |
+
outputs=chatbot_output
|
957 |
+
)
|
958 |
|
959 |
logger.info("Launching Gradio app")
|
960 |
demo.launch(debug=True)
|
|
|
963 |
print(f"Error building the app: {e}")
|
964 |
|
965 |
if __name__ == "__main__":
|
966 |
+
build_app()
|