John Graham Reynolds commited on
Commit
35c020a
Β·
1 Parent(s): 64c7a70

Add Feedback Button that uses the st.feedback module

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -70,6 +70,27 @@ def clear_chat_history():
70
 
71
  st.button('Clear Chat', on_click=clear_chat_history)
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # build our chain outside the working body so that its only instantiated once - simply pass it the chat history for chat completion
74
  chain = ChainBuilder().build_chain()
75
 
@@ -211,16 +232,6 @@ def handle_user_input(user_input):
211
 
212
  st.session_state["messages"].append({"role": "assistant", "content": response, "warning": stream_warning, "error": stream_error})
213
 
214
- # def feedback():
215
- # feedback = st.text_input("Please enter your feedback:")
216
- # rating = st.radio("Rate your experience:", ["πŸ‘", "Neutral", "πŸ‘Ž"])
217
- # review = {"rating": {rating}, "feedback": {feedback}}
218
- # # Save the feedback data
219
- # if st.button("Submit"):
220
- # with open("feedback.json", "a") as f:
221
- # f.write()
222
- # st.write("Thank you for your feedback!")
223
-
224
  main = st.container()
225
  with main:
226
  history = st.container(height=400)
@@ -235,7 +246,6 @@ with main:
235
  # receive feedback on AI outputs if the user feels inclined to give it
236
  # rating = st.radio("Rate your experience:", ["Very satisfied", "Somewhat satisfied", "Neutral", "Somewhat dissatisfied", "Very dissatisfied"])
237
  # st.button("Provide Feedback", on_click=feedback)
238
- st.button("Provide Feedback", key="feedback")
239
  if message["error"] is not None:
240
  st.error(message["error"],icon="🚨")
241
  if message["warning"] is not None:
 
70
 
71
  st.button('Clear Chat', on_click=clear_chat_history)
72
 
73
+ def feedback():
74
+ with st.container():
75
+ sentiment_mapping = [":material/thumb_down:", ":material/thumb_up:"]
76
+ rating = st.feedback()
77
+ # feedback = ""
78
+ if rating is not None:
79
+ st.markdown(f"You selected: {sentiment_mapping[rating]}")
80
+
81
+ feedback = st.text_input("Please detail your rationale for choosing {sentiment_mapping[selected]}: ", "")
82
+ # rating = st.radio("Rate your experience:", ["πŸ‘", "Neutral", "πŸ‘Ž"])
83
+ review = {"rating": {rating}, "feedback": {feedback}}
84
+ st.markdown(review)
85
+ # # Save the feedback data
86
+ # if st.button("Submit"):
87
+ # with open("feedback.json", "a") as f:
88
+ # f.write()
89
+ # st.write("Thank you for your feedback!")
90
+
91
+
92
+ st.button('Give Feedback on Last Response', on_click=feedback)
93
+
94
  # build our chain outside the working body so that its only instantiated once - simply pass it the chat history for chat completion
95
  chain = ChainBuilder().build_chain()
96
 
 
232
 
233
  st.session_state["messages"].append({"role": "assistant", "content": response, "warning": stream_warning, "error": stream_error})
234
 
 
 
 
 
 
 
 
 
 
 
235
  main = st.container()
236
  with main:
237
  history = st.container(height=400)
 
246
  # receive feedback on AI outputs if the user feels inclined to give it
247
  # rating = st.radio("Rate your experience:", ["Very satisfied", "Somewhat satisfied", "Neutral", "Somewhat dissatisfied", "Very dissatisfied"])
248
  # st.button("Provide Feedback", on_click=feedback)
 
249
  if message["error"] is not None:
250
  st.error(message["error"],icon="🚨")
251
  if message["warning"] is not None: