File size: 4,013 Bytes
cac9eab
24b72ba
292fe8b
 
7409805
24b72ba
68833e7
8c614a4
68833e7
292fe8b
6ff8f56
292fe8b
 
 
 
 
 
 
 
 
 
 
 
6ff8f56
 
5436913
d06a517
5436913
d06a517
 
9ebb42b
d06a517
68833e7
d06a517
6ff8f56
5436913
 
 
 
faf6738
292fe8b
5436913
 
 
 
b3fd8d6
5436913
 
 
51ff7fb
 
6ff8f56
 
 
 
 
 
 
 
 
51ff7fb
830f5f1
 
 
6ff8f56
5436913
6ff8f56
 
 
 
5436913
 
 
 
 
 
6ff8f56
 
5436913
 
 
 
 
 
 
 
 
 
 
 
 
 
830f5f1
 
 
6ff8f56
5436913
830f5f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import streamlit as st
import openai
import requests
from bs4 import BeautifulSoup
import os

# Ensure your OpenAI API key is set in your environment variables
openai.api_key = os.environ["OPENAI_API_KEY"]

def scrape_website(url):
    """
    Scrapes the given website URL to extract business-related information.
    """
    try:
        response = requests.get(url)
        response.raise_for_status()
        soup = BeautifulSoup(response.content, "html.parser")
        
        # Extract meta description or a paragraph as a summary
        description = soup.find("meta", {"name": "description"}) or soup.find("p")
        return description.get("content") if description else "No description found."
    except Exception as e:
        return f"Error fetching website data: {e}"

def call_openai_api(messages):
    """
    Calls the OpenAI API using the updated interface for synchronous requests.
    """
    response = openai.ChatCompletion.create(
        model="gpt-4",  # Replace with "openai-o1" or your desired model
        messages=messages,
        max_tokens=1000
    )
    return response

def generate_marketing_plan(website_info, industry, goals, budget, messages):
    """
    Generates a marketing plan based on website information, industry, and user goals.
    """
    query = f"""
    The user has provided the following details:
    - Website information: {website_info}
    - Industry: {industry}
    - Goals for 2025: {goals}
    - Marketing budget for 2025: ${budget}
    
    Please create a comprehensive marketing plan for 2025. Include specific strategies 
    (e.g., content marketing, social media, advertising, SEO) and a timeline for implementing them.
    Highlight how the website's strengths can be leveraged to achieve the stated goals.
    """
    
    messages.append({"role": "user", "content": query})
    response = call_openai_api(messages)
    ChatGPT_reply = response["choices"][0]["message"]["content"]
    messages.append({"role": "assistant", "content": ChatGPT_reply})
    return ChatGPT_reply, messages

# Streamlit setup
st.set_page_config(layout="wide")

# Initialize session state
if "reply" not in st.session_state:
    st.session_state["reply"] = None

# Centered title
st.markdown("<h1 style='text-align: center; color: black;'>2025 Marketing Planner</h1>", unsafe_allow_html=True)

# User inputs
col1, col2 = st.columns(2)
with col1:
    st.markdown("<h2 style='text-align: center; color: black;'>Enter Business Details</h2>", unsafe_allow_html=True)
    website_url = st.text_input("Enter your business website", placeholder="https://example.com")
    industry = st.text_input("Industry", placeholder="E.g., Real Estate, Retail, Technology")
    goals = st.text_area("Goals for 2025", placeholder="E.g., increase brand awareness, drive online sales, expand audience")
    budget = st.number_input("Marketing Budget for 2025 ($)", min_value=1000, step=1000)
    generate_button = st.button('Generate Marketing Plan')

# Process results on button click
if generate_button and website_url:
    website_info = scrape_website(website_url)
    if "Error" not in website_info:
        messages = [{
            "role": "system",
            "content": """
            You are a marketing strategist specializing in creating detailed yearly plans. Based on provided website information,
            industry, goals, and budget, create a tailored 2025 marketing plan. Include strategies, a timeline, and how the 
            business's website strengths can be used to achieve success.
            """
        }]
        st.session_state["reply"], _ = generate_marketing_plan(website_info, industry, goals, budget, messages)
    else:
        st.session_state["reply"] = website_info

# Display results if there is a reply in session state
if st.session_state["reply"]:
    with col2:
        st.markdown("<h2 style='text-align: center; color: black;'>Your 2025 Marketing Plan ⬇️</h2>", unsafe_allow_html=True)
        st.write(st.session_state["reply"])