Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,43 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 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
|
| 10 |
-
def
|
| 11 |
# Craft the prompt for the OpenAI model
|
| 12 |
prompt = f"""You are an experienced digital marketing specialist AI.
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
try:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
# Extract the response text
|
| 37 |
-
keyword_advice = response
|
| 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=
|
| 46 |
allow_flagging="never",
|
| 47 |
inputs=[
|
| 48 |
-
gr.Textbox(
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
],
|
| 55 |
outputs=gr.Textbox(label="Customized Digital Marketing Advice"),
|
| 56 |
-
title="AI-Powered Keyworder
|
| 57 |
-
description="This app provides customized digital marketing advice based on your input. Powered by AI and domain
|
| 58 |
)
|
| 59 |
|
| 60 |
# Launch the application
|
| 61 |
-
|
|
|
|
|
|
| 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)
|