nniehaus commited on
Commit
cb47839
·
verified ·
1 Parent(s): 730007c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -24
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.environ["OPENAI_API_KEY"]
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 a paragraph as a summary
20
- description = soup.find("meta", {"name": "description"}) or soup.find("p")
21
- return description.get("content") if description else "No description found."
 
 
 
 
22
  except Exception as e:
23
  return f"Error fetching website data: {e}"
24
 
25
- def call_openai_api(messages):
26
  """
27
  Calls the OpenAI API using the updated interface for synchronous requests.
28
  """
29
- response = openai.Chat.create(
30
- model="gpt-4", # Replace with your desired model
31
- messages=messages,
32
  max_tokens=1000,
33
  temperature=0.7
34
  )
35
- return response.choices[0].message.content.strip()
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
- messages = [
42
- {"role": "system", "content": "You are a marketing strategist."},
43
- {"role": "user", "content": f"""
44
- The user has provided the following details:
45
- - Website information: {website_info}
46
- - Industry: {industry}
47
- - Goals for 2025: {goals}
48
- - Marketing budget for 2025: ${budget}
49
-
50
- Please create a comprehensive marketing plan for 2025. Include specific strategies
51
- (e.g., content marketing, social media, advertising, SEO) and a timeline for implementing them.
52
- Highlight how the website's strengths can be leveraged to achieve the stated goals.
53
- """}
54
- ]
55
 
56
- return call_openai_api(messages)
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")