willn9 commited on
Commit
40ff22e
·
verified ·
1 Parent(s): 4d92904

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -38
app.py CHANGED
@@ -1,40 +1,43 @@
1
  import os
2
- from openai import OpenAI
3
-
4
- client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
5
  import gradio as gr
6
 
7
  # Set OpenAI API key from environment variable
 
8
 
9
- # Function to generate customized career advice
10
- def generate_kewords(customer_profile, pain_points, customer_wishes, brand_name, solution_benefits, differentiators):
11
  # Craft the prompt for the OpenAI model
12
  prompt = f"""You are an experienced digital marketing specialist AI.
13
- Provide customized keyword recommendations for a producer or service provider, owner of the brand listed below,
14
- who wishes to market their product online using Google Search Ads, using the following details:
15
- - Customer profile and what task or job they are trying to do: {customer_profile}
16
- - Problems and pain points that customers are currently facing while doing this task: {pain_points}
17
- - Customer needs and what they wish the solution (product or service) would have to make their lives easier: {customer_wishes}
18
- - Brand name (suggest a brand name and a slogan if the user don't yet have them): {brand_name}
19
- - What does your solution (product or service) offer to solve their problems, relieve their pain points and meet or exceed their wishes: {solution_benefits}
20
- - What differentiates your solution for existing competitor offerings: {differentiators}
21
- Include:
22
- - 3 options for a catchy headline for a Google Search Ad.
23
- - 3 options for Google Search Ad description each to match the above headline.
24
- - 15 Recommended keywords to use in Google Search Ad.
25
- Be concise and limit your response to 512 tokens or less."""
26
-
27
- # Call the OpenAI API
 
28
  try:
29
- response = client.chat.completions.create(model="gpt-4 # Use "gpt-3.5-turbo" if desired
30
- messages=[
31
- {"role": "system", "content": "You are a helpful and knowledgeable digital marketing strategist."},
32
- {"role": "user", "content": prompt},
33
- ],
34
- max_tokens=512,
35
- temperature=0.7)
 
 
 
36
  # Extract the response text
37
- keyword_advice = response.choices[0].message.content.strip()
38
  except Exception as e:
39
  keyword_advice = f"An error occurred: {str(e)}"
40
 
