Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,13 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
import re
|
4 |
|
5 |
-
# Load models
|
6 |
-
emotion_classifier = pipeline(
|
|
|
|
|
|
|
|
|
7 |
intent_classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
8 |
-
text_generator = pipeline("text2text-generation", model="declare-lab/flan-alpaca-base", max_new_tokens=200)
|
9 |
|
10 |
# Candidate intents
|
11 |
candidate_tasks = [
|
@@ -19,14 +22,18 @@ candidate_tasks = [
|
|
19 |
"upgrade device"
|
20 |
]
|
21 |
|
22 |
-
# Emotion
|
23 |
-
urgent_emotions = {"anger", "
|
24 |
-
moderate_emotions = {"
|
|
|
|
|
|
|
|
|
25 |
|
26 |
def get_emotion_score(emotion):
|
27 |
-
if emotion in urgent_emotions:
|
28 |
return 1.0
|
29 |
-
elif emotion in moderate_emotions:
|
30 |
return 0.6
|
31 |
else:
|
32 |
return 0.2
|
@@ -73,7 +80,7 @@ def generate_reply(input_text, intent):
|
|
73 |
|
74 |
return f"{opening} {solution} {closing}"
|
75 |
|
76 |
-
# UI
|
77 |
st.set_page_config(page_title="Customer Support Assistant", layout="centered")
|
78 |
st.title("π Smart Customer Support Assistant (for Agents Only)")
|
79 |
|
@@ -85,10 +92,9 @@ if st.button("Analyze Message"):
|
|
85 |
else:
|
86 |
with st.spinner("Processing..."):
|
87 |
|
88 |
-
# Emotion detection
|
89 |
emotion_result = emotion_classifier(user_input)
|
90 |
-
|
91 |
-
emotion_label = emotion_data['label']
|
92 |
emotion_score = get_emotion_score(emotion_label)
|
93 |
|
94 |
# Intent detection
|
|
|
2 |
from transformers import pipeline
|
3 |
import re
|
4 |
|
5 |
+
# Load upgraded models
|
6 |
+
emotion_classifier = pipeline(
|
7 |
+
"text-classification",
|
8 |
+
model="j-hartmann/emotion-english-distilroberta-base",
|
9 |
+
return_all_scores=True
|
10 |
+
)
|
11 |
intent_classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
|
|
12 |
|
13 |
# Candidate intents
|
14 |
candidate_tasks = [
|
|
|
22 |
"upgrade device"
|
23 |
]
|
24 |
|
25 |
+
# Emotion categories (updated)
|
26 |
+
urgent_emotions = {"anger", "frustration", "anxiety", "urgency", "afraid", "annoyed"}
|
27 |
+
moderate_emotions = {"confused", "sad", "tired", "concerned"}
|
28 |
+
|
29 |
+
def get_emotion_label(emotion_result):
|
30 |
+
sorted_emotions = sorted(emotion_result[0], key=lambda x: x['score'], reverse=True)
|
31 |
+
return sorted_emotions[0]['label']
|
32 |
|
33 |
def get_emotion_score(emotion):
|
34 |
+
if emotion.lower() in urgent_emotions:
|
35 |
return 1.0
|
36 |
+
elif emotion.lower() in moderate_emotions:
|
37 |
return 0.6
|
38 |
else:
|
39 |
return 0.2
|
|
|
80 |
|
81 |
return f"{opening} {solution} {closing}"
|
82 |
|
83 |
+
# Streamlit UI
|
84 |
st.set_page_config(page_title="Customer Support Assistant", layout="centered")
|
85 |
st.title("π Smart Customer Support Assistant (for Agents Only)")
|
86 |
|
|
|
92 |
else:
|
93 |
with st.spinner("Processing..."):
|
94 |
|
95 |
+
# Emotion detection (updated)
|
96 |
emotion_result = emotion_classifier(user_input)
|
97 |
+
emotion_label = get_emotion_label(emotion_result)
|
|
|
98 |
emotion_score = get_emotion_score(emotion_label)
|
99 |
|
100 |
# Intent detection
|