Spaces:
Running on T4
Running on T4
Creative strategy insights: translate brain regions to actionable ad advice
Browse files
app.py
CHANGED
|
@@ -212,65 +212,107 @@ def find_peak_region_seconds(region_activations, hrf_offset):
|
|
| 212 |
return summary
|
| 213 |
|
| 214 |
|
| 215 |
-
def generate_insights(engagement, hrf_offset=5):
|
|
|
|
| 216 |
insights = []
|
| 217 |
if len(engagement) < 3:
|
| 218 |
return insights
|
| 219 |
|
| 220 |
mean_eng = float(np.mean(engagement))
|
|
|
|
| 221 |
|
| 222 |
-
#
|
| 223 |
hook = float(np.mean(engagement[:3]))
|
| 224 |
if hook < mean_eng * 0.85:
|
| 225 |
drop = ((mean_eng - hook) / mean_eng * 100)
|
| 226 |
insights.append({
|
| 227 |
-
"type": "
|
| 228 |
-
"
|
| 229 |
-
"
|
|
|
|
| 230 |
})
|
| 231 |
elif hook > mean_eng * 1.15:
|
| 232 |
lift = ((hook - mean_eng) / mean_eng * 100)
|
| 233 |
insights.append({
|
| 234 |
-
"type": "
|
| 235 |
-
"
|
| 236 |
-
"
|
|
|
|
| 237 |
})
|
| 238 |
|
| 239 |
-
#
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
mid_eng = float(np.mean(engagement[mid_s:mid_e]))
|
| 244 |
if mid_eng < mean_eng * 0.8:
|
| 245 |
insights.append({
|
| 246 |
"type": "mid_drop", "severity": "medium",
|
| 247 |
-
"
|
| 248 |
-
"
|
|
|
|
| 249 |
})
|
| 250 |
|
| 251 |
-
# Ending
|
| 252 |
-
if
|
| 253 |
last_3s = float(np.mean(engagement[-3:]))
|
| 254 |
if last_3s < mean_eng * 0.8:
|
| 255 |
insights.append({
|
| 256 |
-
"type": "
|
| 257 |
-
"
|
| 258 |
-
"
|
|
|
|
| 259 |
})
|
| 260 |
-
elif last_3s > mean_eng * 1.
|
| 261 |
insights.append({
|
| 262 |
-
"type": "
|
| 263 |
-
"
|
| 264 |
-
"
|
|
|
|
| 265 |
})
|
| 266 |
|
| 267 |
-
#
|
| 268 |
std_eng = float(np.std(engagement))
|
| 269 |
if std_eng < 0.05:
|
| 270 |
insights.append({
|
| 271 |
-
"type": "
|
| 272 |
-
"
|
| 273 |
-
"
|
|
|
|
| 274 |
})
|
| 275 |
|
| 276 |
return insights
|
|
@@ -359,7 +401,7 @@ def analyze_video(video_url: str, filename: str = "video.mp4") -> str:
|
|
| 359 |
peak_idx = int(np.argmax(valid_engagement))
|
| 360 |
low_idx = int(np.argmin(valid_engagement))
|
| 361 |
|
| 362 |
-
insights = generate_insights(valid_engagement, hrf_offset)
|
| 363 |
elapsed = time.time() - start_time
|
| 364 |
|
| 365 |
report = {
|
|
|
|
| 212 |
return summary
|
| 213 |
|
| 214 |
|
| 215 |
+
def generate_insights(engagement, region_activations, hrf_offset=5):
|
| 216 |
+
"""Generate actionable creative strategy insights from brain data."""
|
| 217 |
insights = []
|
| 218 |
if len(engagement) < 3:
|
| 219 |
return insights
|
| 220 |
|
| 221 |
mean_eng = float(np.mean(engagement))
|
| 222 |
+
n = len(engagement)
|
| 223 |
|
| 224 |
+
# ββ 1. Hook Analysis ββ
|
| 225 |
hook = float(np.mean(engagement[:3]))
|
| 226 |
if hook < mean_eng * 0.85:
|
| 227 |
drop = ((mean_eng - hook) / mean_eng * 100)
|
| 228 |
insights.append({
|
| 229 |
+
"type": "hook", "severity": "high",
|
| 230 |
+
"title": "Weak Opening Hook",
|
| 231 |
+
"message": f"The first 3 seconds generate {drop:.0f}% less brain engagement than the rest of the ad. In a feed environment, this means scroll-past risk is high.",
|
| 232 |
+
"action": "Front-load impact: lead with a surprising visual, bold text, or audio spike in the first 1-2 seconds."
|
| 233 |
})
|
| 234 |
elif hook > mean_eng * 1.15:
|
| 235 |
lift = ((hook - mean_eng) / mean_eng * 100)
|
| 236 |
insights.append({
|
| 237 |
+
"type": "hook", "severity": "positive",
|
| 238 |
+
"title": "Strong Opening Hook",
|
| 239 |
+
"message": f"The opening drives {lift:.0f}% higher engagement than average β this ad grabs attention immediately.",
|
| 240 |
+
"action": "This hook pattern works. Replicate the opening structure (visual style, pacing, audio) across other creatives."
|
| 241 |
})
|
| 242 |
|
| 243 |
+
# ββ 2. What's Driving Engagement (translate brain regions to creative language) ββ
|
| 244 |
+
region_means = {}
|
| 245 |
+
for rname in ["visual_processing", "attention", "emotional_response", "language_processing", "motor_planning"]:
|
| 246 |
+
if rname in region_activations:
|
| 247 |
+
vals = region_activations[rname]
|
| 248 |
+
search = vals[:-2] if len(vals) > 3 else vals
|
| 249 |
+
region_means[rname] = float(np.mean(search))
|
| 250 |
+
|
| 251 |
+
if region_means:
|
| 252 |
+
sorted_regions = sorted(region_means.items(), key=lambda x: x[1], reverse=True)
|
| 253 |
+
top = sorted_regions[0][0]
|
| 254 |
+
|
| 255 |
+
driver_map = {
|
| 256 |
+
"visual_processing": ("Visually-Led Creative", "The visual elements (colors, motion, composition) generate the strongest brain response. Viewers are engaged by what they see, not what they hear.", "Double down on visual storytelling. Test different visual treatments β the audience is responding to imagery over copy."),
|
| 257 |
+
"attention": ("High Cognitive Engagement", "This ad demands active focus β viewers are thinking and processing, not passively watching.", "This is engaging but mentally demanding. Balance information-dense sections with breathing room to avoid fatigue."),
|
| 258 |
+
"emotional_response": ("Emotionally Resonant", "Emotional processing dominates β this ad creates a feeling. Emotion-driven ads tend to build stronger brand recall.", "Lean into the emotional angle in your CTA. 'Feel' CTAs ('Join the movement', 'Don't miss out') outperform 'think' CTAs ('Learn more') for emotional creatives."),
|
| 259 |
+
"language_processing": ("Copy & Audio Are Carrying", "Language processing is the dominant signal β voiceover, on-screen text, or dialogue are doing the heavy lifting.", "The words matter most. A/B test different copy, voiceover tones, or text overlay styles to find the strongest variant."),
|
| 260 |
+
"motor_planning": ("Action-Oriented", "The brain is preparing to act β tap, swipe, click. This is the ideal response for performance ads.", "Capitalize on this impulse. Make the CTA large, immediate, and friction-free. This audience is ready to convert."),
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
if top in driver_map:
|
| 264 |
+
title, msg, action = driver_map[top]
|
| 265 |
+
insights.append({"type": "driver", "severity": "positive", "title": title, "message": msg, "action": action})
|
| 266 |
+
|
| 267 |
+
# ββ 3. Peak Moment ββ
|
| 268 |
+
peak_idx = int(np.argmax(engagement))
|
| 269 |
+
peak_s = peak_idx + hrf_offset
|
| 270 |
+
insights.append({
|
| 271 |
+
"type": "peak", "severity": "positive",
|
| 272 |
+
"title": f"Strongest Moment at {peak_s}s",
|
| 273 |
+
"message": f"Peak brain engagement occurs at second {peak_s}. Whatever happens here β a visual reveal, scene transition, or key message β is the most impactful element.",
|
| 274 |
+
"action": f"Build your ad's narrative arc around the {peak_s}-second mark. Consider placing your product reveal or key value proposition here."
|
| 275 |
+
})
|
| 276 |
+
|
| 277 |
+
# ββ 4. Mid-Section Drop ββ
|
| 278 |
+
if n >= 8:
|
| 279 |
+
mid_s = n // 3
|
| 280 |
+
mid_e = 2 * n // 3
|
| 281 |
mid_eng = float(np.mean(engagement[mid_s:mid_e]))
|
| 282 |
if mid_eng < mean_eng * 0.8:
|
| 283 |
insights.append({
|
| 284 |
"type": "mid_drop", "severity": "medium",
|
| 285 |
+
"title": "Middle Section Loses Attention",
|
| 286 |
+
"message": f"Engagement drops between seconds {mid_s+hrf_offset}-{mid_e+hrf_offset}. Without new stimulus, viewers disengage here.",
|
| 287 |
+
"action": "Add a pattern interrupt: scene change, new speaker, text overlay, music shift, or tempo change. The brain needs novelty every 3-5 seconds."
|
| 288 |
})
|
| 289 |
|
| 290 |
+
# ββ 5. Ending / CTA Readiness ββ
|
| 291 |
+
if n >= 5:
|
| 292 |
last_3s = float(np.mean(engagement[-3:]))
|
| 293 |
if last_3s < mean_eng * 0.8:
|
| 294 |
insights.append({
|
| 295 |
+
"type": "ending", "severity": "high",
|
| 296 |
+
"title": "CTA Lands on Low Engagement",
|
| 297 |
+
"message": "Brain engagement is low when the CTA appears. Viewers' attention has drifted β they're less likely to act.",
|
| 298 |
+
"action": "Either move the CTA to the peak moment, or create a second attention spike at the end (urgency text, bold visual, or a direct question to re-engage)."
|
| 299 |
})
|
| 300 |
+
elif last_3s > mean_eng * 1.1:
|
| 301 |
insights.append({
|
| 302 |
+
"type": "ending", "severity": "positive",
|
| 303 |
+
"title": "Strong CTA Window",
|
| 304 |
+
"message": "Engagement is high at the end β viewers are attentive when the CTA appears, maximizing click-through potential.",
|
| 305 |
+
"action": "Ensure the CTA is visually prominent and uses action language. This audience is primed to convert."
|
| 306 |
})
|
| 307 |
|
| 308 |
+
# ββ 6. Overall Dynamics ββ
|
| 309 |
std_eng = float(np.std(engagement))
|
| 310 |
if std_eng < 0.05:
|
| 311 |
insights.append({
|
| 312 |
+
"type": "dynamics", "severity": "medium",
|
| 313 |
+
"title": "Flat Response β Low Memorability",
|
| 314 |
+
"message": "Brain activation is uniform throughout β no emotional peaks or valleys. Flat response correlates with lower ad recall.",
|
| 315 |
+
"action": "Create contrast: a quiet moment followed by a bold one, humor, an unexpected visual, or a change in pace. Memorable ads have peaks."
|
| 316 |
})
|
| 317 |
|
| 318 |
return insights
|
|
|
|
| 401 |
peak_idx = int(np.argmax(valid_engagement))
|
| 402 |
low_idx = int(np.argmin(valid_engagement))
|
| 403 |
|
| 404 |
+
insights = generate_insights(valid_engagement, region_activations, hrf_offset)
|
| 405 |
elapsed = time.time() - start_time
|
| 406 |
|
| 407 |
report = {
|