Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -96,6 +96,8 @@ if 'system_result' not in st.session_state:
|
|
96 |
st.session_state.system_result = None
|
97 |
if 'agent_reply' not in st.session_state:
|
98 |
st.session_state.agent_reply = ""
|
|
|
|
|
99 |
|
100 |
# Always show conversation
|
101 |
st.markdown("### Conversation")
|
@@ -133,25 +135,32 @@ if analyze_clicked and user_input.strip():
|
|
133 |
intent = top_intents[0]
|
134 |
response = f"Thank you for contacting us. I understand your concern. {intent_solutions[intent]} {intent_closings[intent]}"
|
135 |
st.session_state.chat.append({"role": "assistant", "content": response})
|
|
|
|
|
136 |
else:
|
137 |
st.session_state.system_result = {
|
138 |
"emotion": emotion_label,
|
139 |
"tone": "Urgent" if emotion_score > 0.8 else "Concerned" if emotion_score > 0.5 else "Calm",
|
140 |
"intents": top_intents
|
141 |
}
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
st.
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
155 |
st.markdown("#### Customer Status")
|
156 |
st.markdown(f"- **Emotion:** {st.session_state.system_result['emotion'].capitalize()}")
|
157 |
st.markdown(f"- **Tone:** {st.session_state.system_result['tone']}")
|
|
|
96 |
st.session_state.system_result = None
|
97 |
if 'agent_reply' not in st.session_state:
|
98 |
st.session_state.agent_reply = ""
|
99 |
+
if 'support_required' not in st.session_state:
|
100 |
+
st.session_state.support_required = ""
|
101 |
|
102 |
# Always show conversation
|
103 |
st.markdown("### Conversation")
|
|
|
135 |
intent = top_intents[0]
|
136 |
response = f"Thank you for contacting us. I understand your concern. {intent_solutions[intent]} {intent_closings[intent]}"
|
137 |
st.session_state.chat.append({"role": "assistant", "content": response})
|
138 |
+
st.session_state.system_result = None
|
139 |
+
st.session_state.support_required = "🟢 Automated response handled this request."
|
140 |
else:
|
141 |
st.session_state.system_result = {
|
142 |
"emotion": emotion_label,
|
143 |
"tone": "Urgent" if emotion_score > 0.8 else "Concerned" if emotion_score > 0.5 else "Calm",
|
144 |
"intents": top_intents
|
145 |
}
|
146 |
+
st.session_state.support_required = "🔴 Human support required."
|
147 |
+
|
148 |
+
# Show support need status
|
149 |
+
if st.session_state.support_required:
|
150 |
+
st.markdown(f"### {st.session_state.support_required}")
|
151 |
+
|
152 |
+
# Always show agent input box
|
153 |
+
st.subheader("Agent Response Console")
|
154 |
+
st.session_state.agent_reply = st.text_area("Compose your reply:", value=st.session_state.agent_reply)
|
155 |
+
if st.button("Send Reply"):
|
156 |
+
if st.session_state.agent_reply.strip():
|
157 |
+
st.session_state.chat.append({"role": "assistant", "content": st.session_state.agent_reply})
|
158 |
+
st.session_state.agent_reply = ""
|
159 |
+
st.session_state.system_result = None
|
160 |
+
st.session_state.support_required = ""
|
161 |
+
|
162 |
+
# If human support needed, show status and suggestions
|
163 |
+
if st.session_state.system_result is not None:
|
164 |
st.markdown("#### Customer Status")
|
165 |
st.markdown(f"- **Emotion:** {st.session_state.system_result['emotion'].capitalize()}")
|
166 |
st.markdown(f"- **Tone:** {st.session_state.system_result['tone']}")
|