Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,16 +27,16 @@ candidate_tasks = [
|
|
27 |
def generate_response(intent, human=True):
|
28 |
if human:
|
29 |
prompt = (
|
30 |
-
f"Write a customer service message for intent '{intent}'.
|
31 |
-
"1. Greeting, 2.
|
32 |
-
"3. A polite
|
33 |
)
|
34 |
else:
|
35 |
prompt = (
|
36 |
-
f"
|
37 |
-
"
|
38 |
)
|
39 |
-
return text_generator(prompt, max_new_tokens=
|
40 |
|
41 |
urgent_emotions = {"anger", "frustration", "anxiety", "urgency", "afraid", "annoyed"}
|
42 |
moderate_emotions = {"confused", "sad", "tired", "concerned", "sadness"}
|
@@ -100,6 +100,7 @@ with col2:
|
|
100 |
analyze_clicked = st.button("Analyze", use_container_width=True)
|
101 |
|
102 |
if analyze_clicked and user_input.strip():
|
|
|
103 |
emotion_result = emotion_classifier(user_input)
|
104 |
emotion_label = get_emotion_label(emotion_result, user_input)
|
105 |
emotion_score = get_emotion_score(emotion_label)
|
@@ -114,7 +115,6 @@ if analyze_clicked and user_input.strip():
|
|
114 |
content_score += 0.4
|
115 |
|
116 |
final_score = 0.5 * emotion_score + 0.5 * content_score
|
117 |
-
session["chat"].append({"role": "user", "content": user_input})
|
118 |
|
119 |
if final_score < 0.5 and top_intents:
|
120 |
intent = top_intents[0]
|
@@ -129,6 +129,7 @@ if analyze_clicked and user_input.strip():
|
|
129 |
"intents": top_intents
|
130 |
}
|
131 |
session["support_required"] = "🔴 Human support required."
|
|
|
132 |
|
133 |
if session["support_required"]:
|
134 |
st.markdown(f"### {session['support_required']}")
|
|
|
27 |
def generate_response(intent, human=True):
|
28 |
if human:
|
29 |
prompt = (
|
30 |
+
f"Write a customer service message for intent '{intent}' in 3 sentences only. Each sentence must represent: "
|
31 |
+
"1. Greeting, 2. One-sentence description of customer's current service and a suitable option, "
|
32 |
+
"3. A short and polite question asking if the customer would like to proceed. Use placeholders like Plan X, ¥X, etc."
|
33 |
)
|
34 |
else:
|
35 |
prompt = (
|
36 |
+
f"Automatically resolve the customer request: '{intent}' in one helpful and polite sentence."
|
37 |
+
" Use direct language and include relevant details like plan options or links, with placeholder values."
|
38 |
)
|
39 |
+
return text_generator(prompt, max_new_tokens=80, do_sample=True)[0]['generated_text']
|
40 |
|
41 |
urgent_emotions = {"anger", "frustration", "anxiety", "urgency", "afraid", "annoyed"}
|
42 |
moderate_emotions = {"confused", "sad", "tired", "concerned", "sadness"}
|
|
|
100 |
analyze_clicked = st.button("Analyze", use_container_width=True)
|
101 |
|
102 |
if analyze_clicked and user_input.strip():
|
103 |
+
session["chat"].append({"role": "user", "content": user_input})
|
104 |
emotion_result = emotion_classifier(user_input)
|
105 |
emotion_label = get_emotion_label(emotion_result, user_input)
|
106 |
emotion_score = get_emotion_score(emotion_label)
|
|
|
115 |
content_score += 0.4
|
116 |
|
117 |
final_score = 0.5 * emotion_score + 0.5 * content_score
|
|
|
118 |
|
119 |
if final_score < 0.5 and top_intents:
|
120 |
intent = top_intents[0]
|
|
|
129 |
"intents": top_intents
|
130 |
}
|
131 |
session["support_required"] = "🔴 Human support required."
|
132 |
+
session["agent_reply"] = ""
|
133 |
|
134 |
if session["support_required"]:
|
135 |
st.markdown(f"### {session['support_required']}")
|