Ravilppcd07 commited on
Commit
dc0d761
·
verified ·
1 Parent(s): 80bb045

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -0
app.py CHANGED
@@ -72,6 +72,16 @@ def get_emotion(text: str) -> str:
72
  except Exception as e:
73
  return f"Error in emotion detection: {e}"
74
 
 
 
 
 
 
 
 
 
 
 
75
  # Function to handle long conversations for emotion detection
76
  def analyze_long_text_emotion(text: str, chunk_size: int = 512) -> str:
77
  # Split the text into chunks of the specified size
 
72
  except Exception as e:
73
  return f"Error in emotion detection: {e}"
74
 
75
+ def get_emotion(text: str) -> str:
76
+ try:
77
+ result = emotion_classifier(text)
78
+ if result and isinstance(result, list):
79
+ emotion_label = result[0]['label']
80
+ return emotion_label.capitalize()
81
+ return "Unknown emotion"
82
+ except Exception as e:
83
+ return f"Error in emotion detection: {e}"
84
+
85
  # Function to handle long conversations for emotion detection
86
  def analyze_long_text_emotion(text: str, chunk_size: int = 512) -> str:
87
  # Split the text into chunks of the specified size