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