Spaces:
Running
Running
File size: 2,070 Bytes
6d2672a e9c37ad 9a5bc4c 0de5a79 6d2672a 7442bcb 9a5bc4c c3032ff 6d2672a eaf823e 025bfac 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 64 65 66 67 |
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()
|