JoshuaZywoo commited on
Commit
223059a
·
verified ·
1 Parent(s): fb0a176

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -27,14 +27,13 @@ candidate_tasks = [
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
 
@@ -81,7 +80,8 @@ if selected_customer not in st.session_state.chat_sessions:
81
  "chat": [],
82
  "system_result": None,
83
  "agent_reply": "",
84
- "support_required": ""
 
85
  }
86
  session = st.session_state.chat_sessions[selected_customer]
87
 
@@ -95,12 +95,15 @@ for msg in session["chat"]:
95
 
96
  col1, col2 = st.columns([6,1])
97
  with col1:
98
- user_input = st.text_input("Enter customer message:", key="user_input")
99
  with col2:
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)
@@ -159,4 +162,5 @@ if st.button("End Conversation"):
159
  session["system_result"] = None
160
  session["agent_reply"] = ""
161
  session["support_required"] = ""
 
162
  st.success("Conversation ended and cleared.")
 
27
  def generate_response(intent, human=True):
28
  if human:
29
  prompt = (
30
+ f"Write a customer service message for intent '{intent}' using 3 clearly separated segments: "
31
+ "[Greeting] + [You currently have Plan X with ¥X/month. We recommend Plan Y offering XXGB at ¥Y/month.] + [Would you like to switch now?] "
32
+ "Use placeholder numbers and express one sentence per section."
33
  )
34
  else:
35
  prompt = (
36
+ f"Resolve customer request: '{intent}' in one short sentence directly addressing their need. Use clear and polite tone with placeholder plan/price."
 
37
  )
38
  return text_generator(prompt, max_new_tokens=80, do_sample=True)[0]['generated_text']
39
 
 
80
  "chat": [],
81
  "system_result": None,
82
  "agent_reply": "",
83
+ "support_required": "",
84
+ "user_input": ""
85
  }
86
  session = st.session_state.chat_sessions[selected_customer]
87
 
 
95
 
96
  col1, col2 = st.columns([6,1])
97
  with col1:
98
+ session["user_input"] = st.text_input("Enter customer message:", value=session["user_input"])
99
  with col2:
100
  analyze_clicked = st.button("Analyze", use_container_width=True)
101
 
102
+ if analyze_clicked and session["user_input"].strip():
103
+ user_input = session["user_input"]
104
  session["chat"].append({"role": "user", "content": user_input})
105
+ session["user_input"] = ""
106
+
107
  emotion_result = emotion_classifier(user_input)
108
  emotion_label = get_emotion_label(emotion_result, user_input)
109
  emotion_score = get_emotion_score(emotion_label)
 
162
  session["system_result"] = None
163
  session["agent_reply"] = ""
164
  session["support_required"] = ""
165
+ session["user_input"] = ""
166
  st.success("Conversation ended and cleared.")