Spaces:
Runtime error
Runtime error
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() |