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 online using recommended media mix (Google Search Ads, Facebook Ads, SEO, SEM, etc.) using the following details: - Customer profile and what task or job they are trying to do: {customer_profile} - Problems and pain points that customers are currently facing while doing this task: {pain_points} - Customer needs and what they wish the solution (product or service) would have to make their lives easier: {customer_wishes} - 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, relieve their pain points, and meet or exceed their wishes: {solution_benefits} - What differentiates the solution from existing competitor offerings: {differentiators} - 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", 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.)", lines=2, ), gr.Textbox( label="Your 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, ), 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 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!) ", lines=2, ), gr.Textbox( label="Your Differentiators", 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.).", lines=2, ), gr.Textbox( label="Your 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=30), title="Keyworder", description="This app provides customized digital marketing strategy advice based on your input. 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)