Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -408,6 +408,18 @@ def process_feedback(ease, clarity, engagement, satisfaction, cognitive_load, us
|
|
| 408 |
chat_history[-1] = (user_input, response)
|
| 409 |
return chat_history, user_state
|
| 410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
#############################################################################
|
| 413 |
# Chat Flow
|
|
@@ -671,99 +683,95 @@ def new_chat_input(chat_history, user_state, user_input, *args, **kwargs):
|
|
| 671 |
gr.update(visible=False),
|
| 672 |
gr.update(visible=False)
|
| 673 |
)
|
| 674 |
-
|
| 675 |
elif user_state["stage"] == "emotional_relevance":
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
chat_history[-1] = (user_input, response)
|
| 682 |
return (
|
| 683 |
-
chat_history,
|
| 684 |
-
user_state,
|
| 685 |
-
gr.update(visible=True, value=""),
|
| 686 |
-
gr.update(visible=False),
|
| 687 |
-
gr.update(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
)
|
| 689 |
|
| 690 |
-
|
| 691 |
-
user_state["standardized_data"][f'Emotional Relevance'] = int(emotional_relevance)
|
| 692 |
user_state["stage"] = "positive_valence"
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
chat_history[-1] = (user_input, response)
|
| 696 |
return (
|
| 697 |
-
chat_history,
|
| 698 |
-
user_state,
|
| 699 |
-
gr.update(visible=True, value=""),
|
| 700 |
-
gr.update(visible=False),
|
| 701 |
-
gr.update(visible=False)
|
| 702 |
-
)
|
| 703 |
|
| 704 |
elif user_state["stage"] == "positive_valence":
|
| 705 |
-
positive_valence =
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
response = "Sorry, I couldn't understand your response. Could you please rephrase or specify your choice?"
|
| 710 |
-
chat_history[-1] = (user_input, response)
|
| 711 |
return (
|
| 712 |
-
chat_history,
|
| 713 |
-
user_state,
|
| 714 |
-
gr.update(visible=True, value=""),
|
| 715 |
-
gr.update(visible=False),
|
| 716 |
-
gr.update(visible=False)
|
| 717 |
)
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
user_state["standardized_data"][f'Positive Valence'] = int(positive_valence)
|
| 721 |
user_state["stage"] = "negative_valence"
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
response = f"""How much discomfort or tension did you feel while imagining this scenario? (1 = None, 10 = A lot)"""
|
| 725 |
-
chat_history[-1] = (user_input, response)
|
| 726 |
return (
|
| 727 |
-
chat_history,
|
| 728 |
-
user_state,
|
| 729 |
-
gr.update(visible=True, value=""),
|
| 730 |
-
gr.update(visible=False),
|
| 731 |
-
gr.update(visible=False)
|
| 732 |
)
|
| 733 |
|
| 734 |
elif user_state["stage"] == "negative_valence":
|
| 735 |
-
negative_valence =
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
response = "Sorry, I couldn't understand your response. Could you please rephrase or specify your choice?"
|
| 740 |
-
chat_history[-1] = (user_input, response)
|
| 741 |
return (
|
| 742 |
-
chat_history,
|
| 743 |
-
user_state,
|
| 744 |
-
gr.update(visible=True, value=""),
|
| 745 |
-
gr.update(visible=False),
|
| 746 |
-
gr.update(visible=False)
|
| 747 |
)
|
| 748 |
|
| 749 |
-
|
| 750 |
-
user_state["standardized_data"][f'Negative Valence'] = int(negative_valence)
|
| 751 |
-
|
| 752 |
-
# Move to next stage
|
| 753 |
user_state["stage"] = "internal_external"
|
| 754 |
-
user_state['options_text'] = generate_internal_external_options(chat_history, user_state["standardized_data"][f'Vignette'], user_state)
|
| 755 |
response = (
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
|
|
|
| 761 |
return (
|
| 762 |
-
chat_history,
|
| 763 |
-
user_state,
|
| 764 |
-
gr.update(visible=False),
|
| 765 |
-
gr.update(visible=True
|
| 766 |
-
gr.update(visible=True)
|
| 767 |
)
|
| 768 |
|
| 769 |
elif user_state["stage"] == "vignette_regeneration":
|
|
|
|
| 408 |
chat_history[-1] = (user_input, response)
|
| 409 |
return chat_history, user_state
|
| 410 |
|
| 411 |
+
def validate_numeric_input(user_input, min_val=1, max_val=10):
|
| 412 |
+
"""
|
| 413 |
+
Attempts to convert user_input to an integer and ensures it's between min_val and max_val.
|
| 414 |
+
Returns (value, None) if valid, or (None, error_message) if invalid.
|
| 415 |
+
"""
|
| 416 |
+
try:
|
| 417 |
+
value = int(user_input.strip())
|
| 418 |
+
if value < min_val or value > max_val:
|
| 419 |
+
return None, f"Please provide a number between {min_val} and {max_val}."
|
| 420 |
+
return value, None
|
| 421 |
+
except ValueError:
|
| 422 |
+
return None, f"Please provide a number between {min_val} and {max_val}."
|
| 423 |
|
| 424 |
#############################################################################
|
| 425 |
# Chat Flow
|
|
|
|
| 683 |
gr.update(visible=False),
|
| 684 |
gr.update(visible=False)
|
| 685 |
)
|
| 686 |
+
|
| 687 |
elif user_state["stage"] == "emotional_relevance":
|
| 688 |
+
try:
|
| 689 |
+
emotional_relevance_int = int(user_input.strip())
|
| 690 |
+
except ValueError:
|
| 691 |
+
response = "Please provide a number between 1 and 10."
|
| 692 |
+
chat_history[-1] = (user_input, response)
|
|
|
|
| 693 |
return (
|
| 694 |
+
chat_history,
|
| 695 |
+
user_state,
|
| 696 |
+
gr.update(visible=True, value=""),
|
| 697 |
+
gr.update(visible=False),
|
| 698 |
+
gr.update(visible=False)
|
| 699 |
+
)
|
| 700 |
+
if emotional_relevance_int not in range(1, 11):
|
| 701 |
+
response = "Please provide a number between 1 and 10."
|
| 702 |
+
chat_history[-1] = (user_input, response)
|
| 703 |
+
return (
|
| 704 |
+
chat_history,
|
| 705 |
+
user_state,
|
| 706 |
+
gr.update(visible=True, value=""),
|
| 707 |
+
gr.update(visible=False),
|
| 708 |
+
gr.update(visible=False)
|
| 709 |
)
|
| 710 |
|
| 711 |
+
user_state["standardized_data"]["Emotional Relevance"] = emotional_relevance_int
|
|
|
|
| 712 |
user_state["stage"] = "positive_valence"
|
| 713 |
+
response = "How much joy, excitement, or satisfaction did this scenario evoke in you? (1 = None, 10 = A lot)"
|
| 714 |
+
chat_history[-1] = (user_input, response)
|
|
|
|
| 715 |
return (
|
| 716 |
+
chat_history,
|
| 717 |
+
user_state,
|
| 718 |
+
gr.update(visible=True, value=""),
|
| 719 |
+
gr.update(visible=False),
|
| 720 |
+
gr.update(visible=False)
|
|
|
|
| 721 |
|
| 722 |
elif user_state["stage"] == "positive_valence":
|
| 723 |
+
positive_valence, error = validate_numeric_input(user_input, 1, 10)
|
| 724 |
+
if error:
|
| 725 |
+
response = error
|
| 726 |
+
chat_history[-1] = (user_input, response)
|
|
|
|
|
|
|
| 727 |
return (
|
| 728 |
+
chat_history,
|
| 729 |
+
user_state,
|
| 730 |
+
gr.update(visible=True, value=""),
|
| 731 |
+
gr.update(visible=False),
|
| 732 |
+
gr.update(visible=False)
|
| 733 |
)
|
| 734 |
+
|
| 735 |
+
user_state["standardized_data"]['Positive Valence'] = positive_valence
|
|
|
|
| 736 |
user_state["stage"] = "negative_valence"
|
| 737 |
+
response = "How much discomfort or tension did you feel while imagining this scenario? (1 = None, 10 = A lot)"
|
| 738 |
+
chat_history[-1] = (user_input, response)
|
|
|
|
|
|
|
| 739 |
return (
|
| 740 |
+
chat_history,
|
| 741 |
+
user_state,
|
| 742 |
+
gr.update(visible=True, value=""),
|
| 743 |
+
gr.update(visible=False),
|
| 744 |
+
gr.update(visible=False)
|
| 745 |
)
|
| 746 |
|
| 747 |
elif user_state["stage"] == "negative_valence":
|
| 748 |
+
negative_valence, error = validate_numeric_input(user_input, 1, 10)
|
| 749 |
+
if error:
|
| 750 |
+
response = error
|
| 751 |
+
chat_history[-1] = (user_input, response)
|
|
|
|
|
|
|
| 752 |
return (
|
| 753 |
+
chat_history,
|
| 754 |
+
user_state,
|
| 755 |
+
gr.update(visible=True, value=""),
|
| 756 |
+
gr.update(visible=False),
|
| 757 |
+
gr.update(visible=False)
|
| 758 |
)
|
| 759 |
|
| 760 |
+
user_state["standardized_data"]['Negative Valence'] = negative_valence
|
|
|
|
|
|
|
|
|
|
| 761 |
user_state["stage"] = "internal_external"
|
|
|
|
| 762 |
response = (
|
| 763 |
+
f"Please read the scenario again and use the slider below to answer the next few questions:\n"
|
| 764 |
+
f"{user_state['vignette']}\n"
|
| 765 |
+
"\nImagine this situation is happening to you personally. From 1 to 10, which of the following statements do you think is more likely (1 = Definitely Option A, 10 = Definitely Option B):\n"
|
| 766 |
+
f"{user_state['options_text']}"
|
| 767 |
+
)
|
| 768 |
+
chat_history[-1] = (user_input, response)
|
| 769 |
return (
|
| 770 |
+
chat_history,
|
| 771 |
+
user_state,
|
| 772 |
+
gr.update(visible=False),
|
| 773 |
+
gr.update(visible=True),
|
| 774 |
+
gr.update(visible=True)
|
| 775 |
)
|
| 776 |
|
| 777 |
elif user_state["stage"] == "vignette_regeneration":
|