basyx commited on
Commit
d86652a
·
verified ·
1 Parent(s): d01c228

Create viral_scorer.py

Browse files
Files changed (1) hide show
  1. utils/viral_scorer.py +46 -0
utils/viral_scorer.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def score_clip(words):
2
+ """
3
+ Returns virality score (0–100)
4
+ based on speech + structure signals
5
+ """
6
+
7
+ if not words:
8
+ return 0
9
+
10
+ text = " ".join([w["text"] for w in words]).lower()
11
+
12
+ score = 0
13
+
14
+ # -----------------------------
15
+ # HOOK SIGNAL (first words)
16
+ # -----------------------------
17
+ hook_words = ["you", "imagine", "stop", "listen", "this", "never", "why"]
18
+
19
+ if any(h in text[:50] for h in hook_words):
20
+ score += 25
21
+
22
+ # -----------------------------
23
+ # EMOTION SIGNAL
24
+ # -----------------------------
25
+ exclamations = sum(1 for w in words if "!" in w["text"])
26
+ score += min(exclamations * 5, 20)
27
+
28
+ # -----------------------------
29
+ # LENGTH OPTIMIZATION
30
+ # -----------------------------
31
+ duration = words[-1]["end"] - words[0]["start"]
32
+
33
+ if 6 <= duration <= 25:
34
+ score += 25
35
+ elif duration < 6:
36
+ score -= 10
37
+ else:
38
+ score -= 5
39
+
40
+ # -----------------------------
41
+ # WORD DENSITY
42
+ # -----------------------------
43
+ score += min(len(words) / 2, 20)
44
+
45
+ # Clamp
46
+ return max(0, min(100, score))