SamanthaStorm commited on
Commit
f81397d
·
verified ·
1 Parent(s): d270769

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -8,6 +8,15 @@ import matplotlib.pyplot as plt
8
  import io
9
  from PIL import Image
10
  from datetime import datetime
 
 
 
 
 
 
 
 
 
11
 
12
  # --- Timeline Visualization Function ---
13
  def generate_abuse_score_chart(dates, scores, labels):
@@ -130,6 +139,9 @@ DARVO_MOTIFS = [
130
  "You’re the one who’s always making me feel like I’m the one who’s abusive.",
131
  "You’re the one who’s always making me feel like I’m the one who’s toxic."
132
  ]
 
 
 
133
  def detect_contradiction(message):
134
  patterns = [
135
  (r"\b(i love you).{0,15}(i hate you|you ruin everything)", re.IGNORECASE),
@@ -319,7 +331,11 @@ def analyze_single_message(text, thresholds):
319
  abuse_score_raw = min(abuse_score_raw + 25, 100)
320
 
321
  abuse_score = min(abuse_score_raw, 100 if "threat" in threshold_labels or "control" in threshold_labels else 95)
322
-
 
 
 
 
323
  print("\n--- Debug Info ---")
324
  print(f"Text: {text}")
325
  print(f"Sentiment: {sentiment} (raw: {result['label']}, score: {result['score']:.3f})")
 
8
  import io
9
  from PIL import Image
10
  from datetime import datetime
11
+ from transformers import pipeline as hf_pipeline # prevent name collision with gradio pipeline
12
+
13
+ # Emotion model (no retraining needed)
14
+ emotion_pipeline = hf_pipeline(
15
+ "text-classification",
16
+ model="j-hartmann/emotion-english-distilroberta-base",
17
+ top_k=None,
18
+ truncation=True
19
+ )
20
 
21
  # --- Timeline Visualization Function ---
22
  def generate_abuse_score_chart(dates, scores, labels):
 
139
  "You’re the one who’s always making me feel like I’m the one who’s abusive.",
140
  "You’re the one who’s always making me feel like I’m the one who’s toxic."
141
  ]
142
+ def get_emotion_profile(text):
143
+ emotions = emotion_pipeline(text)
144
+ return {e['label'].lower(): round(e['score'], 3) for e in emotions}
145
  def detect_contradiction(message):
146
  patterns = [
147
  (r"\b(i love you).{0,15}(i hate you|you ruin everything)", re.IGNORECASE),
 
331
  abuse_score_raw = min(abuse_score_raw + 25, 100)
332
 
333
  abuse_score = min(abuse_score_raw, 100 if "threat" in threshold_labels or "control" in threshold_labels else 95)
334
+ # New: Emotion Profile
335
+ emotion_profile = get_emotion_profile(text)
336
+ print("Emotion Profile:")
337
+ for emotion, score in emotion_profile.items():
338
+ print(f" {emotion.capitalize():10}: {score}")
339
  print("\n--- Debug Info ---")
340
  print(f"Text: {text}")
341
  print(f"Sentiment: {sentiment} (raw: {result['label']}, score: {result['score']:.3f})")