Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,7 @@ def scrape_website(url, max_pages=5):
|
|
| 19 |
visited = set()
|
| 20 |
to_visit = [url]
|
| 21 |
all_content = []
|
|
|
|
| 22 |
|
| 23 |
while to_visit and len(visited) < max_pages:
|
| 24 |
current_url = to_visit.pop(0)
|
|
@@ -30,6 +31,7 @@ def scrape_website(url, max_pages=5):
|
|
| 30 |
response.raise_for_status()
|
| 31 |
soup = BeautifulSoup(response.content, "html.parser")
|
| 32 |
visited.add(current_url)
|
|
|
|
| 33 |
|
| 34 |
# Extract meaningful content
|
| 35 |
meta_description = soup.find("meta", {"name": "description"})
|
|
@@ -46,10 +48,11 @@ def scrape_website(url, max_pages=5):
|
|
| 46 |
if url in full_url and full_url not in visited:
|
| 47 |
to_visit.append(full_url)
|
| 48 |
|
| 49 |
-
except Exception
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
return " ".join(all_content[:3000])
|
| 53 |
|
| 54 |
# Initial system message setup
|
| 55 |
initial_messages = [{
|
|
@@ -118,14 +121,15 @@ with col1:
|
|
| 118 |
|
| 119 |
# Process results on button click
|
| 120 |
if generate_button:
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
| 124 |
if fallback_mode:
|
| 125 |
st.warning("Unable to retrieve website content. Generating recommendations based on your input.")
|
| 126 |
messages = initial_messages.copy()
|
| 127 |
st.session_state["reply"] = generate_marketing_plan(
|
| 128 |
-
website_content if
|
| 129 |
industry, goals, budget, messages, fallback=fallback_mode
|
| 130 |
)
|
| 131 |
|
|
|
|
| 19 |
visited = set()
|
| 20 |
to_visit = [url]
|
| 21 |
all_content = []
|
| 22 |
+
scrape_successful = False
|
| 23 |
|
| 24 |
while to_visit and len(visited) < max_pages:
|
| 25 |
current_url = to_visit.pop(0)
|
|
|
|
| 31 |
response.raise_for_status()
|
| 32 |
soup = BeautifulSoup(response.content, "html.parser")
|
| 33 |
visited.add(current_url)
|
| 34 |
+
scrape_successful = True
|
| 35 |
|
| 36 |
# Extract meaningful content
|
| 37 |
meta_description = soup.find("meta", {"name": "description"})
|
|
|
|
| 48 |
if url in full_url and full_url not in visited:
|
| 49 |
to_visit.append(full_url)
|
| 50 |
|
| 51 |
+
except Exception:
|
| 52 |
+
# Silently skip any errors during scraping
|
| 53 |
+
continue
|
| 54 |
|
| 55 |
+
return " ".join(all_content[:3000]), scrape_successful
|
| 56 |
|
| 57 |
# Initial system message setup
|
| 58 |
initial_messages = [{
|
|
|
|
| 121 |
|
| 122 |
# Process results on button click
|
| 123 |
if generate_button:
|
| 124 |
+
st.info("Generating your marketing plan. This process may take a minute or two. Please wait...")
|
| 125 |
+
with st.spinner("Analyzing website content and preparing your report..."):
|
| 126 |
+
website_content, scrape_successful = scrape_website(website_url) if website_url else ("", False)
|
| 127 |
+
fallback_mode = not scrape_successful
|
| 128 |
if fallback_mode:
|
| 129 |
st.warning("Unable to retrieve website content. Generating recommendations based on your input.")
|
| 130 |
messages = initial_messages.copy()
|
| 131 |
st.session_state["reply"] = generate_marketing_plan(
|
| 132 |
+
website_content if scrape_successful else "N/A",
|
| 133 |
industry, goals, budget, messages, fallback=fallback_mode
|
| 134 |
)
|
| 135 |
|