Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -570,7 +570,7 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 570 |
"""
|
| 571 |
|
| 572 |
if user_state["vignette_counter"] == 1 and not user_state.get("welcome_message", False):
|
| 573 |
-
welcome_message = "
|
| 574 |
response = welcome_message + response
|
| 575 |
user_state["welcome_message"] = True
|
| 576 |
|
|
@@ -789,7 +789,7 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 789 |
user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
|
| 790 |
response = (
|
| 791 |
f"Please read the scenario again:\n{user_state['vignette']}\n"
|
| 792 |
-
"\nFrom 1 to 10, which of the following statements do you personally think is more likely (1 = Definitely Option
|
| 793 |
f"{user_state['options_text']}")
|
| 794 |
chat_history[-1] = (user_input, response)
|
| 795 |
return chat_history, user_state, ""
|
|
@@ -847,18 +847,20 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 847 |
'response': user_input
|
| 848 |
})
|
| 849 |
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 854 |
chat_history[-1] = (user_input, response)
|
| 855 |
-
return chat_history, user_state, ""
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
user_state["standardized_data"]['Raw Internal_External'] = int(user_input)
|
| 861 |
-
|
| 862 |
# Store the initial internal/external attribution numerically
|
| 863 |
if user_state["explanation_response"] == '1':
|
| 864 |
user_state["standardized_data"]['Initial Internal'] = 1
|
|
@@ -928,7 +930,7 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 928 |
response = (
|
| 929 |
f"Alright, noted. Now please imagine the following:\n\n"
|
| 930 |
f"{user_state['first_reveal']}\n\n"
|
| 931 |
-
"Based on these developments, on a scale from 1 to 10, which of the following statements seems more likely to you personally? (1 = Definitely Option
|
| 932 |
f"{user_state['options_text']}"
|
| 933 |
)
|
| 934 |
chat_history[-1] = (user_input, response)
|
|
@@ -964,20 +966,20 @@ def new_chat_input(user_input, chat_history, user_state, *args, **kwargs):
|
|
| 964 |
user_state["standardized_data"][f'Reassessment External'] = None
|
| 965 |
|
| 966 |
user_state["stage"] = "likelihood_of_change"
|
| 967 |
-
response = "On a scale from 1 to 10: Based on the new information, how likely are you to change your initial interpretation of the scene? (1 = least likely, 10 = most likely)"
|
| 968 |
-
chat_history[-1] = (user_input, response)
|
| 969 |
-
return chat_history, user_state, ""
|
| 970 |
|
| 971 |
elif user_state["stage"] == "likelihood_of_change":
|
| 972 |
-
# user_input = fn_input("You: ")
|
| 973 |
-
input = standardize_response("Please extract the user's rating on a scale from 1 to 10.", user_input)
|
| 974 |
-
user_state["user_responses"].append({'user_state["stage"]': 'likelihood_of_change', 'response': input})
|
| 975 |
-
if input not in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']:
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
|
| 980 |
-
user_state["standardized_data"][f'Likelihood of Change'] = int(input)
|
| 981 |
user_state["vignette_counter"] += 1 # Move to the next vignette
|
| 982 |
|
| 983 |
# If all vignettes are complete, transition to usability feedback
|
|
@@ -1272,13 +1274,30 @@ with gr.Blocks(theme= gr.themes.Glass()) as app:
|
|
| 1272 |
placeholder="Type your response here...",
|
| 1273 |
lines=1)
|
| 1274 |
|
| 1275 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1276 |
user_message.submit(
|
| 1277 |
fn=new_chat_input,
|
| 1278 |
inputs=[user_message, chatbot, user_state],
|
| 1279 |
-
outputs=[chatbot, user_state, user_message],
|
| 1280 |
queue=False # Disable queueing for real-time streaming
|
| 1281 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1282 |
|
| 1283 |
######################################################################
|
| 1284 |
# Transition Logic
|
|
|
|
| 570 |
"""
|
| 571 |
|
| 572 |
if user_state["vignette_counter"] == 1 and not user_state.get("welcome_message", False):
|
| 573 |
+
welcome_message = "Alright then! "
|
| 574 |
response = welcome_message + response
|
| 575 |
user_state["welcome_message"] = True
|
| 576 |
|
|
|
|
| 789 |
user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
|
| 790 |
response = (
|
| 791 |
f"Please read the scenario again:\n{user_state['vignette']}\n"
|
| 792 |
+
"\nFrom 1 to 10, which of the following statements do you personally think is more likely (1 = Definitely Option A, 10 = Definitely Option B):\n"
|
| 793 |
f"{user_state['options_text']}")
|
| 794 |
chat_history[-1] = (user_input, response)
|
| 795 |
return chat_history, user_state, ""
|
|
|
|
| 847 |
'response': user_input
|
| 848 |
})
|
| 849 |
|
| 850 |
+
# Validate the response and store the raw rating
|
| 851 |
+
try:
|
| 852 |
+
assessment_rating = int(user_input)
|
| 853 |
+
if assessment_rating < 1 or assessment_rating > 10:
|
| 854 |
+
raise ValueError
|
| 855 |
+
user_state["standardized_data"]['Raw Internal_External'] = assessment_rating
|
| 856 |
+
except ValueError:
|
| 857 |
+
response = "Please provide a number between 1 and 10."
|
| 858 |
chat_history[-1] = (user_input, response)
|
| 859 |
+
return chat_history, user_state, ""
|
| 860 |
+
|
| 861 |
+
# Map the rating to the binary classification
|
| 862 |
+
user_state["explanation_response"] = '1' if assessment_rating <= 5 else '2'
|
| 863 |
+
|
|
|
|
|
|
|
| 864 |
# Store the initial internal/external attribution numerically
|
| 865 |
if user_state["explanation_response"] == '1':
|
| 866 |
user_state["standardized_data"]['Initial Internal'] = 1
|
|
|
|
| 930 |
response = (
|
| 931 |
f"Alright, noted. Now please imagine the following:\n\n"
|
| 932 |
f"{user_state['first_reveal']}\n\n"
|
| 933 |
+
"Based on these developments, on a scale from 1 to 10, which of the following statements seems more likely to you personally? (1 = Definitely Option A, 10 = Definitely Option B):\n"
|
| 934 |
f"{user_state['options_text']}"
|
| 935 |
)
|
| 936 |
chat_history[-1] = (user_input, response)
|
|
|
|
| 966 |
user_state["standardized_data"][f'Reassessment External'] = None
|
| 967 |
|
| 968 |
user_state["stage"] = "likelihood_of_change"
|
| 969 |
+
# response = "On a scale from 1 to 10: Based on the new information, how likely are you to change your initial interpretation of the scene? (1 = least likely, 10 = most likely)"
|
| 970 |
+
# chat_history[-1] = (user_input, response)
|
| 971 |
+
# return chat_history, user_state, ""
|
| 972 |
|
| 973 |
elif user_state["stage"] == "likelihood_of_change":
|
| 974 |
+
# # user_input = fn_input("You: ")
|
| 975 |
+
# input = standardize_response("Please extract the user's rating on a scale from 1 to 10.", user_input)
|
| 976 |
+
# user_state["user_responses"].append({'user_state["stage"]': 'likelihood_of_change', 'response': input})
|
| 977 |
+
# if input not in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']:
|
| 978 |
+
# response = "Sorry, I couldn't understand your response. Could you please rephrase or specify your choice?"
|
| 979 |
+
# chat_history[-1] = (user_input, response)
|
| 980 |
+
# return chat_history, user_state, ""
|
| 981 |
|
| 982 |
+
# user_state["standardized_data"][f'Likelihood of Change'] = int(input)
|
| 983 |
user_state["vignette_counter"] += 1 # Move to the next vignette
|
| 984 |
|
| 985 |
# If all vignettes are complete, transition to usability feedback
|
|
|
|
| 1274 |
placeholder="Type your response here...",
|
| 1275 |
lines=1)
|
| 1276 |
|
| 1277 |
+
# Slider for Internal/External Attribution (Initially Hidden)
|
| 1278 |
+
attribution_slider = gr.Slider(
|
| 1279 |
+
minimum=1,
|
| 1280 |
+
maximum=10,
|
| 1281 |
+
step=1,
|
| 1282 |
+
label="Definitely Option 1 Definitely Option 2",
|
| 1283 |
+
visible=False # Hidden by default
|
| 1284 |
+
)
|
| 1285 |
+
|
| 1286 |
+
# Submit handler for text input
|
| 1287 |
user_message.submit(
|
| 1288 |
fn=new_chat_input,
|
| 1289 |
inputs=[user_message, chatbot, user_state],
|
| 1290 |
+
outputs=[chatbot, user_state, user_message, attribution_slider],
|
| 1291 |
queue=False # Disable queueing for real-time streaming
|
| 1292 |
)
|
| 1293 |
+
|
| 1294 |
+
# Change handler for slider input
|
| 1295 |
+
attribution_slider.change(
|
| 1296 |
+
fn=handle_attribution_slider,
|
| 1297 |
+
inputs=[attribution_slider, chatbot, user_state],
|
| 1298 |
+
outputs=[chatbot, user_state, attribution_slider],
|
| 1299 |
+
queue=False
|
| 1300 |
+
)
|
| 1301 |
|
| 1302 |
######################################################################
|
| 1303 |
# Transition Logic
|