areebsatin commited on
Commit
c2da8fc
·
1 Parent(s): 78a9770

Refactor: Upgraded transcript scoring to psychology-based viral system

Browse files
Files changed (1) hide show
  1. server.py +39 -15
server.py CHANGED
@@ -751,19 +751,42 @@ _TRIGGER_KEYWORDS = {
751
  }
752
 
753
 
754
- def score_triggers(transcript_text: str) -> dict:
755
- """Scan transcript for biological trigger keywords.
756
-
757
- Returns:
758
- {"score": int (0-5), "tags": list[str]}
759
  """
760
- text_lower = transcript_text.lower()
761
- found_categories = set()
762
- for category, keywords in _TRIGGER_KEYWORDS.items():
763
- if any(kw in text_lower for kw in keywords):
764
- found_categories.add(category)
765
- score = min(5, len(found_categories))
766
- return {"score": score, "tags": sorted(found_categories)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
767
 
768
 
769
  def score_pacing(energies: list, start: float, end: float) -> int:
@@ -1152,11 +1175,12 @@ def process():
1152
  structure = segment_structure(s, e)
1153
 
1154
  # Trigger scoring uses Whisper transcript if captions were generated
 
1155
  if transcript_text:
1156
- triggers = score_triggers(transcript_text)
 
1157
  else:
1158
- # No transcript available (captions disabled or failed)
1159
- triggers = {"score": 0, "tags": []}
1160
 
1161
  yield json.dumps({
1162
  "clip": f"{url_prefix}/clips/{clip_path.name}",
 
751
  }
752
 
753
 
754
+ def score_transcript_segment(text: str) -> float:
755
+ """
756
+ Score a transcript segment for viral potential based on hooks, structure, and emotions.
757
+ Returns a float 0.0–1.0.
 
758
  """
759
+ if not text or not text.strip():
760
+ return 0.0
761
+
762
+ score = 0.0
763
+ text_lower = text.lower().strip()
764
+
765
+ # 1. Hook Phrases (+0.3)
766
+ hooks = ["wait", "secret", "no one tells you", "here's why", "never", "always", "mistake", "truth", "actually"]
767
+ if any(h in text_lower for h in hooks):
768
+ score += 0.3
769
+
770
+ # 2. Question Mark (+0.2)
771
+ if "?" in text:
772
+ score += 0.2
773
+
774
+ # 3. Information Density (+0.2)
775
+ word_count = len(text.split())
776
+ if word_count > 20:
777
+ score += 0.2
778
+
779
+ # 4. Emotional Words (+0.15)
780
+ emotions = ["crazy", "insane", "shocked", "love", "hate", "afraid", "angry", "excited", "wow", "unbelievable"]
781
+ if any(e in text_lower for e in emotions):
782
+ score += 0.15
783
+
784
+ # 5. Strong Openers (+0.15)
785
+ openers = ["so", "but", "wait", "now", "here", "this is"]
786
+ if any(text_lower.startswith(o) for o in openers):
787
+ score += 0.15
788
+
789
+ return min(1.0, round(score, 2))
790
 
791
 
792
  def score_pacing(energies: list, start: float, end: float) -> int:
 
1175
  structure = segment_structure(s, e)
1176
 
1177
  # Trigger scoring uses Whisper transcript if captions were generated
1178
+ # Viral scoring uses behavior-based psychology rules
1179
  if transcript_text:
1180
+ viral_score = score_transcript_segment(transcript_text)
1181
+ triggers = {"score": viral_score, "tags": ["Viral Hook" if viral_score > 0.5 else "Context"]}
1182
  else:
1183
+ triggers = {"score": 0.0, "tags": []}
 
1184
 
1185
  yield json.dumps({
1186
  "clip": f"{url_prefix}/clips/{clip_path.name}",