Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,51 +7,55 @@ import gradio as gr
|
|
| 7 |
# Set OpenAI API key from environment variable
|
| 8 |
|
| 9 |
# Function to generate customized career advice
|
| 10 |
-
def
|
| 11 |
# Craft the prompt for the OpenAI model
|
| 12 |
-
prompt = f"""You are
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
-
|
| 16 |
-
-
|
| 17 |
-
-
|
|
|
|
|
|
|
|
|
|
| 18 |
Include:
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
Be concise and limit your response to 512 tokens or less."""
|
| 23 |
|
| 24 |
# Call the OpenAI API
|
| 25 |
try:
|
| 26 |
-
response = client.chat.completions.create(model="gpt-
|
| 27 |
messages=[
|
| 28 |
-
{"role": "system", "content": "You are a helpful and knowledgeable
|
| 29 |
{"role": "user", "content": prompt},
|
| 30 |
],
|
| 31 |
max_tokens=512,
|
| 32 |
temperature=0.7)
|
| 33 |
# Extract the response text
|
| 34 |
-
|
| 35 |
except Exception as e:
|
| 36 |
-
|
| 37 |
|
| 38 |
-
return
|
| 39 |
|
| 40 |
-
# Create Gradio interface for the
|
| 41 |
-
|
| 42 |
-
fn=
|
| 43 |
allow_flagging="never",
|
| 44 |
inputs=[
|
| 45 |
-
gr.Textbox(label="
|
| 46 |
-
gr.Textbox(label="
|
| 47 |
-
gr.Textbox(label="
|
| 48 |
-
gr.Textbox(label="
|
| 49 |
-
gr.Textbox(label="
|
|
|
|
| 50 |
],
|
| 51 |
-
outputs=gr.Textbox(label="Customized
|
| 52 |
-
title="
|
| 53 |
-
description="This app provides
|
| 54 |
)
|
| 55 |
|
| 56 |
# Launch the application
|
| 57 |
-
|
|
|
|
| 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 |
|
| 41 |
+
return keyword_advice
|
| 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)
|