import gradio as gr import google.generativeai as genai from dotenv import load_dotenv from bs4 import BeautifulSoup import requests import os # Set your Gemini API key from environment variable genai.configure(api_key=os.environ["GEMINI_API_KEY"]) headers = { "User-Agent": "Mozilla/5.0" } class Website: def __init__(self, url): self.url = url response = requests.get(url, headers=headers) soup = BeautifulSoup(response.content, 'html.parser') self.title = soup.title.string if soup.title else "No title found" for irrelevant in soup.body(["script", "style", "img", "input"]): irrelevant.decompose() self.text = soup.body.get_text(separator="\n", strip=True) def generate_brochure(url): site = Website(url) system_prompt = ( "You are an assistant that analyzes the contents of a website " "and provides a short summary, ignoring text that might be navigation-related. " "Respond in markdown." ) user_prompt = ( f"You are looking at a website titled '{site.title}'. " "The contents of this website are as follows. " "Please provide a short summary of this website in markdown. " "If it includes news or announcements, then summarize those too.\n\n" f"{site.text}" ) model = genai.GenerativeModel("gemini-2.5-pro") response = model.generate_content([system_prompt, user_prompt]) return response.text def chat_interface_function(msg, history): return generate_brochure(msg) gr.ChatInterface( fn=chat_interface_function, chatbot=gr.Chatbot( label = 'Gemini Summary', type="messages", avatar_images=["user_avatar.png", "bot_avatar.png"] ), theme="soft", title="Brochure Generator", description="Paste a **URL** in a correct way and press Enter to get a **markdown-style summary** of the site.", submit_btn="Generate Brochure", examples=[ "https://www.alraya-store.com/", "https://www.apple.com" ] ).launch()