Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,46 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
-
import requests
|
4 |
-
from bs4 import BeautifulSoup
|
5 |
import os
|
6 |
|
7 |
# Ensure your OpenAI API key is set in your environment variables
|
8 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
"""
|
14 |
-
|
15 |
-
response = requests.get(url)
|
16 |
-
response.raise_for_status()
|
17 |
-
soup = BeautifulSoup(response.content, "html.parser")
|
18 |
-
|
19 |
-
# Extract meta description or the first paragraph as a summary
|
20 |
-
description = soup.find("meta", {"name": "description"})
|
21 |
-
if description and description.get("content"):
|
22 |
-
return description["content"]
|
23 |
-
else:
|
24 |
-
paragraph = soup.find("p")
|
25 |
-
return paragraph.get_text(strip=True) if paragraph else "No description found."
|
26 |
-
except Exception as e:
|
27 |
-
return f"Error fetching website data: {e}"
|
28 |
|
29 |
-
def call_openai_api(
|
30 |
"""
|
31 |
-
Calls the OpenAI API
|
32 |
"""
|
33 |
-
response = openai.
|
34 |
-
model="
|
35 |
-
|
36 |
max_tokens=1000,
|
37 |
temperature=0.7
|
38 |
)
|
39 |
-
return response
|
40 |
|
41 |
-
def generate_marketing_plan(website_info, industry, goals, budget):
|
42 |
"""
|
43 |
Generates a marketing plan based on website information, industry, and user goals.
|
44 |
"""
|
45 |
-
|
46 |
The user has provided the following details:
|
47 |
- Website information: {website_info}
|
48 |
- Industry: {industry}
|
49 |
- Goals for 2025: {goals}
|
50 |
- Marketing budget for 2025: ${budget}
|
51 |
-
|
52 |
-
|
53 |
(e.g., content marketing, social media, advertising, SEO) and a timeline for implementing them.
|
54 |
Highlight how the website's strengths can be leveraged to achieve the stated goals.
|
55 |
"""
|
56 |
|
57 |
-
|
|
|
58 |
|
59 |
# Streamlit setup
|
60 |
st.set_page_config(layout="wide")
|
@@ -70,22 +56,13 @@ st.markdown("<h1 style='text-align: center; color: black;'>2025 Marketing Planne
|
|
70 |
col1, col2 = st.columns(2)
|
71 |
with col1:
|
72 |
st.markdown("<h2 style='text-align: center; color: black;'>Enter Business Details</h2>", unsafe_allow_html=True)
|
73 |
-
|
74 |
industry = st.text_input("Industry", placeholder="E.g., Real Estate, Retail, Technology")
|
75 |
-
goals = st.text_area("Goals for 2025", placeholder="E.g., increase brand awareness, drive online sales
|
76 |
budget = st.number_input("Marketing Budget for 2025 ($)", min_value=1000, step=1000)
|
77 |
generate_button = st.button('Generate Marketing Plan')
|
78 |
|
79 |
# Process results on button click
|
80 |
-
if generate_button and
|
81 |
-
|
82 |
-
|
83 |
-
st.session_state["reply"] = generate_marketing_plan(website_info, industry, goals, budget)
|
84 |
-
else:
|
85 |
-
st.session_state["reply"] = website_info
|
86 |
-
|
87 |
-
# Display results if there is a reply in session state
|
88 |
-
if st.session_state["reply"]:
|
89 |
-
with col2:
|
90 |
-
st.markdown("<h2 style='text-align: center; color: black;'>Your 2025 Marketing Plan ⬇️</h2>", unsafe_allow_html=True)
|
91 |
-
st.write(st.session_state["reply"])
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
|
|
|
|
3 |
import os
|
4 |
|
5 |
# Ensure your OpenAI API key is set in your environment variables
|
6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
+
# Initial system message setup
|
9 |
+
initial_messages = [{
|
10 |
+
"role": "system",
|
11 |
+
"content": "You are a marketing strategist who creates detailed yearly plans based on provided inputs."
|
12 |
+
}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
def call_openai_api(messages):
|
15 |
"""
|
16 |
+
Calls the OpenAI ChatCompletion API with the correct format.
|
17 |
"""
|
18 |
+
response = openai.ChatCompletion.create(
|
19 |
+
model="gpt-4", # Ensure you're using the correct model
|
20 |
+
messages=messages,
|
21 |
max_tokens=1000,
|
22 |
temperature=0.7
|
23 |
)
|
24 |
+
return response["choices"][0]["message"]["content"]
|
25 |
|
26 |
+
def generate_marketing_plan(website_info, industry, goals, budget, messages):
|
27 |
"""
|
28 |
Generates a marketing plan based on website information, industry, and user goals.
|
29 |
"""
|
30 |
+
query = f"""
|
31 |
The user has provided the following details:
|
32 |
- Website information: {website_info}
|
33 |
- Industry: {industry}
|
34 |
- Goals for 2025: {goals}
|
35 |
- Marketing budget for 2025: ${budget}
|
36 |
+
|
37 |
+
Create a comprehensive marketing plan for 2025. Include specific strategies
|
38 |
(e.g., content marketing, social media, advertising, SEO) and a timeline for implementing them.
|
39 |
Highlight how the website's strengths can be leveraged to achieve the stated goals.
|
40 |
"""
|
41 |
|
42 |
+
messages.append({"role": "user", "content": query})
|
43 |
+
return call_openai_api(messages)
|
44 |
|
45 |
# Streamlit setup
|
46 |
st.set_page_config(layout="wide")
|
|
|
56 |
col1, col2 = st.columns(2)
|
57 |
with col1:
|
58 |
st.markdown("<h2 style='text-align: center; color: black;'>Enter Business Details</h2>", unsafe_allow_html=True)
|
59 |
+
website_info = st.text_input("Website Information", placeholder="Provide key details or a URL")
|
60 |
industry = st.text_input("Industry", placeholder="E.g., Real Estate, Retail, Technology")
|
61 |
+
goals = st.text_area("Goals for 2025", placeholder="E.g., increase brand awareness, drive online sales")
|
62 |
budget = st.number_input("Marketing Budget for 2025 ($)", min_value=1000, step=1000)
|
63 |
generate_button = st.button('Generate Marketing Plan')
|
64 |
|
65 |
# Process results on button click
|
66 |
+
if generate_button and website_info:
|
67 |
+
messages = initial_messages.copy()
|
68 |
+
st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|