| """ |
| variations.py |
| --------------------------------------- |
| Hook & Script Variation Engine (V8) |
| |
| Purpose: |
| - Generate multiple viral hooks |
| - Create alternative script directions |
| - Support A/B testing of edits |
| - Enable Multi-Version Render pipeline |
| |
| Works fully CPU-only. |
| No external API required. |
| """ |
|
|
| import random |
| import hashlib |
|
|
|
|
| |
| |
| |
|
|
| HOOK_PATTERNS = [ |
| "You are not going to believe this...", |
| "This is what nobody tells you about {}", |
| "Stop scrolling if you want to understand {}", |
| "The truth about {} will shock you", |
| "Most people get {} wrong", |
| "If you understand this, your {} changes forever", |
| "I wish I knew this before about {}", |
| "This is how you actually win at {}", |
| "Everyone is lying about {}", |
| "Watch this before it's too late..." |
| ] |
|
|
|
|
| |
| |
| |
|
|
| def extract_keywords(words): |
| """ |
| Extract simple keyword candidates from transcript |
| """ |
|
|
| freq = {} |
|
|
| for w in words: |
| word = w["word"].lower().strip() |
| if len(word) < 3: |
| continue |
| freq[word] = freq.get(word, 0) + 1 |
|
|
| sorted_words = sorted(freq.items(), key=lambda x: x[1], reverse=True) |
|
|
| return [w[0] for w in sorted_words[:5]] |
|
|
|
|
| |
| |
| |
|
|
| def generate_hooks(words, count=5): |
| """ |
| Generate multiple viral hooks from transcript |
| """ |
|
|
| keywords = extract_keywords(words) |
|
|
| hooks = [] |
|
|
| for i in range(count): |
|
|
| template = random.choice(HOOK_PATTERNS) |
|
|
| keyword = random.choice(keywords) if keywords else "this" |
|
|
| try: |
| hook = template.format(keyword) |
| except: |
| hook = template |
|
|
| hooks.append(hook) |
|
|
| return hooks |
|
|
|
|
| |
| |
| |
|
|
| def generate_script_variations(words): |
| """ |
| Creates alternative narrative directions |
| """ |
|
|
| base_text = " ".join([w["word"] for w in words]) |
|
|
| variations = [] |
|
|
| variations.append({ |
| "style": "direct", |
| "script": base_text |
| }) |
|
|
| variations.append({ |
| "style": "emotional", |
| "script": "Imagine this... " + base_text |
| }) |
|
|
| variations.append({ |
| "style": "urgent", |
| "script": "You need to hear this: " + base_text |
| }) |
|
|
| variations.append({ |
| "style": "story", |
| "script": "Let me tell you something important. " + base_text |
| }) |
|
|
| return variations |
|
|
|
|
| |
| |
| |
|
|
| def generate_caption_variations(captions): |
| """ |
| Creates multiple caption styles for rendering |
| """ |
|
|
| styles = [] |
|
|
| for c in captions: |
|
|
| styles.append({ |
| "style": "bold_center", |
| "text": c["text"].upper() |
| }) |
|
|
| styles.append({ |
| "style": "minimal", |
| "text": c["text"] |
| }) |
|
|
| styles.append({ |
| "style": "emphasis_words", |
| "text": highlight_keywords(c["text"]) |
| }) |
|
|
| return styles |
|
|
|
|
| |
| |
| |
|
|
| def highlight_keywords(text): |
| """ |
| Emphasizes strong words in captions |
| """ |
|
|
| keywords = ["you", "this", "stop", "now", "secret", "important"] |
|
|
| words = text.split() |
|
|
| output = [] |
|
|
| for w in words: |
| if w.lower() in keywords: |
| output.append(w.upper()) |
| else: |
| output.append(w) |
|
|
| return " ".join(output) |
|
|
|
|
| |
| |
| |
|
|
| def generate_render_variations(video_path, hooks=None): |
| """ |
| Creates multiple render variants metadata |
| (actual rendering happens in render.py) |
| """ |
|
|
| if not hooks: |
| hooks = ["Hook 1", "Hook 2", "Hook 3"] |
|
|
| outputs = [] |
|
|
| for i, hook in enumerate(hooks): |
|
|
| outputs.append({ |
| "version": i + 1, |
| "hook": hook, |
| "output_file": f"render_variant_{i+1}.mp4" |
| }) |
|
|
| return outputs |
|
|
|
|
| |
| |
| |
|
|
| def viral_signature(text): |
| """ |
| Creates deterministic ID for A/B testing consistency |
| """ |
|
|
| return hashlib.md5(text.encode()).hexdigest()[:10] |
|
|
|
|
| |
| |
| |
|
|
| def generate_hooks_only(words): |
| return generate_hooks(words) |
|
|
|
|
| def generate_full_variations(words): |
| """ |
| Full pipeline for V8 Multi-Version system |
| """ |
|
|
| hooks = generate_hooks(words) |
|
|
| scripts = generate_script_variations(words) |
|
|
| return { |
| "hooks": hooks, |
| "scripts": scripts |
| } |