# Website_scraping_tab.py # Gradio UI for scraping websites # Imports # # External Imports import gradio as gr from App_Function_Libraries.Article_Summarization_Lib import scrape_and_summarize_multiple from App_Function_Libraries.DB_Manager import load_preset_prompts from App_Function_Libraries.Gradio_UI.Chat_ui import update_user_prompt # # Local Imports # # ######################################################################################################################## # # Functions: def create_website_scraping_tab(): with gr.TabItem("Website Scraping"): gr.Markdown("# Scrape Websites & Summarize Articles using a Headless Chrome Browser!") with gr.Row(): with gr.Column(): url_input = gr.Textbox(label="Article URLs", placeholder="Enter article URLs here, one per line", lines=5) custom_article_title_input = gr.Textbox(label="Custom Article Titles (Optional, one per line)", placeholder="Enter custom titles for the articles, one per line", lines=5) with gr.Row(): custom_prompt_checkbox = gr.Checkbox(label="Use a Custom Prompt", value=False, visible=True) preset_prompt_checkbox = gr.Checkbox(label="Use a pre-set Prompt", value=False, visible=True) with gr.Row(): preset_prompt = gr.Dropdown(label="Select Preset Prompt", choices=load_preset_prompts(), visible=False) with gr.Row(): website_custom_prompt_input = gr.Textbox(label="Custom Prompt", placeholder="Enter custom prompt here", lines=3, visible=False) with gr.Row(): system_prompt_input = gr.Textbox(label="System Prompt", value="""You are a bulleted notes specialist. [INST]```When creating comprehensive bulleted notes, you should follow these guidelines: Use multiple headings based on the referenced topics, not categories like quotes or terms. Headings should be surrounded by bold formatting and not be listed as bullet points themselves. Leave no space between headings and their corresponding list items underneath. Important terms within the content should be emphasized by setting them in bold font. Any text that ends with a colon should also be bolded. Before submitting your response, review the instructions, and make any corrections necessary to adhered to the specified format. Do not reference these instructions within the notes.``` \nBased on the content between backticks create comprehensive bulleted notes.[/INST] **Bulleted Note Creation Guidelines** **Headings**: - Based on referenced topics, not categories like quotes or terms - Surrounded by **bold** formatting - Not listed as bullet points - No space between headings and list items underneath **Emphasis**: - **Important terms** set in bold font - **Text ending in a colon**: also bolded **Review**: - Ensure adherence to specified format - Do not reference these instructions in your response.[INST] {{ .Prompt }} [/INST] """, lines=3, visible=False) custom_prompt_checkbox.change( fn=lambda x: (gr.update(visible=x), gr.update(visible=x)), inputs=[custom_prompt_checkbox], outputs=[website_custom_prompt_input, system_prompt_input] ) preset_prompt_checkbox.change( fn=lambda x: gr.update(visible=x), inputs=[preset_prompt_checkbox], outputs=[preset_prompt] ) def update_prompts(preset_name): prompts = update_user_prompt(preset_name) return ( gr.update(value=prompts["user_prompt"], visible=True), gr.update(value=prompts["system_prompt"], visible=True) ) preset_prompt.change( update_prompts, inputs=preset_prompt, outputs=[website_custom_prompt_input, system_prompt_input] ) api_name_input = gr.Dropdown( choices=[None, "Local-LLM", "OpenAI", "Anthropic", "Cohere", "Groq", "DeepSeek", "Mistral", "OpenRouter", "Llama.cpp", "Kobold", "Ooba", "Tabbyapi", "VLLM","ollama", "HuggingFace"], value=None, label="API Name (Mandatory for Summarization)") api_key_input = gr.Textbox(label="API Key (Mandatory if API Name is specified)", placeholder="Enter your API key here; Ignore if using Local API or Built-in API", type="password") keywords_input = gr.Textbox(label="Keywords", placeholder="Enter keywords here (comma-separated)", value="default,no_keyword_set", visible=True) scrape_button = gr.Button("Scrape and Summarize") with gr.Column(): result_output = gr.Textbox(label="Result", lines=20) scrape_button.click( fn=scrape_and_summarize_multiple, inputs=[url_input, website_custom_prompt_input, api_name_input, api_key_input, keywords_input, custom_article_title_input, system_prompt_input], outputs=result_output )