Spaces:
Running
Running
import os | |
from openai import OpenAI | |
# Set OpenAI API key from environment variable | |
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) | |
import gradio as gr | |
# Function to generate customized keywords | |
def generate_keywords(customer_profile, pain_points, customer_wishes, brand_name, solution_benefits, differentiators, goal): | |
# Craft the prompt for the OpenAI model | |
prompt = f"""You are an experienced digital marketing specialist AI. | |
Provide customized digital marketing strategy recommendations for a producer or service provider (user of the chatbot) | |
who wishes to market their product or service online using recommended media mix (Google Search Ads, Facebook Ads, SEO, SEM, etc.) using the following details: | |
- Their customer profile and what task or job they are trying to do: {customer_profile} | |
- Problems, pain points, needs, preferences and wishes that their customers have while trying to do the task: {pain_points} | |
- Brand name (suggest a brand name and a slogan if the user doesn't yet have them): {brand_name} | |
- What the solution (product or service) offers to solve customer problems, pain points, needs, wishes and how they are different from the competition: {solution_benefits} | |
- They main marketing goal the service provider (user of the chatbot) wishes to pursue: {goal} | |
Include: | |
- Digital marketing strategy and media mix. | |
- 3 options for a catchy headline for a Google Search Ad and or a social media Ad (recommend). | |
- 3 options for online ad descriptions to match the above headlines in the recommended media. | |
- 10 recommended keywords to use in the recommended media. | |
Be concise and limit your response to 512 tokens or less.""" | |
try: | |
# Call the OpenAI API | |
response = client.chat.completions.create( | |
model="gpt-4o-mini", # Replace with "gpt-3.5-turbo" if needed | |
messages=[ | |
{"role": "system", "content": "You are a helpful and knowledgeable digital marketing strategist."}, | |
{"role": "user", "content": prompt}, | |
], | |
max_tokens=512, | |
temperature=0.7, | |
) | |
# Extract the response text | |
keyword_advice = response.choices[0].message.content.strip() | |
except Exception as e: | |
keyword_advice = f"An error occurred: {str(e)}" | |
return keyword_advice | |
# Create Gradio interface for the keyworder application | |
keyworder_app = gr.Interface( | |
fn=generate_keywords, | |
allow_flagging="never", | |
inputs=[ | |
gr.Textbox( | |
label="Your 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, | |
), | |
gr.Textbox( | |
label="Your Customer Pain Points, Needs, Wishes, and Preferences ", | |
placeholder="Identify problems, pain points, needs, wishes and preferences of your customers. (e.g., When busy they are worried about their pets and feel guilty.)", | |
lines=2, | |
), | |
gr.Textbox( | |
label="Your Brand Name", | |
placeholder="List your brand name and slogan (e.g., InstaPet, where you are always with your pet.) or request suggestions.", | |
lines=2, | |
), | |
gr.Textbox( | |
label="Benefits and Differentiators of your Solution", | |
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! Our pet-care-providers love pets and will help you say hi to your pet via our secure network.) ", | |
lines=2, | |
), | |
gr.Textbox( | |
label="Marketing Goal", | |
placeholder="What is your main marketing goal (e.g., Boost awareness by reaching 10000 potential customers in 2 months, 2000 website visits by end of Q1, 500 conversions by end of Q2, etc.).", | |
lines=2, | |
), | |
], | |
outputs=gr.Textbox(label="Customized Digital Marketing Advice", lines=25), | |
title="Digital Marketer", | |
description="This app provides customized digital marketing strategy advice based on your inputs. Powered by OpenAI GPT 4, Design Thinking and domain expertise. Developed by wn. Disclaimer: AI makes mistakes. Use with caution and at your own risk!", | |
) | |
# Launch the application | |
if __name__ == "__main__": | |
keyworder_app.launch(server_name="0.0.0.0", debug=True, share=True) | |