@@ -42,20 +45,45 @@ def generate_kewords(customer_profile, pain_points, customer_wishes, brand_name,
42
 
43
  # Create Gradio interface for the keyworder application
44
  keyworder_app = gr.Interface(
45
- fn=generate_kewords,
46
  allow_flagging="never",
47
  inputs=[
48
- gr.Textbox(label="Customer Profile", placeholder="Describe your customer and what task or job they are trying to do. (e.g., My customer is a busy executive on the go. They have a pet whom they love dearly. They want to make sure that their pet is always taken care of even when they are busy or delayed at work.).", lines=2),
49
- gr.Textbox(label="Customer Pain Points", placeholder="Identify problems and pain points that your customers are currently facing while they are trying to accomplish the above task. (e.g., Sometimes, they are held up late at work or by traffic. They are worried about their pets and feel guilty.)", lines=2),
50
- gr.Textbox(label="Customer Needs and Wishes", placeholder="Describe your customers' needs and wishes (e.g., They need someone reliable to check on their pets, walk them, ensure that that they have food and water, etc. They wish they could see their pets, make sure they are OK and say hi to them via their phones.).", lines=2),
51
- gr.Textbox(label="Brand Name", placeholder="List your brand name and slogan. (e.g., InstaPet, where you are always with your pet.) or enter don't have them yet please suggest.", lines=2),
52
- gr.Textbox(label="Benefits of your Solution", placeholder="Enter key benefits that your product or service offers to solve customer problems (e.g., You can always rely on our network of pet lovers to care for your pet while you are held up at work or other commitments!)", lines=2),
53
- gr.Textbox(label="Differentiators", placeholder="List what differentiate you from the competition (e.g., Our pet-care-providers love pets and will help you say hi to your pet via our secure network.)", lines=2),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  ],
55
  outputs=gr.Textbox(label="Customized Digital Marketing Advice"),
56
- title="AI-Powered Keyworder, by wn",
57
- description="This app provides customized digital marketing advice based on your input. Powered by AI and domain knowledge expertise! Caution: even AI can make mistakes!",
58
  )
59
 
60
  # Launch the application
61
- keyworder_app.launch(server_name="0.0.0.0", debug=True, share=True)
 
 
1
  import os
2
+ import openai
 
 
3
  import gradio as gr
4
 
5
  # Set OpenAI API key from environment variable
6
+ openai.api_key = os.environ.get("OPENAI_API_KEY")
7
 
8
+ # Function to generate customized keywords
9
+ def generate_keywords(customer_profile, pain_points, customer_wishes, brand_name, solution_benefits, differentiators):
10
  # Craft the prompt for the OpenAI model
11
  prompt = f"""You are an experienced digital marketing specialist AI.
12
+ Provide customized keyword recommendations for a producer or service provider, owner of the brand listed below,
13
+ who wishes to market their product online using Google Search Ads, using the following details:
14
+ - Customer profile and what task or job they are trying to do: {customer_profile}
15
+ - Problems and pain points that customers are currently facing while doing this task: {pain_points}
16
+ - Customer needs and what they wish the solution (product or service) would have to make their lives easier: {customer_wishes}
17
+ - Brand name (suggest a brand name and a slogan if the user doesn't yet have them): {brand_name}
18
+ - What does your solution (product or service) offer to solve their problems, relieve their pain points, and meet or exceed their wishes: {solution_benefits}
19
+ - What differentiates your solution from existing competitor offerings: {differentiators}
20
+
21
+ Include:
22
+ - 3 options for a catchy headline for a Google Search Ad.
23
+ - 3 options for Google Search Ad descriptions to match the above headlines.
24
+ - 15 recommended keywords to use in Google Search Ads.
25
+
26
+ Be concise and limit your response to 512 tokens or less."""
27
+
28
  try:
29
+ # Call the OpenAI API
30
+ response = openai.ChatCompletion.create(
31
+ model="gpt-4", # Replace with "gpt-3.5-turbo" if needed
32
+ messages=[
33
+ {"role": "system", "content": "You are a helpful and knowledgeable digital marketing strategist."},
34
+ {"role": "user", "content": prompt},
35
+ ],
36
+ max_tokens=512,
37
+ temperature=0.7,
38
+ )
39
  # Extract the response text
40
+ keyword_advice = response["choices"][0]["message"]["content"].strip()
41
  except Exception as e:
42
  keyword_advice = f"An error occurred: {str(e)}"
43
 
 
45
 
46
  # Create Gradio interface for the keyworder application
47
  keyworder_app = gr.Interface(
48
+ fn=generate_keywords,
49
  allow_flagging="never",
50
  inputs=[
51
+ gr.Textbox(
52
+ label="Customer Profile",
53
+ placeholder="Describe your customer and what task or job they are trying to do. (e.g., My customer is a busy executive on the go. They have a pet whom they love dearly. They want to make sure that their pet is always taken care of even when they are busy or delayed at work.)",
54
+ lines=2,
55
+ ),
56
+ gr.Textbox(
57
+ label="Customer Pain Points",
58
+ placeholder="Identify problems and pain points your customers are facing. (e.g., Sometimes, they are held up late at work or by traffic. They are worried about their pets and feel guilty.",
59
+ lines=2,
60
+ ),
61
+ gr.Textbox(
62
+ label="Customer Needs and Wishes",
63
+ placeholder="Describe your customers' needs and wishes. (e.g., They need someone reliable to check on their pets, walk them, ensure that that they have food and water, etc. They wish they could see their pets, make sure they are OK and say hi to them via their phones.)",
64
+ lines=2,
65
+ ),
66
+ gr.Textbox(
67
+ label="Brand Name",
68
+ placeholder="List your brand name and slogan (e.g., InstaPet, where you are always with your pet.) or request suggestions.",
69
+ lines=2,
70
+ ),
71
+ gr.Textbox(
72
+ label="Benefits of your Solution",
73
+ placeholder="Enter key benefits your product or service offers. (e.g., You can always rely on our network of pet lovers to care for your pet while you are held up at work or other commitments!) ",
74
+ lines=2,
75
+ ),
76
+ gr.Textbox(
77
+ label="Differentiators",
78
+ placeholder="List what differentiates you from the competition.(e.g., Our pet-care-providers love pets and will help you say hi to your pet via our secure network.).",
79
+ lines=2,
80
+ ),
81
  ],
82
  outputs=gr.Textbox(label="Customized Digital Marketing Advice"),
83
+ title="AI-Powered Keyworder by wn",
84
+ description="This app provides customized digital marketing advice based on your input. Powered by AI and domain expertise! Note: Even AI can make mistakes!",
85
  )
86
 
87
  # Launch the application
88
+ if __name__ == "__main__":
89
+ keyworder_app.launch(server_name="0.0.0.0", debug=True, share=True)