basyx commited on
Commit
54520ba
·
verified ·
1 Parent(s): 2c5ac2e

Create variations.py

Browse files
Files changed (1) hide show
  1. utils/variations.py +238 -0
utils/variations.py ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ variations.py
3
+ ---------------------------------------
4
+ Hook & Script Variation Engine (V8)
5
+
6
+ Purpose:
7
+ - Generate multiple viral hooks
8
+ - Create alternative script directions
9
+ - Support A/B testing of edits
10
+ - Enable Multi-Version Render pipeline
11
+
12
+ Works fully CPU-only.
13
+ No external API required.
14
+ """
15
+
16
+ import random
17
+ import hashlib
18
+
19
+
20
+ # =====================================================
21
+ # HOOK TEMPLATES (VIRAL PATTERNS)
22
+ # =====================================================
23
+
24
+ HOOK_PATTERNS = [
25
+ "You are not going to believe this...",
26
+ "This is what nobody tells you about {}",
27
+ "Stop scrolling if you want to understand {}",
28
+ "The truth about {} will shock you",
29
+ "Most people get {} wrong",
30
+ "If you understand this, your {} changes forever",
31
+ "I wish I knew this before about {}",
32
+ "This is how you actually win at {}",
33
+ "Everyone is lying about {}",
34
+ "Watch this before it's too late..."
35
+ ]
36
+
37
+
38
+ # =====================================================
39
+ # TEXT CLEANER
40
+ # =====================================================
41
+
42
+ def extract_keywords(words):
43
+ """
44
+ Extract simple keyword candidates from transcript
45
+ """
46
+
47
+ freq = {}
48
+
49
+ for w in words:
50
+ word = w["word"].lower().strip()
51
+ if len(word) < 3:
52
+ continue
53
+ freq[word] = freq.get(word, 0) + 1
54
+
55
+ sorted_words = sorted(freq.items(), key=lambda x: x[1], reverse=True)
56
+
57
+ return [w[0] for w in sorted_words[:5]]
58
+
59
+
60
+ # =====================================================
61
+ # HOOK GENERATION
62
+ # =====================================================
63
+
64
+ def generate_hooks(words, count=5):
65
+ """
66
+ Generate multiple viral hooks from transcript
67
+ """
68
+
69
+ keywords = extract_keywords(words)
70
+
71
+ hooks = []
72
+
73
+ for i in range(count):
74
+
75
+ template = random.choice(HOOK_PATTERNS)
76
+
77
+ keyword = random.choice(keywords) if keywords else "this"
78
+
79
+ try:
80
+ hook = template.format(keyword)
81
+ except:
82
+ hook = template
83
+
84
+ hooks.append(hook)
85
+
86
+ return hooks
87
+
88
+
89
+ # =====================================================
90
+ # SCRIPT VARIATION ENGINE
91
+ # =====================================================
92
+
93
+ def generate_script_variations(words):
94
+ """
95
+ Creates alternative narrative directions
96
+ """
97
+
98
+ base_text = " ".join([w["word"] for w in words])
99
+
100
+ variations = []
101
+
102
+ variations.append({
103
+ "style": "direct",
104
+ "script": base_text
105
+ })
106
+
107
+ variations.append({
108
+ "style": "emotional",
109
+ "script": "Imagine this... " + base_text
110
+ })
111
+
112
+ variations.append({
113
+ "style": "urgent",
114
+ "script": "You need to hear this: " + base_text
115
+ })
116
+
117
+ variations.append({
118
+ "style": "story",
119
+ "script": "Let me tell you something important. " + base_text
120
+ })
121
+
122
+ return variations
123
+
124
+
125
+ # =====================================================
126
+ # CAPTION VARIATION ENGINE
127
+ # =====================================================
128
+
129
+ def generate_caption_variations(captions):
130
+ """
131
+ Creates multiple caption styles for rendering
132
+ """
133
+
134
+ styles = []
135
+
136
+ for c in captions:
137
+
138
+ styles.append({
139
+ "style": "bold_center",
140
+ "text": c["text"].upper()
141
+ })
142
+
143
+ styles.append({
144
+ "style": "minimal",
145
+ "text": c["text"]
146
+ })
147
+
148
+ styles.append({
149
+ "style": "emphasis_words",
150
+ "text": highlight_keywords(c["text"])
151
+ })
152
+
153
+ return styles
154
+
155
+
156
+ # =====================================================
157
+ # KEYWORD HIGHLIGHTER
158
+ # =====================================================
159
+
160
+ def highlight_keywords(text):
161
+ """
162
+ Emphasizes strong words in captions
163
+ """
164
+
165
+ keywords = ["you", "this", "stop", "now", "secret", "important"]
166
+
167
+ words = text.split()
168
+
169
+ output = []
170
+
171
+ for w in words:
172
+ if w.lower() in keywords:
173
+ output.append(w.upper())
174
+ else:
175
+ output.append(w)
176
+
177
+ return " ".join(output)
178
+
179
+
180
+ # =====================================================
181
+ # MULTI VERSION RENDER ENGINE
182
+ # =====================================================
183
+
184
+ def generate_render_variations(video_path, hooks=None):
185
+ """
186
+ Creates multiple render variants metadata
187
+ (actual rendering happens in render.py)
188
+ """
189
+
190
+ if not hooks:
191
+ hooks = ["Hook 1", "Hook 2", "Hook 3"]
192
+
193
+ outputs = []
194
+
195
+ for i, hook in enumerate(hooks):
196
+
197
+ outputs.append({
198
+ "version": i + 1,
199
+ "hook": hook,
200
+ "output_file": f"render_variant_{i+1}.mp4"
201
+ })
202
+
203
+ return outputs
204
+
205
+
206
+ # =====================================================
207
+ # DETERMINISTIC VIRAL HASH
208
+ # =====================================================
209
+
210
+ def viral_signature(text):
211
+ """
212
+ Creates deterministic ID for A/B testing consistency
213
+ """
214
+
215
+ return hashlib.md5(text.encode()).hexdigest()[:10]
216
+
217
+
218
+ # =====================================================
219
+ # PUBLIC API
220
+ # =====================================================
221
+
222
+ def generate_hooks_only(words):
223
+ return generate_hooks(words)
224
+
225
+
226
+ def generate_full_variations(words):
227
+ """
228
+ Full pipeline for V8 Multi-Version system
229
+ """
230
+
231
+ hooks = generate_hooks(words)
232
+
233
+ scripts = generate_script_variations(words)
234
+
235
+ return {
236
+ "hooks": hooks,
237
+ "scripts": scripts
238
+ }