Step-by-Step Implementation of Copy.ai
About Copy.ai
Copy.ai uses LLMs to generate:
- Social media captions
- Product descriptions
- Ad headlines
- Slogans
- Email hooks
...based on minimal user input (product, tone, audience).
We’ll build this functionality step-by-step using OpenAI GPT API, Python, and Gradio UI.
Step 1: Install Required Libraries
pip install openai gradio
Step 2: Set OpenAI API Key
import openai
openai.api_key = "YOUR_OPENAI_API_KEY"
Step 3: Define Templates for Content Types
templates = {
"Product Description": "Write a product description for '{product}' targeting {audience}. Tone: {tone}.",
"Instagram Caption": "Write an Instagram caption for '{product}' targeting {audience} in a {tone} tone. Include hashtags.",
"Facebook Ad Copy": "Write a Facebook ad copy for '{product}' targeting {audience} with a {tone} tone.",
"Slogan Generator": "Create a catchy slogan for '{product}' in a {tone} tone.",
"Email Hook": "Write an email hook for a product called '{product}' aimed at {audience}. Tone: {tone}."
}
Step 4: Generate Content Using GPT
def generate_copy(template_type, product, audience, tone):
prompt = templates[template_type].format(product=product, audience=audience, tone=tone)
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a marketing copywriter."},
{"role": "user", "content": prompt}
],
max_tokens=150,
temperature=0.8,
top_p=0.95
)
return response.choices[0].message["content"].strip()
Step 5: Try Generating Copy (With Output)
Example:
print(generate_copy("Slogan Generator", "Plant-based Protein Shake", "fitness enthusiasts", "energetic"))
🖥️ Output:
"Fuel Your Gains, Naturally."
Try another one:
print(generate_copy("Instagram Caption", "Wireless Earbuds", "young professionals", "modern"))
🖥️ Output:
Cut the wires, not the vibes. 🎧✨
#WirelessFreedom #ModernSound #WorkFromAnywhere
🖥️ Step 6: Build Copy.ai-Like Gradio UI
import gradio as gr
def app(template_type, product, audience, tone):
return generate_copy(template_type, product, audience, tone)
gr.Interface(
fn=app,
inputs=[
gr.Dropdown(list(templates.keys()), label="Select Content Type"),
gr.Textbox(label="Product/Service"),
gr.Textbox(label="Target Audience"),
gr.Dropdown(["funny", "professional", "casual", "energetic", "inspirational"], label="Tone")
],
outputs=gr.Textbox(label="Generated Copy"),
title="Copy.ai Clone - AI Marketing Assistant",
description="Enter product info and get instant AI-generated ad copy, captions, slogans, and more."
).launch()
Final Output Example
Input:
- Template: Product Description
- Product: Bamboo Toothbrush
- Audience: Eco-conscious millennials
- Tone: Professional
Generated Output:
Introducing the Bamboo Toothbrush — a sustainable choice for eco-conscious millennials. Crafted from biodegradable bamboo, it’s durable, lightweight, and a step forward in your zero-waste journey.
Project Folder Structure
copyai-clone/
│
├── copy_templates.py # Template dictionary
├── generate.py # Prompt generation and model code
├── ui.py # Gradio interface
├── requirements.txt
Optional Add-ons (Advanced Features):
Feature | Tools to Use |
---|---|
User login | Firebase / Supabase |
Save copy history | SQLite / Firebase |
SEO scoring | Yoast, SEMrush API |
A/B test outputs | Store multiple generations |
Custom tone tuning | Prompt tuning / fine-tuning |
Translate to other languages | DeepL / Google Translate API |
Summary Table of Inputs & Outputs
Content Type | Input Example | Output Example |
---|---|---|
Slogan Generator | Plant-based Protein | “Fuel Your Gains, Naturally.” |
Instagram Caption | Wireless Earbuds + Modern | “Cut the wires, not the vibes. 🎧✨ #Wireless...” |
Email Hook | Running Shoes + Athletes | “Ready to outrun your goals? Let’s get moving...” |
Conclusion
You’ve just built a working Copy.ai clone with:
- Multi-template selection
- Custom tone & audience options
- GPT-powered generation
Live working UI using Gradio
Next Blog- Part 1- Tools for Text-Based AI: Grammarly