Spaces:
Runtime error
Runtime error
Update app.py
Browse files3 unmodified lines45678939 unmodified lines495051525354555657585960616263646566676869707172738 unmodified lines82838485868788899091929394959697989910010110225 unmodified lines1281291301311321331341351361371381391403 unmodified linesfrom bs4 import BeautifulSoupfrom urllib.parse import urljoinimport os# Ensure your OpenAI API key is set in your environment variablesopenai.api_key = os.getenv("OPENAI_API_KEY")39 unmodified linesto_visit.append(full_url)except Exception:# Silently skip any errors during scrapingcontinuereturn " ".join(all_content[:3000]), scrape_successful# Initial system message setupinitial_messages = [{"role": "system","content": """You are a world-class marketing strategist trained by Neil Patel, David Ogilvy, and Seth Godin.Your task is to create highly customized and innovative marketing plans based on the provided details.Go beyond generic strategies and use advanced analysis to recommend:- Marketing tactics inspired by successful case studies from the same or similar industries.- Unique approaches that leverage emerging trends, tools, and platforms.- Recommendations that align with the business's budget and specific goals.Each strategy must:- Be actionable, with clear steps to execute.- Include measurable KPIs to track success.- Be specific to the business's industry, competitive landscape, and target audience.Ensure every suggestion feels fresh, creative, and deeply tailored to the business's needs."""}]def call_openai_api(messages):8 unmodified lines)return response["choices"][0]["message"]["content"]def generate_marketing_plan(website_content, industry, goals, budget, messages, fallback=False):"""Generates a marketing plan based on website content, industry, and user goals."""query = f"""The user has provided the following details:- Website content: {website_content if not fallback else "N/A (website content could not be retrieved)"}- Industry: {industry}- Goals for 2025: {goals}- Marketing budget for 2025: ${budget}Create a comprehensive, customized 1-year marketing plan for 2025, including:- Advanced analysis based on successful case studies and trends.- Unique strategies for the business to stand out.- Actionable steps with measurable KPIs.Avoid generic suggestions; focus on innovative and practical ideas."""messages.append({"role": "user", "content": query})return call_openai_api(messages)25 unmodified linesst.session_state["show_notice"] = Truewith st.spinner("Analyzing website content and preparing your report..."):website_content, scrape_successful = scrape_website(website_url) if website_url else ("", False)fallback_mode = not scrape_successfulif fallback_mode:st.warning("Unable to retrieve website content. Generating recommendations based on your input.")messages = initial_messages.copy()st.session_state["reply"] = generate_marketing_plan(website_content if scrape_successful else "N/A",industry, goals, budget, messages, fallback=fallback_mode)st.session_state["show_notice"] = False # Remove the notice once the report is ready3 unmodified lines4567891039 unmodified lines50515253545556575859606162636465666768697071727374757677788 unmodified lines8788899091929394959697989910010110210310410510610710810911011111211311411525 unmodified lines1411421431441451461471481491501511521531543 unmodified linesfrom bs4 import BeautifulSoupfrom urllib.parse import urljoinimport osimport re# Ensure your OpenAI API key is set in your environment variablesopenai.api_key = os.getenv("OPENAI_API_KEY")39 unmodified linesto_visit.append(full_url)except Exception:continuereturn " ".join(all_content[:3000]), scrape_successfuldef extract_location(content):"""Extract a possible location from the website content using regular expressions."""location_match = re.search(r'\b(?:serving|located in|offices in|based in)\s([\w\s,]+)', content, re.IGNORECASE)return location_match.group(1).strip() if location_match else None# Initial system message setupinitial_messages = [{"role": "system","content": """You are a world-class marketing strategist trained by Neil Patel, David Ogilvy, and Seth Godin.Your task is to create highly customized marketing plans based on user input. Incorporate any business locationor target areas explicitly mentioned in the website content or user-provided details into the recommendations.Go beyond generic suggestions, and include:- Specific, long-tail keywords to target.- Detailed content ideas, including blogs, videos, and social media campaigns.- Unique strategies tailored to the business's industry, goals, and location.- Innovative advertising campaigns and emerging platform recommendations.Ensure every suggestion is actionable and includes measurable KPIs."""}]def call_openai_api(messages):8 unmodified lines)return response["choices"][0]["message"]["content"]def generate_marketing_plan(website_content, industry, goals, budget, location, messages, fallback=False):"""Generates a marketing plan based on website content, industry, goals, and budget."""location_info = f"The business is located in {location}." if location else "No specific location was mentioned."query = f"""The user has provided the following details:- Website content: {website_content if not fallback else "N/A (website content could not be retrieved)"}- Industry: {industry}- Goals for 2025: {goals}- Marketing budget for 2025: ${budget}- {location_info}Create a detailed 1-year marketing plan that includes:1. **Advanced Keywords**: Long-tail keywords specific to the industry and location (if applicable).2. **Content Topics**: Blog and YouTube video topics that target the business's goals and location.3. **Social Media Strategies**: Platform recommendations, post frequency, and campaign ideas tailored to the location.4. **Advertising Campaigns**: Target audience, platforms, and budget breakdowns, integrating location-specific targeting.5. **Emerging Platforms**: Recommendations for new or underutilized platforms.6. **SEO Improvements**: Tools, techniques, and steps to improve search rankings.7. **Execution Plan**: Actionable, step-by-step instructions for implementation with quarterly timelines.Ensure all suggestions align with the business's strengths, and avoid generic or obvious recommendations."""messages.append({"role": "user", "content": query})return call_openai_api(messages)25 unmodified linesst.session_state["show_notice"] = Truewith st.spinner("Analyzing website content and preparing your report..."):website_content, scrape_successful = scrape_website(website_url) if website_url else ("", False)location = extract_location(website_content) if scrape_successful else Nonefallback_mode = not scrape_successfulif fallback_mode:st.warning("Unable to retrieve website content. Generating recommendations based on your input.")messages = initial_messages.copy()st.session_state["reply"] = generate_marketing_plan(website_content if scrape_successful else "N/A",industry, goals, budget, location, messages, fallback=fallback_mode)st.session_state["show_notice"] = False # Remove the notice once the report is ready
app.py+33-19