nniehaus commited on
Commit
0648774
·
verified ·
1 Parent(s): 137a954

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -60
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 clean, focused subject lines"""
67
  try:
68
- framework_guide = {
69
- "FOMO (Fear of Missing Out)": "Create urgency with phrases like 'limited time', 'last chance', 'ending soon'",
70
- "Curiosity Gap": "Leave something incomplete or pose intriguing questions",
71
- "Social Proof": "Reference what others are doing - numbers, popularity, trends",
72
- "Loss Aversion": "Frame what they might lose rather than gain",
73
- "Reciprocity": "Offer value first - 'free', 'gift', 'bonus'",
74
- "Authority": "Reference experts, data, credentials",
75
- "Scarcity": "Emphasize limited availability or exclusive access"
76
  }
77
 
78
- prompt_text = f"""You are an expert email subject line copywriter. Generate 10 high-converting subject lines and matching preheaders.
79
 
80
- Context:
81
- - Audience: {audience}
82
- - Message: {message}
83
- - Tone: {tone}
84
- - Psychology: {psychology_framework} ({framework_guide.get(psychology_framework, '')})
85
- - Industry: {industry}
86
- - Personalization: {personalization}
87
 
88
- Requirements:
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
- Output format (exactly as shown):
96
- **Subject Line 1:** [subject]
97
- **Preheader 1:** [preheader]
98
 
99
- **Subject Line 2:** [subject]
100
- **Preheader 2:** [preheader]
 
 
 
 
 
 
 
101
 
102
- Continue for all 10. Keep it clean and scannable."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- """Clean optimization focused on results"""
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"""Optimize this email subject line for maximum open rates.
132
 
133
- Current: "{existing_subject}"
 
134
  {preheader_text}
135
- Characters: {analysis['character_count']} | Words: {analysis['word_count']} | Mobile preview: "{analysis['mobile_preview']}"
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
- Context:
138
- - Audience: {audience}
139
- - Message: {message}
140
- - Tone: {tone}
141
- - Apply: {psychology_framework}
142
- - Industry: {industry}
143
- - Personalization: {personalization}
 
144
 
145
- Optimization goals:
146
- - 2-4 words max (33 characters for mobile)
147
- - Apply {psychology_framework} psychology
148
- - Include numbers if relevant
149
- - Add emoji if appropriate
150
- - Improve current score of {analysis['score']}/10
151
 
152
- Provide exactly 5 optimized versions:
153
 
154
- **Current Subject Line:**
155
- "{existing_subject}" (Score: {analysis['score']}/10)
156
 
157
- **Optimized Option 1:** [subject]
158
- **Preheader:** [preheader]
159
 
160
- **Optimized Option 2:** [subject]
161
- **Preheader:** [preheader]
162
 
163
- **Optimized Option 3:** [subject]
164
- **Preheader:** [preheader]
165
 
166
- **Optimized Option 4:** [subject]
167
- **Preheader:** [preheader]
168
 
169
- **Optimized Option 5:** [subject]
170
- **Preheader:** [preheader]
171
 
172
- Keep it clean and focused on the actual subject lines."""
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(