dominguezdaniel commited on
Commit
f0a4457
·
verified ·
1 Parent(s): 403ff13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -27
app.py CHANGED
@@ -1,35 +1,23 @@
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()
 
 
 
 
 
 
 
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 Google Business Profile description. Make it clear, professional, 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
+ with gr.Blocks() as demo:
12
+ gr.Markdown("## Webpy - GMB Optimizer")
13
+ gr.Markdown("Paste your Google Business Profile URL (optional):")
14
+ url = gr.Textbox(label="Google My Business URL (optional)")
15
+
16
+ gr.Markdown("Then paste your current description below:")
17
+ input_desc = gr.Textbox(lines=4, label="Current Description", placeholder="e.g. We create affordable websites for small businesses in Colombia.")
18
+ output = gr.Textbox(label="Improved Description")
19
+
20
+ submit = gr.Button("Enhance")
21
+ submit.click(fn=improve_description, inputs=input_desc, outputs=output)
22
+
23
+ demo.launch()