Create app.py
Browse files
app.py
CHANGED
|
@@ -63,43 +63,60 @@ def analyze_subject_line(subject_line):
|
|
| 63 |
return analysis
|
| 64 |
|
| 65 |
def generate_subject_lines_advanced(audience, message, tone, psychology_framework, industry, personalization, client):
|
| 66 |
-
"""Generate
|
| 67 |
try:
|
| 68 |
-
|
| 69 |
-
"FOMO (Fear of Missing Out)": "Create urgency
|
| 70 |
-
"Curiosity Gap": "
|
| 71 |
-
"Social Proof": "
|
| 72 |
-
"Loss Aversion": "Frame what they
|
| 73 |
-
"Reciprocity": "
|
| 74 |
-
"Authority": "Reference experts, data,
|
| 75 |
-
"Scarcity": "Emphasize limited availability
|
| 76 |
}
|
| 77 |
|
| 78 |
-
prompt_text = f"""You are
|
| 79 |
|
| 80 |
-
Context:
|
| 81 |
-
- Audience: {audience}
|
| 82 |
-
- Message: {message}
|
| 83 |
-
- Tone: {tone}
|
| 84 |
-
-
|
| 85 |
-
- Industry: {industry}
|
| 86 |
-
- Personalization: {personalization}
|
| 87 |
|
| 88 |
-
|
| 89 |
-
- Keep subject lines 2-4 words (33 characters max for mobile)
|
| 90 |
-
- Include numbers when relevant (+45% open rates)
|
| 91 |
-
- Use 1 emoji max where appropriate (+39% opens)
|
| 92 |
-
- Apply {psychology_framework} authentically
|
| 93 |
-
- Create matching preheaders that complement the subject
|
| 94 |
|
| 95 |
-
|
| 96 |
-
**Subject Line 1:** [subject]
|
| 97 |
-
**Preheader 1:** [preheader]
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
if OPENAI_V1:
|
| 105 |
response = client.chat.completions.create(
|
|
@@ -123,53 +140,66 @@ Continue for all 10. Keep it clean and scannable."""
|
|
| 123 |
return None
|
| 124 |
|
| 125 |
def optimize_existing_subject_line_clean(existing_subject, existing_preheader, audience, message, tone, psychology_framework, industry, personalization, client):
|
| 126 |
-
"""
|
| 127 |
try:
|
| 128 |
analysis = analyze_subject_line(existing_subject)
|
| 129 |
preheader_text = f"Current preheader: {existing_preheader}" if existing_preheader else "No preheader provided"
|
| 130 |
|
| 131 |
-
prompt_text = f"""
|
| 132 |
|
| 133 |
-
|
|
|
|
| 134 |
{preheader_text}
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
-
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
-
-
|
| 147 |
-
-
|
| 148 |
-
-
|
| 149 |
-
-
|
| 150 |
-
-
|
| 151 |
|
| 152 |
-
|
| 153 |
|
| 154 |
-
**Current
|
| 155 |
-
"{existing_subject}" (Score: {analysis['score']}/10)
|
| 156 |
|
| 157 |
-
**
|
| 158 |
-
|
| 159 |
|
| 160 |
-
**
|
| 161 |
-
|
| 162 |
|
| 163 |
-
**
|
| 164 |
-
|
| 165 |
|
| 166 |
-
**
|
| 167 |
-
|
| 168 |
|
| 169 |
-
**
|
| 170 |
-
|
| 171 |
|
| 172 |
-
|
| 173 |
|
| 174 |
if OPENAI_V1:
|
| 175 |
response = client.chat.completions.create(
|
|
|
|
| 63 |
return analysis
|
| 64 |
|
| 65 |
def generate_subject_lines_advanced(audience, message, tone, psychology_framework, industry, personalization, client):
|
| 66 |
+
"""Generate high-quality, compelling subject lines"""
|
| 67 |
try:
|
| 68 |
+
framework_strategies = {
|
| 69 |
+
"FOMO (Fear of Missing Out)": "Create genuine urgency and scarcity. Use time-sensitive language, countdown elements, or limited availability",
|
| 70 |
+
"Curiosity Gap": "Create compelling information gaps that demand closure. Hint at valuable secrets, surprising revelations, or counterintuitive insights",
|
| 71 |
+
"Social Proof": "Leverage what others are doing - specific user numbers, testimonials, trending status, or peer behavior",
|
| 72 |
+
"Loss Aversion": "Frame what they're currently missing or losing rather than what they could gain",
|
| 73 |
+
"Reciprocity": "Lead with valuable gifts, free resources, or helpful insights before asking for anything",
|
| 74 |
+
"Authority": "Reference credible experts, research data, proven methodologies, or industry leadership",
|
| 75 |
+
"Scarcity": "Emphasize genuine limited availability, exclusive access, or member-only benefits"
|
| 76 |
}
|
| 77 |
|
| 78 |
+
prompt_text = f"""You are a world-class email copywriter who has written subject lines for the highest-performing email campaigns. Your subject lines are known for being irresistibly compelling while staying authentic.
|
| 79 |
|
| 80 |
+
Campaign Context:
|
| 81 |
+
- Target Audience: {audience}
|
| 82 |
+
- Core Message: {message}
|
| 83 |
+
- Brand Tone: {tone}
|
| 84 |
+
- Psychological Strategy: {psychology_framework}
|
| 85 |
+
- Industry Context: {industry}
|
| 86 |
+
- Personalization Approach: {personalization}
|
| 87 |
|
| 88 |
+
Advanced Strategy: {framework_strategies.get(psychology_framework, '')}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
Your Mission: Create 10 subject lines that would make someone instantly stop scrolling and click. Each should feel fresh, compelling, and impossible to ignore.
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
Critical Requirements:
|
| 93 |
+
1. Maximum 33 characters (mobile-first optimization)
|
| 94 |
+
2. 2-4 words for maximum impact
|
| 95 |
+
3. Apply {psychology_framework} psychology masterfully, not obviously
|
| 96 |
+
4. Include power words that trigger emotional response
|
| 97 |
+
5. Use numbers strategically (proven to increase opens by 45%)
|
| 98 |
+
6. Add 1 relevant emoji only if it genuinely enhances appeal
|
| 99 |
+
7. Make each line feel unique and scroll-stopping
|
| 100 |
+
8. Avoid clichés, generic phrases, or obvious sales language
|
| 101 |
|
| 102 |
+
Examples of compelling techniques:
|
| 103 |
+
- Specific numbers: "2-min trick", "73% faster", "$847 saved"
|
| 104 |
+
- Intriguing questions: "Still doing this?", "Why {specific thing}?"
|
| 105 |
+
- Surprising statements: "We're wrong", "This failed", "Oops..."
|
| 106 |
+
- Personal urgency: "Your {specific thing}", "Behind schedule?", "Missing this?"
|
| 107 |
+
|
| 108 |
+
CRITICAL: Output format must be exactly:
|
| 109 |
+
|
| 110 |
+
**1.** [subject line]
|
| 111 |
+
[preheader text]
|
| 112 |
+
|
| 113 |
+
**2.** [subject line]
|
| 114 |
+
[preheader text]
|
| 115 |
+
|
| 116 |
+
**3.** [subject line]
|
| 117 |
+
[preheader text]
|
| 118 |
+
|
| 119 |
+
Continue for all 10 options. Make each subject line feel like it was crafted by a master copywriter, not an AI tool."""
|
| 120 |
|
| 121 |
if OPENAI_V1:
|
| 122 |
response = client.chat.completions.create(
|
|
|
|
| 140 |
return None
|
| 141 |
|
| 142 |
def optimize_existing_subject_line_clean(existing_subject, existing_preheader, audience, message, tone, psychology_framework, industry, personalization, client):
|
| 143 |
+
"""Advanced optimization with superior subject lines"""
|
| 144 |
try:
|
| 145 |
analysis = analyze_subject_line(existing_subject)
|
| 146 |
preheader_text = f"Current preheader: {existing_preheader}" if existing_preheader else "No preheader provided"
|
| 147 |
|
| 148 |
+
prompt_text = f"""You are an elite email optimization specialist who transforms mediocre subject lines into irresistible ones. Your optimizations consistently achieve 40%+ higher open rates.
|
| 149 |
|
| 150 |
+
CURRENT SUBJECT LINE ANALYSIS:
|
| 151 |
+
"{existing_subject}"
|
| 152 |
{preheader_text}
|
| 153 |
+
Length: {analysis['character_count']} characters, {analysis['word_count']} words
|
| 154 |
+
Mobile Preview: "{analysis['mobile_preview']}"
|
| 155 |
+
Current Effectiveness Score: {analysis['score']}/10
|
| 156 |
+
|
| 157 |
+
OPTIMIZATION BRIEF:
|
| 158 |
+
- Target Audience: {audience}
|
| 159 |
+
- Core Message: {message}
|
| 160 |
+
- Desired Tone: {tone}
|
| 161 |
+
- Psychology to Apply: {psychology_framework}
|
| 162 |
+
- Industry Context: {industry}
|
| 163 |
+
- Personalization Strategy: {personalization}
|
| 164 |
+
|
| 165 |
+
YOUR MISSION: Transform this into 5 compelling alternatives that would dramatically outperform the original.
|
| 166 |
|
| 167 |
+
Advanced Optimization Strategies:
|
| 168 |
+
1. Apply {psychology_framework} psychology masterfully
|
| 169 |
+
2. Maximize mobile impact (33 characters max)
|
| 170 |
+
3. Use power words that trigger immediate action
|
| 171 |
+
4. Include specific numbers or percentages when relevant
|
| 172 |
+
5. Create genuine intrigue without being misleading
|
| 173 |
+
6. Leverage industry-specific pain points and desires
|
| 174 |
+
7. Make each option feel scroll-stopping and urgent
|
| 175 |
|
| 176 |
+
Quality Standards:
|
| 177 |
+
- Each subject line should feel like it was written by the world's best copywriter
|
| 178 |
+
- Avoid generic, cliché, or obviously promotional language
|
| 179 |
+
- Create genuine curiosity and emotional pull
|
| 180 |
+
- Ensure mobile-first optimization
|
| 181 |
+
- Focus on what makes people instantly want to click
|
| 182 |
|
| 183 |
+
EXACT OUTPUT FORMAT:
|
| 184 |
|
| 185 |
+
**Current:** {existing_subject} (Score: {analysis['score']}/10)
|
|
|
|
| 186 |
|
| 187 |
+
**Option 1:** [compelling subject line]
|
| 188 |
+
[irresistible preheader]
|
| 189 |
|
| 190 |
+
**Option 2:** [compelling subject line]
|
| 191 |
+
[irresistible preheader]
|
| 192 |
|
| 193 |
+
**Option 3:** [compelling subject line]
|
| 194 |
+
[irresistible preheader]
|
| 195 |
|
| 196 |
+
**Option 4:** [compelling subject line]
|
| 197 |
+
[irresistible preheader]
|
| 198 |
|
| 199 |
+
**Option 5:** [compelling subject line]
|
| 200 |
+
[irresistible preheader]
|
| 201 |
|
| 202 |
+
Make each option significantly more compelling than the original."""
|
| 203 |
|
| 204 |
if OPENAI_V1:
|
| 205 |
response = client.chat.completions.create(
|