Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,35 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
generator = pipeline("text-generation", model="gpt2")
|
5 |
|
6 |
-
def
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
result = generator(prompt, max_length=120, num_return_sequences=1)[0]['generated_text']
|
9 |
return result
|
10 |
|
11 |
gr.Interface(
|
12 |
-
fn=
|
13 |
-
inputs=gr.Textbox(label="Your
|
14 |
outputs="text",
|
15 |
-
title="
|
16 |
-
description="Paste your
|
17 |
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
from transformers import pipeline
|
5 |
|
6 |
generator = pipeline("text-generation", model="gpt2")
|
7 |
|
8 |
+
def fetch_description(url):
|
9 |
+
try:
|
10 |
+
response = requests.get(url, timeout=5)
|
11 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
12 |
+
# Try to find a meta or paragraph that looks like a description
|
13 |
+
desc = soup.find("meta", {"name": "description"})
|
14 |
+
if desc and desc.get("content"):
|
15 |
+
return desc["content"]
|
16 |
+
p_tags = soup.find_all("p")
|
17 |
+
if p_tags:
|
18 |
+
return p_tags[0].text.strip()
|
19 |
+
return "Could not extract description automatically. Please paste it manually."
|
20 |
+
except Exception as e:
|
21 |
+
return f"Error fetching the page: {str(e)}"
|
22 |
+
|
23 |
+
def improve_description_from_url(url):
|
24 |
+
original = fetch_description(url)
|
25 |
+
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:"
|
26 |
result = generator(prompt, max_length=120, num_return_sequences=1)[0]['generated_text']
|
27 |
return result
|
28 |
|
29 |
gr.Interface(
|
30 |
+
fn=improve_description_from_url,
|
31 |
+
inputs=gr.Textbox(label="Your Google Business Profile URL", placeholder="https://g.page/yourbusiness"),
|
32 |
outputs="text",
|
33 |
+
title="GMB Description Enhancer from URL",
|
34 |
+
description="Paste your Google Business Profile URL and get an improved business description.",
|
35 |
).launch()
|