tharakap commited on
Commit
3452fb6
·
1 Parent(s): 5646424

Made changes in app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -27,7 +27,7 @@ except Exception as e:
27
  classifier = pipeline("sentiment-analysis")
28
 
29
 
30
- def predict_sentiment(text, threshold=0.21):
31
  results = classifier(text)[0]
32
 
33
  formatted = []
@@ -37,17 +37,20 @@ def predict_sentiment(text, threshold=0.21):
37
  label = res["label"].upper()
38
  score = res["score"]
39
 
 
40
  if score >= threshold:
41
  active_labels.append(label)
42
  formatted.append(f"- **{label}** (ACTIVE): {round(score, 4)}")
43
  else:
44
  formatted.append(f"- {label}: {round(score, 4)}")
45
 
46
- output = "### Active Emotions:\n"
47
  if active_labels:
48
  output += ", ".join(active_labels) + "\n\n"
49
  else:
50
  output += "None detected above threshold.\n\n"
 
 
51
 
52
  return output
53
 
 
27
  classifier = pipeline("sentiment-analysis")
28
 
29
 
30
+ def predict_sentiment(text, threshold=0.2): # You set the threshold here
31
  results = classifier(text)[0]
32
 
33
  formatted = []
 
37
  label = res["label"].upper()
38
  score = res["score"]
39
 
40
+ # Check if the score is above the custom threshold
41
  if score >= threshold:
42
  active_labels.append(label)
43
  formatted.append(f"- **{label}** (ACTIVE): {round(score, 4)}")
44
  else:
45
  formatted.append(f"- {label}: {round(score, 4)}")
46
 
47
+ output = "### Active Emotions (Threshold > " + str(threshold) + "):\n"
48
  if active_labels:
49
  output += ", ".join(active_labels) + "\n\n"
50
  else:
51
  output += "None detected above threshold.\n\n"
52
+
53
+ output += "### All Emotion Scores:\n" + "\n".join(formatted)
54
 
55
  return output
56