Spaces:
Sleeping
Sleeping
Zekun Wu
commited on
Commit
•
727d404
1
Parent(s):
07aabce
add
Browse files
app.py
CHANGED
@@ -190,7 +190,19 @@ def main_app():
|
|
190 |
# Ask for feedback
|
191 |
st.markdown(st.session_state['analysis'])
|
192 |
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
criteria = {
|
196 |
"Faithfulness": "Are all claims made in the answer inferred from the given context, i.e., not hallucinated?",
|
@@ -203,12 +215,17 @@ def main_app():
|
|
203 |
|
204 |
ratings = {}
|
205 |
for criterion, description in criteria.items():
|
206 |
-
ratings[criterion] = st.slider(f"{criterion}: {description}", 0, 10, 5,key=f"
|
207 |
|
208 |
-
feedback = st.text_input("Provide additional feedback on the response:",key=f"
|
209 |
|
210 |
if st.button('Submit Report Feedback'):
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
212 |
st.success("Feedback submitted successfully!")
|
213 |
|
214 |
|
@@ -333,37 +350,13 @@ def sidebar_components():
|
|
333 |
|
334 |
if st.sidebar.button('Submit'):
|
335 |
if user_input:
|
|
|
336 |
if st.session_state['chat_context'] == "profile":
|
337 |
chat_prompt_template = create_chat_prompt_template(get_profile_str(st.session_state['profile']),st.session_state['definition'])
|
338 |
else:
|
339 |
chat_prompt_template = create_chat_prompt_template(st.session_state['analysis'],st.session_state['definition'])
|
340 |
-
|
341 |
-
|
342 |
-
st.sidebar.markdown(response)
|
343 |
-
|
344 |
-
st.markdown("Provide feedback on the response:")
|
345 |
-
|
346 |
-
# Feedback criteria
|
347 |
-
st.sidebar.markdown("## Feedback Criteria")
|
348 |
-
criteria = {
|
349 |
-
"Faithfulness": "Are all claims made in the answer inferred from the given context, i.e., not hallucinated?",
|
350 |
-
"Answer Relevancy": "Is the answer relevant to the question?",
|
351 |
-
"Context Relevancy": "Is the context relevant to the question?",
|
352 |
-
"Correctness": "Is the answer factually correct, based on the context?",
|
353 |
-
"Clarity": "Is the answer explained clearly without the extensive jargon of the original document?",
|
354 |
-
"Completeness": "Is the question answered fully, with all parts and subquestions being addressed?",
|
355 |
-
}
|
356 |
-
ratings = {}
|
357 |
-
for criterion, description in criteria.items():
|
358 |
-
ratings[criterion] = st.sidebar.slider(f"{criterion}: {description}", 0, 10, 5,key=f"report {criterion}")
|
359 |
-
|
360 |
-
# Ask for feedback
|
361 |
-
feedback = st.sidebar.text_input("Provide additional feedback on the response:",key=f"report feedback")
|
362 |
-
|
363 |
-
if st.sidebar.button('Submit Coach Feedback'):
|
364 |
-
store_feedback(user_input, response, feedback, str(ratings), "wu981526092/feedback_coach")
|
365 |
-
time.sleep(10)
|
366 |
-
st.sidebar.success("Feedback submitted successfully!")
|
367 |
|
368 |
|
369 |
|
@@ -378,7 +371,9 @@ session_defaults = {
|
|
378 |
'version': "",
|
379 |
'username': '',
|
380 |
'password': '',
|
381 |
-
'authenticated': False
|
|
|
|
|
382 |
}
|
383 |
|
384 |
for key, default in session_defaults.items():
|
@@ -390,38 +385,3 @@ if st.session_state['authenticated']:
|
|
390 |
main_app()
|
391 |
else:
|
392 |
login_page()
|
393 |
-
|
394 |
-
# # Display the sidebar components based on the state
|
395 |
-
# if 'show_chat' not in st.session_state:
|
396 |
-
# st.session_state['show_chat'] = None
|
397 |
-
#
|
398 |
-
# if 'definition' not in st.session_state:
|
399 |
-
# st.session_state['definition'] = 1
|
400 |
-
#
|
401 |
-
# if 'chat_context' not in st.session_state:
|
402 |
-
# st.session_state['chat_context'] = "analysis"
|
403 |
-
#
|
404 |
-
# if 'profile' not in st.session_state:
|
405 |
-
# st.session_state['profile'] = None
|
406 |
-
#
|
407 |
-
# if 'analysis' not in st.session_state:
|
408 |
-
# st.session_state['analysis'] = None
|
409 |
-
#
|
410 |
-
# if 'temperature' not in st.session_state:
|
411 |
-
# st.session_state['temperature'] = 0
|
412 |
-
#
|
413 |
-
# if 'version' not in st.session_state:
|
414 |
-
# st.session_state['version'] = ""
|
415 |
-
#
|
416 |
-
# # Initialize session state for username, password, and authentication
|
417 |
-
# if 'username' not in st.session_state:
|
418 |
-
# st.session_state['username'] = ''
|
419 |
-
# if 'password' not in st.session_state:
|
420 |
-
# st.session_state['password'] = ''
|
421 |
-
# if 'authenticated' not in st.session_state:
|
422 |
-
# st.session_state['authenticated'] = False
|
423 |
-
# # Show login or main app based on authentication
|
424 |
-
# if st.session_state['authenticated']:
|
425 |
-
# main_app()
|
426 |
-
# else:
|
427 |
-
# login_page()
|
|
|
190 |
# Ask for feedback
|
191 |
st.markdown(st.session_state['analysis'])
|
192 |
|
193 |
+
# Ask the user to choose the type of feedback
|
194 |
+
feedback_type = st.selectbox(
|
195 |
+
"Select the type of feedback:",
|
196 |
+
["Report", "Coach"]
|
197 |
+
)
|
198 |
+
|
199 |
+
# Set the dataset identifier based on feedback type
|
200 |
+
if feedback_type == "Report":
|
201 |
+
dataset_id = "wu981526092/feedback_report"
|
202 |
+
else:
|
203 |
+
dataset_id = "wu981526092/feedback_coach"
|
204 |
+
|
205 |
+
st.markdown(f"Provide feedback on the {feedback_type.lower()}:")
|
206 |
|
207 |
criteria = {
|
208 |
"Faithfulness": "Are all claims made in the answer inferred from the given context, i.e., not hallucinated?",
|
|
|
215 |
|
216 |
ratings = {}
|
217 |
for criterion, description in criteria.items():
|
218 |
+
ratings[criterion] = st.slider(f"{criterion}: {description}", 0, 10, 5,key=f"{feedback_type} {criterion}")
|
219 |
|
220 |
+
feedback = st.text_input("Provide additional feedback on the response:",key=f"{feedback_type} feedback")
|
221 |
|
222 |
if st.button('Submit Report Feedback'):
|
223 |
+
if feedback_type == "Report":
|
224 |
+
store_feedback(str(generate_prompt_from_profile(profile, version=st.session_state['version'])), st.session_state['analysis'], feedback, str(ratings), dataset_id)
|
225 |
+
else:
|
226 |
+
store_feedback(st.session_state['coach_query'], st.session_state['coach_response'], feedback, str(ratings), dataset_id)
|
227 |
+
|
228 |
+
|
229 |
st.success("Feedback submitted successfully!")
|
230 |
|
231 |
|
|
|
350 |
|
351 |
if st.sidebar.button('Submit'):
|
352 |
if user_input:
|
353 |
+
st.session_state['coach_query'] = user_input
|
354 |
if st.session_state['chat_context'] == "profile":
|
355 |
chat_prompt_template = create_chat_prompt_template(get_profile_str(st.session_state['profile']),st.session_state['definition'])
|
356 |
else:
|
357 |
chat_prompt_template = create_chat_prompt_template(st.session_state['analysis'],st.session_state['definition'])
|
358 |
+
st.session_state['coach_response'] = execute_query(index, chat_prompt_template, user_input)
|
359 |
+
st.sidebar.markdown(st.session_state['coach_response'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
|
361 |
|
362 |
|
|
|
371 |
'version': "",
|
372 |
'username': '',
|
373 |
'password': '',
|
374 |
+
'authenticated': False,
|
375 |
+
'coach_response':"",
|
376 |
+
'coach_query':""
|
377 |
}
|
378 |
|
379 |
for key, default in session_defaults.items():
|
|
|
385 |
main_app()
|
386 |
else:
|
387 |
login_page()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|