Spaces:
Runtime error
Runtime error
File size: 1,971 Bytes
6d2672a 0de5a79 6d2672a 0de5a79 95313d9 c3032ff 6d2672a 0de5a79 6d2672a 0de5a79 6d2672a |
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 |
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,
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.",
user_avatar="user_avatar.png",
bot_avatar="bot_avatar.png",
submit_btn="Generate Brochure",
examples=[
"https://apple.com",
"https://www.bbc.com/news"
],
).launch()
|