Nelly-43 commited on
Commit
b5e4252
Β·
1 Parent(s): 3068ee8

add feedback prompt

Browse files
Files changed (1) hide show
  1. app_web.py +37 -2
app_web.py CHANGED
@@ -65,6 +65,37 @@ def init_session():
65
  st.session_state.stata_file = None
66
  if "chat_id" not in st.session_state:
67
  st.session_state.chat_id = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
 
70
  # ── Sidebar ──────────────────────────────────────────────────────────────────
@@ -290,7 +321,7 @@ def process_contact_request(original_query:str, qcat_result:Dict, uploaded_files
290
  #save ticket
291
  with open(f"{DATA_DIR}/tickets/{ticket}/contact_data.json", "w", encoding="utf-8") as f:
292
  json.dump(contact_data, f, indent=4)
293
-
294
  if qcat_result.get("action") == "upload":
295
  if uploaded_files:
296
  # Specify the path where the zip file will be saved
@@ -382,6 +413,7 @@ def render_chat():
382
  """Render the chat interface with message history and input."""
383
  cfg = st.session_state.cfg
384
 
 
385
  # Display chat history
386
  for i, msg in enumerate(st.session_state.messages):
387
  with st.chat_message(msg["role"]):
@@ -396,8 +428,11 @@ def render_chat():
396
  # Pre-populate if feedback already exists in history
397
  default=msg.get("feedback", None),
398
  )
 
 
399
 
400
-
 
401
  # Chat input
402
  user_input = st.chat_input("Ask a question about your knowledge base...",
403
  accept_file="multiple",
 
65
  st.session_state.stata_file = None
66
  if "chat_id" not in st.session_state:
67
  st.session_state.chat_id = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
68
+ if "feddback_data" not in st.session_state:
69
+ st.session_state.feddback_data = None
70
+
71
+ @st.dialog("Provide Your Feedback")
72
+ def feedback_prompt():
73
+ st.write("How would you rate your WEAIBot experience?")
74
+
75
+ # Built-in Streamlit feedback widget (thumbs or stars)
76
+ rating = st.feedback("faces") # or st.feedback("stars")
77
+
78
+ # Optional text details
79
+ comments = st.text_area("Tell us more (optional):")
80
+ feedback_data = {
81
+ "rating": rating,
82
+ "comments": comments,
83
+ }
84
+ col1, col2 = st.columns(2)
85
+
86
+ with col1:
87
+ if st.button("Submit Feedback", type="primary", use_container_width=True):
88
+ # Save feedback to session state or database
89
+ st.session_state["feedback_data"] = feedback_data
90
+ st.toast("Thank you for your feedback!", icon="πŸŽ‰")
91
+
92
+ with open(f"{DATA_DIR}/logs/{st.session_state.chat_id}/feedback.json", "w", encoding="utf-8") as f:
93
+ json.dump(feedback_data, f, indent=4)
94
+
95
+ st.rerun()
96
+ with col2:
97
+ if st.button("Cancel", use_container_width=True):
98
+ st.rerun()
99
 
100
 
101
  # ── Sidebar ──────────────────────────────────────────────────────────────────
 
321
  #save ticket
322
  with open(f"{DATA_DIR}/tickets/{ticket}/contact_data.json", "w", encoding="utf-8") as f:
323
  json.dump(contact_data, f, indent=4)
324
+
325
  if qcat_result.get("action") == "upload":
326
  if uploaded_files:
327
  # Specify the path where the zip file will be saved
 
413
  """Render the chat interface with message history and input."""
414
  cfg = st.session_state.cfg
415
 
416
+ queries = 0
417
  # Display chat history
418
  for i, msg in enumerate(st.session_state.messages):
419
  with st.chat_message(msg["role"]):
 
428
  # Pre-populate if feedback already exists in history
429
  default=msg.get("feedback", None),
430
  )
431
+ if msg["role"] == "user":
432
+ queries += 1
433
 
434
+ if len(queries)>4 and st.session_state.feedback_data is None:
435
+ feedback_prompt()
436
  # Chat input
437
  user_input = st.chat_input("Ask a question about your knowledge base...",
438
  accept_file="multiple",