Spaces:
Runtime error
Runtime error
File size: 1,459 Bytes
6e00735 dd08025 6e00735 dd08025 afc6bfd 6e00735 a20ff57 dd08025 6e00735 dd08025 a20ff57 |
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 |
import gradio as gr
import requests
from bs4 import BeautifulSoup
from transformers import pipeline
generator = pipeline("text-generation", model="gpt2")
def fetch_description(url):
try:
response = requests.get(url, timeout=5)
soup = BeautifulSoup(response.text, 'html.parser')
# Try to find a meta or paragraph that looks like a description
desc = soup.find("meta", {"name": "description"})
if desc and desc.get("content"):
return desc["content"]
p_tags = soup.find_all("p")
if p_tags:
return p_tags[0].text.strip()
return "Could not extract description automatically. Please paste it manually."
except Exception as e:
return f"Error fetching the page: {str(e)}"
def improve_description_from_url(url):
original = fetch_description(url)
prompt = f"Improve this business description for a Google My Business profile. Make it sound professional and SEO-friendly:\n\n{original}\n\nImproved version:"
result = generator(prompt, max_length=120, num_return_sequences=1)[0]['generated_text']
return result
gr.Interface(
fn=improve_description_from_url,
inputs=gr.Textbox(label="Your Google Business Profile URL", placeholder="https://g.page/yourbusiness"),
outputs="text",
title="GMB Description Enhancer from URL",
description="Paste your Google Business Profile URL and get an improved business description.",
).launch() |