dominguezdaniel commited on
Commit
dd08025
·
verified ·
1 Parent(s): a20ff57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
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 improve_description(description):
7
- prompt = f"Improve this business description for a Google My Business profile. Make it sound professional, trustworthy, and SEO-friendly:\n\n{description}\n\nImproved version:"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  result = generator(prompt, max_length=120, num_return_sequences=1)[0]['generated_text']
9
  return result
10
 
11
  gr.Interface(
12
- fn=improve_description,
13
- inputs=gr.Textbox(label="Your Current Business Description", placeholder="We build websites for small businesses in Colombia..."),
14
  outputs="text",
15
- title="Webpy: GMB Description Enhancer",
16
- description="Paste your current Google My Business description and get an AI-enhanced version.",
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()