Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -74,14 +74,18 @@ def get_emotion(text: str) -> str:
|
|
74 |
'''
|
75 |
def get_emotion(text: str) -> str:
|
76 |
try:
|
|
|
77 |
result = emotion_classifier(text)
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
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
|
|
|
74 |
'''
|
75 |
def get_emotion(text: str) -> str:
|
76 |
try:
|
77 |
+
# Get the classification result
|
78 |
result = emotion_classifier(text)
|
79 |
+
|
80 |
+
# Check if the result is a list and has at least one item
|
81 |
+
if result and isinstance(result, list) and len(result) > 0:
|
82 |
+
emotion_label = result[0]['label'] # Access the label of the first result
|
83 |
+
return emotion_label.capitalize() # Capitalize for readability
|
84 |
+
return "Unknown emotion" # Fallback if no label found
|
85 |
except Exception as e:
|
86 |
return f"Error in emotion detection: {e}"
|
87 |
|
88 |
+
|
89 |
# Function to handle long conversations for emotion detection
|
90 |
def analyze_long_text_emotion(text: str, chunk_size: int = 512) -> str:
|
91 |
# Split the text into chunks of the specified size
|