Hasitha16 commited on
Commit
3034a35
·
verified ·
1 Parent(s): d78888c

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +6 -3
model.py CHANGED
@@ -55,10 +55,13 @@ def smart_summarize(text, n_clusters=1):
55
 
56
  # === Emotion Detection (Fixed) ===
57
  def detect_emotion(text):
58
- result = emotion_model(text)
59
- if isinstance(result, list) and len(result) > 0:
60
  return result[0]["label"]
61
- return "neutral"
 
 
 
62
 
63
  # === Follow-up Q&A ===
64
  def answer_followup(text, question, verbosity="brief"):
 
55
 
56
  # === Emotion Detection (Fixed) ===
57
  def detect_emotion(text):
58
+ result = emotion_model(text, top_k=1)
59
+ if isinstance(result, list) and isinstance(result[0], dict):
60
  return result[0]["label"]
61
+ elif isinstance(result, dict) and "label" in result:
62
+ return result["label"]
63
+ else:
64
+ return "neutral"
65
 
66
  # === Follow-up Q&A ===
67
  def answer_followup(text, question, verbosity="brief"):