Update app.py
Browse files
app.py
CHANGED
|
@@ -74,23 +74,16 @@ def infer_business_info_from_url(url):
|
|
| 74 |
)
|
| 75 |
return inferred_info["choices"][0]["message"]["content"]
|
| 76 |
|
| 77 |
-
def
|
| 78 |
"""
|
| 79 |
-
|
| 80 |
-
"""
|
| 81 |
-
location_match = re.search(r'\b(?:serving|located in|offices in|based in)\s([\w\s,]+)', content, re.IGNORECASE)
|
| 82 |
-
return location_match.group(1).strip() if location_match else None
|
| 83 |
-
|
| 84 |
-
def generate_marketing_plan(website_content, industry, goals, budget, location, inferred_info, messages, fallback=False):
|
| 85 |
-
"""
|
| 86 |
-
Generates a marketing plan based on website content, industry, goals, and budget.
|
| 87 |
"""
|
| 88 |
location_info = f"The business is located in {location}." if location else "No specific location was mentioned."
|
| 89 |
additional_info = f"Inferred details: {inferred_info}" if inferred_info else "No additional business details were inferred."
|
| 90 |
|
| 91 |
query = f"""
|
| 92 |
The user has provided the following details:
|
| 93 |
-
-
|
| 94 |
- Industry: {industry}
|
| 95 |
- Goals for 2025: {goals}
|
| 96 |
- Marketing budget for 2025: ${budget}
|
|
@@ -144,31 +137,38 @@ if "show_notice" not in st.session_state:
|
|
| 144 |
st.markdown("<h1 style='text-align: center; color: black;'>2025 Marketing Planner</h1>", unsafe_allow_html=True)
|
| 145 |
|
| 146 |
# User inputs
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
| 155 |
|
| 156 |
# Process results on button click
|
| 157 |
if generate_button:
|
| 158 |
st.session_state["show_notice"] = True
|
| 159 |
-
with st.spinner("Analyzing
|
|
|
|
| 160 |
website_content, scrape_successful = scrape_website(website_url) if website_url else ("", False)
|
| 161 |
location = extract_location(website_content) if scrape_successful else None
|
| 162 |
-
inferred_info = infer_business_info_from_url(website_url) if not scrape_successful else None
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
# Display the waiting notice
|
| 174 |
if st.session_state["show_notice"]:
|
|
@@ -176,6 +176,5 @@ if st.session_state["show_notice"]:
|
|
| 176 |
|
| 177 |
# Display results if there is a reply in session state
|
| 178 |
if st.session_state["reply"]:
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
st.markdown(st.session_state["reply"])
|
|
|
|
| 74 |
)
|
| 75 |
return inferred_info["choices"][0]["message"]["content"]
|
| 76 |
|
| 77 |
+
def generate_marketing_plan(content, industry, goals, budget, location, inferred_info, messages, fallback=False):
|
| 78 |
"""
|
| 79 |
+
Generates a marketing plan based on provided content, industry, goals, and budget.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
"""
|
| 81 |
location_info = f"The business is located in {location}." if location else "No specific location was mentioned."
|
| 82 |
additional_info = f"Inferred details: {inferred_info}" if inferred_info else "No additional business details were inferred."
|
| 83 |
|
| 84 |
query = f"""
|
| 85 |
The user has provided the following details:
|
| 86 |
+
- Content: {content if not fallback else "N/A (no content provided)"}
|
| 87 |
- Industry: {industry}
|
| 88 |
- Goals for 2025: {goals}
|
| 89 |
- Marketing budget for 2025: ${budget}
|
|
|
|
| 137 |
st.markdown("<h1 style='text-align: center; color: black;'>2025 Marketing Planner</h1>", unsafe_allow_html=True)
|
| 138 |
|
| 139 |
# User inputs
|
| 140 |
+
st.markdown("<h2 style='text-align: center; color: black;'>Enter Business Details</h2>", unsafe_allow_html=True)
|
| 141 |
+
website_url = st.text_input("Enter your business website (optional)", placeholder="e.g., https://example.com")
|
| 142 |
+
manual_details = st.text_area(
|
| 143 |
+
"Enter details about your business (if no website is provided or cannot be scanned)",
|
| 144 |
+
placeholder="E.g., Business name, industry, target audience, goals, and location."
|
| 145 |
+
)
|
| 146 |
+
industry = st.text_input("Industry (optional)", placeholder="E.g., Real Estate, Retail, Technology")
|
| 147 |
+
goals = st.text_area("Goals for 2025 (optional)", placeholder="E.g., increase brand awareness, drive online sales")
|
| 148 |
+
budget = st.number_input("Marketing Budget for 2025 ($)", min_value=1000, step=1000)
|
| 149 |
+
generate_button = st.button('Generate Marketing Plan')
|
| 150 |
|
| 151 |
# Process results on button click
|
| 152 |
if generate_button:
|
| 153 |
st.session_state["show_notice"] = True
|
| 154 |
+
with st.spinner("Analyzing provided details and preparing your report..."):
|
| 155 |
+
# Attempt to scrape website content if a URL is provided
|
| 156 |
website_content, scrape_successful = scrape_website(website_url) if website_url else ("", False)
|
| 157 |
location = extract_location(website_content) if scrape_successful else None
|
| 158 |
+
inferred_info = infer_business_info_from_url(website_url) if not scrape_successful and website_url else None
|
| 159 |
+
|
| 160 |
+
# Use manual details as fallback content
|
| 161 |
+
content = website_content if scrape_successful else manual_details
|
| 162 |
+
fallback_mode = not scrape_successful and not manual_details
|
| 163 |
+
|
| 164 |
+
if fallback_mode:
|
| 165 |
+
st.warning("No valid website content or manual details provided. Please enter business details.")
|
| 166 |
+
|
| 167 |
+
messages = initial_messages.copy()
|
| 168 |
+
st.session_state["reply"] = generate_marketing_plan(
|
| 169 |
+
content, industry, goals, budget, location, inferred_info, messages, fallback=fallback_mode
|
| 170 |
+
)
|
| 171 |
+
st.session_state["show_notice"] = False # Remove the notice once the report is ready
|
| 172 |
|
| 173 |
# Display the waiting notice
|
| 174 |
if st.session_state["show_notice"]:
|
|
|
|
| 176 |
|
| 177 |
# Display results if there is a reply in session state
|
| 178 |
if st.session_state["reply"]:
|
| 179 |
+
st.markdown("<h2 style='text-align: center; color: black;'>Your 2025 Marketing Plan ⬇️</h2>", unsafe_allow_html=True)
|
| 180 |
+
st.markdown(st.session_state["reply"])
|
|
|