SamanthaStorm commited on
Commit
a568262
·
verified ·
1 Parent(s): 623a77f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -148,15 +148,22 @@ ESCALATION_QUESTIONS = [
148
 
149
  def analyze_single_message(text, thresholds, motif_flags):
150
  motif_hits, matched_phrases = detect_motifs(text)
 
 
151
  input_ids = sentiment_tokenizer(f"emotion: {text}", return_tensors="pt").input_ids
152
  with torch.no_grad():
153
  outputs = sentiment_model.generate(input_ids)
154
  emotion = sentiment_tokenizer.decode(outputs[0], skip_special_tokens=True).strip().lower()
155
  sentiment = EMOTION_TO_SENTIMENT.get(emotion, "undermining")
156
  sentiment_score = 0.5 if sentiment == "undermining" else 0.0
 
 
157
  contradiction_flag = detect_contradiction(text)
 
 
158
  motifs = [phrase for _, phrase in matched_phrases]
159
 
 
160
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
161
  with torch.no_grad():
162
  outputs = model(**inputs)
@@ -164,7 +171,7 @@ def analyze_single_message(text, thresholds, motif_flags):
164
 
165
  threshold_labels = [label for label, score in zip(LABELS, scores) if score > thresholds[label]]
166
  top_patterns = sorted([(label, score) for label, score in zip(LABELS, scores)], key=lambda x: x[1], reverse=True)[:2]
167
- pattern_labels = [label for label, _ in top_patterns]
168
 
169
  darvo_score = calculate_darvo_score(pattern_labels, 0.0, sentiment_score, motifs, contradiction_flag)
170
 
@@ -175,7 +182,6 @@ def analyze_single_message(text, thresholds, motif_flags):
175
  darvo_score,
176
  {"label": sentiment, "emotion": emotion}
177
  )
178
-
179
  def analyze_composite(msg1, msg2, msg3, *answers_and_none):
180
  responses = answers_and_none[:len(ESCALATION_QUESTIONS)]
181
  none_selected = answers_and_none[-1]
 
148
 
149
  def analyze_single_message(text, thresholds, motif_flags):
150
  motif_hits, matched_phrases = detect_motifs(text)
151
+
152
+ # Sentiment Analysis
153
  input_ids = sentiment_tokenizer(f"emotion: {text}", return_tensors="pt").input_ids
154
  with torch.no_grad():
155
  outputs = sentiment_model.generate(input_ids)
156
  emotion = sentiment_tokenizer.decode(outputs[0], skip_special_tokens=True).strip().lower()
157
  sentiment = EMOTION_TO_SENTIMENT.get(emotion, "undermining")
158
  sentiment_score = 0.5 if sentiment == "undermining" else 0.0
159
+
160
+ # Contradiction Check
161
  contradiction_flag = detect_contradiction(text)
162
+
163
+ # Motifs
164
  motifs = [phrase for _, phrase in matched_phrases]
165
 
166
+ # Model Prediction
167
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
168
  with torch.no_grad():
169
  outputs = model(**inputs)
 
171
 
172
  threshold_labels = [label for label, score in zip(LABELS, scores) if score > thresholds[label]]
173
  top_patterns = sorted([(label, score) for label, score in zip(LABELS, scores)], key=lambda x: x[1], reverse=True)[:2]
174
+ pattern_labels = threshold_labels + [label for label, _ in matched_phrases]
175
 
176
  darvo_score = calculate_darvo_score(pattern_labels, 0.0, sentiment_score, motifs, contradiction_flag)
177
 
 
182
  darvo_score,
183
  {"label": sentiment, "emotion": emotion}
184
  )
 
185
  def analyze_composite(msg1, msg2, msg3, *answers_and_none):
186
  responses = answers_and_none[:len(ESCALATION_QUESTIONS)]
187
  none_selected = answers_and_none[-1]