Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ 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.
|
| 9 |
|
| 10 |
def scrape_website(url):
|
| 11 |
"""
|
|
@@ -16,44 +16,45 @@ def scrape_website(url):
|
|
| 16 |
response.raise_for_status()
|
| 17 |
soup = BeautifulSoup(response.content, "html.parser")
|
| 18 |
|
| 19 |
-
# Extract meta description or
|
| 20 |
-
description = soup.find("meta", {"name": "description"})
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
return f"Error fetching website data: {e}"
|
| 24 |
|
| 25 |
-
def call_openai_api(
|
| 26 |
"""
|
| 27 |
Calls the OpenAI API using the updated interface for synchronous requests.
|
| 28 |
"""
|
| 29 |
-
response = openai.
|
| 30 |
-
model="
|
| 31 |
-
|
| 32 |
max_tokens=1000,
|
| 33 |
temperature=0.7
|
| 34 |
)
|
| 35 |
-
return response.choices[0].
|
| 36 |
|
| 37 |
def generate_marketing_plan(website_info, industry, goals, budget):
|
| 38 |
"""
|
| 39 |
Generates a marketing plan based on website information, industry, and user goals.
|
| 40 |
"""
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
Highlight how the website's strengths can be leveraged to achieve the stated goals.
|
| 53 |
-
"""}
|
| 54 |
-
]
|
| 55 |
|
| 56 |
-
return call_openai_api(
|
| 57 |
|
| 58 |
# Streamlit setup
|
| 59 |
st.set_page_config(layout="wide")
|
|
|
|
| 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 |
def scrape_website(url):
|
| 11 |
"""
|
|
|
|
| 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(prompt):
|
| 30 |
"""
|
| 31 |
Calls the OpenAI API using the updated interface for synchronous requests.
|
| 32 |
"""
|
| 33 |
+
response = openai.Completion.create(
|
| 34 |
+
model="text-davinci-003", # Replace with your desired model
|
| 35 |
+
prompt=prompt,
|
| 36 |
max_tokens=1000,
|
| 37 |
temperature=0.7
|
| 38 |
)
|
| 39 |
+
return response.choices[0].text.strip()
|
| 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 |
+
prompt = f"""
|
| 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 |
+
Please create a comprehensive marketing plan for 2025. Include specific strategies
|
| 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 |
+
return call_openai_api(prompt)
|
| 58 |
|
| 59 |
# Streamlit setup
|
| 60 |
st.set_page_config(layout="wide")
|