import openai import os import time import datetime import string import random import numpy as np import pandas as pd import codecs import gradio as gr print (gr.__version__) import re import psycopg2 from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT from feedback_generation_function import * # import boto3 print ("finished import") pre_load_situations = pd.read_csv('mturk_id_situation_goal_difficulty.csv') MODEL_NAME = 'gpt-3.5-turbo-0613' # GPT 4 alternative: 'gpt-4-0613' AWS_REGION = "us-east-2" DB_INSTANCE_IDENTIFIER = "chat-annotation" DB_USER = "ilin" DB_PASSWORD = os.environ["DB_PASSWORD"] DB_ENDPOINT = os.environ["DB_ENDPOINT"] DB_PORT = 8080 DB_NAME = "postgres" openai.api_key = os.environ["OPENAI_API_KEY"] # openai.api_key = os.getenv("OPENAI_API_KEY") TABLE_NAME = "user_study_t" #TODO: change this table name css = """ #chuanhu_chatbot { height: 100%; min-height: 400px; } body { max-width: 1000px; margin: 0 auto; } [class *= "message"] { border-radius: var(--radius-xl) !important; border: none; padding: var(--spacing-xl) !important; font-size: var(--text-md) !important; line-height: var(--line-md) !important; min-height: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl)); min-width: calc(var(--text-md)*var(--line-md) + 2*var(--spacing-xl)); } [data-testid = "bot"] { max-width: 67%; border-bottom-left-radius: 0 !important; } [data-testid = "user"] { max-width: 67%; width: auto !important; border-bottom-right-radius: 0 !important; } #emp { color: #8A2BE2; font-weight:bold; } #step { background-color: #8A2BE2; border-radius: 5px; padding: 8px; font-weight:bold; color: white;} """ # user_ID = "test_user" # id of the annotator # Establish connection to RDS instance try: conn = psycopg2.connect(host=DB_ENDPOINT, port=DB_PORT, dbname=DB_NAME, user=DB_USER, password=DB_PASSWORD) except Exception as e: print (e) # Check if "annotations" table exists, if not, set up the table table_check_query = """ SELECT EXISTS ( SELECT FROM information_schema.tables WHERE table_name = '""" + TABLE_NAME + """' ); """ with conn.cursor() as cursor: cursor.execute(table_check_query) table_exists = cursor.fetchone()[0] print ("table exists? ", table_exists) if not table_exists: column_defs = [ "user_id varchar(255)", "action varchar(255)", "content text", "timestamp timestamp", ] formatted_column_defs = ", ".join(column_defs) create_table_query = f"CREATE TABLE {TABLE_NAME} (id serial PRIMARY KEY, {formatted_column_defs});" with conn.cursor() as cur: cur.execute(create_table_query) conn.commit() conn.close() print ("table is ready") # Gradio Demo starts here LIST_OF_DEARMAN_DIMENSIONS = ['describe', 'express','assert','reinforce','mindful','confident','negotiate'] LIST_OF_NVC_DIMENSIONS = ['observations','feelings','needs','requests','empathy','self-empathy'] def generate_system_input_few_shot(user_id, user_character_input, user_input,user_situation_category): MAX_RETRIES = 5 current_tries = 1 few_shot_learning_prompt = "Character: My husband \n Situation: My husband always comes home late and he doesn't text me or call me. \n Prompt: Act like my husband who always comes home late without calling or texting me. \n Character: My boss \nPrompt: Act like my boss who regularly calls me on weekends but I don't want to work on the weekends. \n Character: My friend \n Situation: My friend has depression and she relies on me 24/7 and I feel drained \nPrompt: Act like my friend who has depression and who relies on me whenever you have an issue and I want to convince you to seek professional help and not rely on a friend for all your issues. \nCharacter: My neighbor \n Situation: My neighbor frequently plays loud music at a late hour and hosts big parties, which affect my sleep. \nPrompt: Act like my neighbor. You frequently play loud music at a late hour and host big parties. \nCharacter: A customer service agent \n Situation: The airline lost my luggage and the customer service agents have been passing the buck \nPrompt: Act like a customer service agent. Your airline lost my luggage and your colleagues have been passing the buck. \n" if user_character_input == '' or user_input == '' or user_situation_category == []: curr_response_str = "" prompt_error_message = "Please make sure to fill in all fields." else: prompt_error_message = "" prompt_character = "Character: " + user_character_input + " \n" # prompt_personality = "Personality: " + user_personality_input + " \n" prompt_situation = "Situation: " + user_input + " \n" # prompt_goal = "Goal: " + user_goal_input + " \n" prompt = [{"role":"system", "content":"few-shot learning."}, {"role":"user", "content": few_shot_learning_prompt+prompt_character + prompt_situation +"Prompt:"}] while current_tries <= MAX_RETRIES: try: response = openai.ChatCompletion.create( model=MODEL_NAME, messages = prompt, max_tokens = 256 ) print (prompt) break except Exception as e: print('error: ', str(e)) print('response retrying') current_tries += 1 if current_tries > MAX_RETRIES: break time.sleep(5) curr_response_str = response['choices'][0]['message']['content'].replace('\n', ' ').strip() print(curr_response_str) record_chat_message(user_id, "user_input_context", user_input) record_chat_message(user_id, "system_prompt_context", curr_response_str) return curr_response_str, prompt_error_message def generate_system_input_few_shot_and_confirm(user_id, user_character_input, user_input,user_situation_category): MAX_RETRIES = 5 current_tries = 1 few_shot_learning_prompt = "Character: My husband \n Situation: My husband always comes home late and he doesn't text me or call me. \n Prompt: Act like my husband who always comes home late without calling or texting me. \n Character: My boss \nPrompt: Act like my boss who regularly calls me on weekends but I don't want to work on the weekends. \n Character: My friend \n Situation: My friend has depression and she relies on me 24/7 and I feel drained \nPrompt: Act like my friend who has depression and who relies on me whenever you have an issue and I want to convince you to seek professional help and not rely on a friend for all your issues. \nCharacter: My neighbor \n Situation: My neighbor frequently plays loud music at a late hour and hosts big parties, which affect my sleep. \nPrompt: Act like my neighbor. You frequently play loud music at a late hour and host big parties. \nCharacter: A customer service agent \n Situation: The airline lost my luggage and the customer service agents have been passing the buck \nPrompt: Act like a customer service agent. Your airline lost my luggage and your colleagues have been passing the buck. \n" if user_character_input == '' or user_input == '' or user_situation_category == []: curr_response_str = "" prompt_error_message = "Please make sure to fill in all fields." else: prompt_error_message = "" prompt_character = "Character: " + user_character_input + " \n" # prompt_personality = "Personality: " + user_personality_input + " \n" prompt_situation = "Situation: " + user_input + " \n" # prompt_goal = "Goal: " + user_goal_input + " \n" prompt = [{"role":"system", "content":"few-shot learning."}, {"role":"user", "content": few_shot_learning_prompt+prompt_character + prompt_situation +"Prompt:"}] while current_tries <= MAX_RETRIES: try: response = openai.ChatCompletion.create( model=MODEL_NAME, messages = prompt, max_tokens = 256 ) print (prompt) break except Exception as e: print('error: ', str(e)) print('response retrying') current_tries += 1 if current_tries > MAX_RETRIES: break time.sleep(5) curr_response_str = response['choices'][0]['message']['content'].replace('\n', ' ').strip() print(curr_response_str) record_chat_message(user_id, "user_input_context", user_input) record_chat_message(user_id, "system_prompt_context", curr_response_str) return curr_response_str, prompt_error_message, gr.update(visible=True) def generate_system_input_situation_only(user_id, user_input, situation_num): # situation_num should be situation1 or situation2, or situation_given MAX_RETRIES = 5 current_tries = 1 few_shot_learning_prompt = "Situation: My husband always comes home late and he doesn't text me or call me.\nPrompt: Act like my husband who always comes home late without calling or texting me.\nPrompt: Act like my boss who regularly calls me on weekends but I don't want to work on the weekends.\n Situation: My friend has depression and she relies on me 24/7 and I feel drained\nPrompt: Act like my friend who has depression and who relies on me whenever you have an issue and I want to convince you to seek professional help and not rely on a friend for all your issues.\nSituation: My neighbor frequently plays loud music at a late hour and hosts big parties, which affect my sleep.\nPrompt: Act like my neighbor. You frequently play loud music at a late hour and host big parties.\nSituation: The airline lost my luggage and the customer service agents have been passing the buck \nPrompt: Act like a customer service agent. Your airline lost my luggage and your colleagues have been passing the buck.\n" if user_input == '': curr_response_str = "" prompt_error_message = "Input not loading properly" else: prompt_error_message = "" # prompt_character = "Character: " + user_character_input + " \n" # prompt_personality = "Personality: " + user_personality_input + " \n" prompt_situation = "Situation: " + user_input + " \n" # prompt_goal = "Goal: " + user_goal_input + " \n" prompt = [{"role":"system", "content":"few-shot learning."}, {"role":"user", "content": few_shot_learning_prompt+ prompt_situation +"Prompt:"}] while current_tries <= MAX_RETRIES: try: response = openai.ChatCompletion.create( model=MODEL_NAME, messages = prompt, max_tokens = 256 ) print (prompt) print ("few shot prompt worked...") break except Exception as e: print('error: ', str(e)) print('response retrying') current_tries += 1 if current_tries > MAX_RETRIES: break time.sleep(5) curr_response_str = response['choices'][0]['message']['content'].replace('\n', ' ').strip() print(curr_response_str) # record_chat_message(user_id, "user_input_context", user_input) # this info should already been recorded record_chat_message(user_id, f"system_prompt_context_{situation_num}", curr_response_str) return curr_response_str def predict(user_id, strategy_selection, new_input, input_history, system_input_core, convo_num, display): print ("running predict function") print ("strategy_selection: ", strategy_selection, type(strategy_selection)) print ("new_input: ", new_input, type(new_input)) if strategy_selection == []: message_error_message = 'Please select at least one strategy! ' return display, input_history, new_input, '', gr.update(visible=False), message_error_message, strategy_selection elif new_input == '' or len(new_input.split()) < 5: message_error_message = 'Please write a sentence that contains at least five words! ' return display, input_history, new_input, '', gr.update(visible=False), message_error_message, strategy_selection else: message_error_message = "" print ("system_input_core: ", system_input_core) system_input = system_input_core + " Engage in a conversation where you are difficult to convince. Keep the message length below 50 words, or similar to the lengths of my messages." MAX_RETRIES = 5 current_tries = 1 print (input_history, type(input_history)) if input_history == None or type(input_history)==type(gr.State([])): input_history = [] if input_history == []: print ("system_input: ", system_input) prompt = [{"role":"system", "content": system_input}, {"role":"user", "content": new_input}] print (prompt) else: prompt = [{"role":"system", "content": system_input}] + input_history + [{"role":"user", "content":new_input}] while current_tries <= MAX_RETRIES: try: print ('trying...') response = openai.ChatCompletion.create( model=MODEL_NAME, messages = prompt, max_tokens = 512 ) print ('stopped trying') break except Exception as e: print('error: ', str(e)) print('response retrying') current_tries += 1 if current_tries > MAX_RETRIES: break time.sleep(5) curr_response_str = response['choices'][0]['message']['content'].replace('\n', ' ').strip() if input_history == []: input_history = [{"role":"user", "content":new_input}] else: input_history.append({"role":"user", "content":new_input}) input_history.append({"role": "assistant", "content": curr_response_str}) print ("function finished") responses = [(input_history[i]["content"], input_history[i+1]["content"]) for i in range(0, len(input_history)-1, 2)] # MUST return tuples of list record_chat_message(user_id, f"user_strategy_selection_{convo_num}", strategy_selection) record_chat_message(user_id, f"user_message_{convo_num}", new_input) record_chat_message(user_id, f"agent_message_{convo_num}", curr_response_str) # strategy_selection.update(options=[]) turn_count = count_client_message(input_history) if turn_count >= 10: # TODO: update turn count return responses, input_history, '', '', gr.update(visible=True), '', [] #all_dimension_output return responses, input_history, '', '', gr.update(visible=False), '', [] #all_dimension_output def count_client_message(input_history): c = 0 for i in range(len(input_history)): if input_history[i]["role"] == "user": c += 1 else: continue return c def evaluate_dearman(model_name, situation, statement, dimension): systems_all_dimensions = { 'describe':'In the given situation, does the statement "describe" the current interaction between the people in the conversation? To be considered "describe", the client needs to stick to the facts, make no judgmental statements, and be objective. Answer immediately in "Yes" or "No" without other words, then give a brief explanation. If the answer is "No", provide a better statement that describe the current interaction.', 'express': 'In the given situation, is the statement an "expression" of feelings or opinions about the interaction? To be considered an "expression", the client needs to express clearly how they feel or what they believe about the situation. For instance, give a brief rationale for a request or for saying no. Answer immediately in "Yes" or "No" without other words, then give a brief explanation. If the answer is "No", provide a better statement that is an expression of feelings or opinions.', 'assert': 'In the given situation, does the client "assert" wishes in the statement? To be considered "assert", the client needs to ask for what they want or say no clearly. The client cannot be beating around the bush, never really asking or saying no. The client cannot be telling the other person what they "should" do. The statement needs to be clear, concise, and assertive. Answer immediately in "Yes" or "No" without other words, then give a brief explanation. If the answer is "No", provide a better statement that assert the client\'s wishes.', 'reinforce': 'In the given situation, does the client "reinforce" the other person? To be considered "reinforce", the client needs to identify something positive or rewarding that would happen for the other person if they give the response the client wants. Alternatively, the client could offer to do something for the other person, if the other person does this thing for them. At a minimum, the client can express appreciation after the other person does something consistent with their request. Answer immediately in "Yes" or "No" without other words, then give a brief explanation.If the answer is "No", provide a better statement that reinforce the other person that there are something positive or rewarding if they agree.', 'mindful': 'In the given situation, is the client being "mindful" by making the statement? To be considered to stay mindful, the client needs to maintain their position and avoid being distracted onto another topic. The client can keep asking, saying no, or expressing their opinion over and over. Or if the other person attacks, threatens, or tries to change the subject, the client should ignore them and not take the bait. Answer immediately in "Yes" or "No" without other words, then give a brief explanation. If the answer is "No", provide a better statement that is more mindful.', 'confident': 'In the given situation, does the client appear "confident" by making the statement? To be considered confident, the client needs to use a confident tone. The client should not retreat, say they are not sure, or the like. Answer immediately in "Yes" or "No" without other words, then give a brief explanation. If the answer is "No", provide a more confident statement.', 'negotiate': 'In the given situation, is the client "negotiating"? To be considered to be "negotiating", the client needs to be offering and asking for alternative solutions to the problem. They can reduce their request, maintain their ask but offer to do something else or solve the problem another way. Answer immediately in "Yes" or "No" without other words, then give a brief explanation. If the answer is "No", provide a better statement that involves negotiation of the current problem.' } system_input = systems_all_dimensions[dimension] new_input = "Situation: " + situation + "\nStatement: " + statement # consider adding a few examples for few-shot prompt = [{"role":"system", "content": system_input}, {"role":"user", "content": new_input}] MAX_RETRIES = 5 current_tries = 1 while current_tries <= MAX_RETRIES: try: response = openai.ChatCompletion.create( model=MODEL_NAME, messages = prompt ) print (prompt) break except Exception as e: print('error: ', str(e)) print('response retrying') current_tries += 1 if current_tries > MAX_RETRIES: break time.sleep(5) # print (response) curr_response_str = response['choices'][0]['message']['content'].replace('\n', ' ').strip() print (curr_response_str) if curr_response_str[:3] == 'Yes': print (dimension) dimension_explain = curr_response_str[5:] return True, curr_response_str elif curr_response_str[:2] == 'No': print ('not ' + dimension) dimension_explain = curr_response_str[4:] return False, curr_response_str return None, curr_response_str def record_user_login(ts): # print (user) # generate random user id generated_user_id = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 6)) print (generated_user_id) conn = psycopg2.connect(host=DB_ENDPOINT, port=DB_PORT, dbname=DB_NAME, user=DB_USER, password=DB_PASSWORD) log_in_query = f""" INSERT INTO {TABLE_NAME} (user_id, action, content, timestamp) VALUES (%s, %s, %s, %s);""" ts = datetime.datetime.now() data_for_query = (generated_user_id, "log_in", "", ts) with conn.cursor() as cur: cur.execute(log_in_query, data_for_query) conn.commit() conn.close() return generated_user_id def record_chat_message(user, action_type, message): #action_type: chatbot_message or user_message print ("###### recording a message to database: {} ######".format(message)) ts = datetime.datetime.now() conn = psycopg2.connect(host=DB_ENDPOINT, port=DB_PORT, dbname=DB_NAME, user=DB_USER, password=DB_PASSWORD) query = f""" INSERT INTO {TABLE_NAME} (user_id, action, content, timestamp) VALUES (%s, %s, %s, %s);""" ts = datetime.datetime.now() data_for_query = (user, action_type, message, ts) with conn.cursor() as cur: cur.execute(query, data_for_query) conn.commit() conn.close() def confirm_system_prompt(user_id, prompt): if prompt == '': system_prompt_error = 'Please fill in all fields, click on "Process information to generate instruction for the AI model" button, and confirm the instruction, in order to proceed.' return gr.update(visible=False), system_prompt_error else: record_chat_message(user_id, "system_prompt_confirmed", prompt) system_prompt_error = '' return gr.update(visible=True), system_prompt_error def check_consent_and_start(user_id, consent_check): if not consent_check: return ' You must check the box above to continue.', gr.update(visible=True), gr.update(visible=False) else: record_chat_message(user_id, "consent_and_start", "") return '', gr.update(visible=False), gr.update(visible=True) def refresh_state(): return gr.State(), gr.update(visible=False), gr.update(visible=False) def auth(mturk_id): if mturk_id == "": return ' Please enter your mTurk ID you used to complete the Qualification Task. If you think this is a mistake, please reach out to Inna at ilin@cs.washington.edu. ', gr.update(visible=False), gr.update(visible=True), "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" elif mturk_id in pre_load_situations['id'].values: row_index = pre_load_situations[pre_load_situations['id']==mturk_id].index[0] situation1 = pre_load_situations.loc[row_index]['situation1'] goal1 = pre_load_situations.loc[row_index]['goal1'] difficulty1 = pre_load_situations.loc[row_index]['difficulty1'] situation2 = pre_load_situations.loc[row_index]['situation2'] goal2 = pre_load_situations.loc[row_index]['goal2'] difficulty2 = pre_load_situations.loc[row_index]['difficulty2'] conn = psycopg2.connect(host=DB_ENDPOINT, port=DB_PORT, dbname=DB_NAME, user=DB_USER, password=DB_PASSWORD) log_in_query = f""" INSERT INTO {TABLE_NAME} (user_id, action, content, timestamp) VALUES (%s, %s, %s, %s);""" ts = datetime.datetime.now() data_for_query_situation1 = (mturk_id, "situation1", situation1, ts) data_for_query_goal1 = (mturk_id, "goal1", goal1, ts) data_for_query_difficulty1 = (mturk_id, "difficulty1", str(difficulty1), ts) data_for_query_situation2 = (mturk_id, "situation2", situation2, ts) data_for_query_goal2 = (mturk_id, "goal2", goal2, ts) data_for_query_difficulty2 = (mturk_id, "difficulty2", str(difficulty2), ts) with conn.cursor() as cur: cur.execute(log_in_query, data_for_query_situation1) cur.execute(log_in_query, data_for_query_goal1) cur.execute(log_in_query, data_for_query_difficulty1) cur.execute(log_in_query, data_for_query_situation2) cur.execute(log_in_query, data_for_query_goal2) cur.execute(log_in_query, data_for_query_difficulty2) conn.commit() conn.close() difficulty1_text = "You rated the difficulty of the situation as: " + str(difficulty1) + " out of 9." difficulty2_text = "You rated the difficulty of the situation as: " + str(difficulty2) + " out of 9." print (situation1) system_prompt1_convo1 = generate_system_input_situation_only(mturk_id, situation1, "situation1") system_prompt1_convo3 = system_prompt1_convo1 system_prompt2_convo4 = generate_system_input_situation_only(mturk_id, situation2, "situation2") situation1_formatted = format_markdown('situation1', situation1) goal1_formatted = format_markdown('goal1', goal1) situation2_formatted = format_markdown('situation2', situation2) goal2_formatted = format_markdown('goal2', goal2) difficulty1_formatted = format_markdown('difficulty1', difficulty1_text) difficulty2_formatted = format_markdown('difficulty2', difficulty2_text) return "", gr.update(visible=True), gr.update(visible=False), situation1_formatted, goal1_formatted, difficulty1_formatted, situation2_formatted, goal2_formatted, difficulty2_formatted, situation1_formatted, goal1_formatted, difficulty1_formatted, situation1_formatted, goal1_formatted, difficulty1_formatted, situation1_formatted, goal1_formatted, difficulty1_formatted, situation1_formatted, goal1_formatted, difficulty1_formatted,situation2_formatted, goal2_formatted, difficulty2_formatted, situation2_formatted, goal2_formatted, difficulty2_formatted, system_prompt1_convo1, system_prompt1_convo3, system_prompt2_convo4 # last eight: situation1_convo1, goal1_convo1, situation1_convo2, goal1_convo2, situation1_convo3, goal1_convo3, situation2_convo4, goal2_convo4 # last two: system_prompt1, system_prompt2 else: return ' Cannot find this mTurk ID in qualified pool. If you think this is a mistake, please reach out to Inna at ilin@cs.washington.edu. ', gr.update(visible=False), gr.update(visible=True), "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "","", "", "", "", "", "", "", "", "", "" def format_markdown(text_type, text): if text_type == 'situation1': return ' Situation 1: ' + text + '' elif text_type == 'goal1': return ' Goal: ' + text + '' elif text_type == 'difficulty1': return ' Difficulty: ' + text + '' elif text_type == 'situation2': return ' Situation 2: ' + text + '' elif text_type == 'goal2': return ' Goal: ' + text + '' elif text_type == 'difficulty2': return ' Difficulty: ' + text + '' def proceed_to_next_chat(): return gr.update(visible=False), gr.update(visible=True) def proceed_to_next_chat_completion(code_check): if code_check: return gr.update(visible=False), gr.update(visible=True), '' else: return gr.update(visible=True), gr.update(visible=False), 'Please confirm you have recorded your completion code and check the above to continue.' def proceed_to_next_chat_final(mturk_id): generated_completion_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 6)) conn = psycopg2.connect(host=DB_ENDPOINT, port=DB_PORT, dbname=DB_NAME, user=DB_USER, password=DB_PASSWORD) log_in_query = f""" INSERT INTO {TABLE_NAME} (user_id, action, content, timestamp) VALUES (%s, %s, %s, %s);""" ts = datetime.datetime.now() data_for_query = (mturk_id, "completion_code", generated_completion_code, ts) with conn.cursor() as cur: cur.execute(log_in_query, data_for_query) conn.commit() conn.close() return gr.update(visible=False), gr.update(visible=True), generated_completion_code def record_survey_answers(survey_name, user_id, confident_ans, worried_ans, hopeful_ans, motivated_ans, fear_ans, anger_ans, disgust_ans, sad_ans): print ("Showing answer data types: ", confident_ans, type(confident_ans), worried_ans, type(worried_ans)) if confident_ans == '' or worried_ans == '' or hopeful_ans == '' or motivated_ans == '' or fear_ans == '' or anger_ans == '' or disgust_ans == '' or sad_ans == '': return gr.update(visible=True), gr.update(visible=False), 'Please fill in all fields.' record_chat_message(user_id, f"{survey_name}_confident", confident_ans) record_chat_message(user_id, f"{survey_name}_worried", worried_ans) record_chat_message(user_id, f"{survey_name}_hopeful", hopeful_ans) record_chat_message(user_id, f"{survey_name}_motivated", motivated_ans) record_chat_message(user_id, f"{survey_name}_fear", fear_ans) record_chat_message(user_id, f"{survey_name}_anger", anger_ans) record_chat_message(user_id, f"{survey_name}_disgust", disgust_ans) record_chat_message(user_id, f"{survey_name}_sad", sad_ans) return gr.update(visible=False), gr.update(visible=True), '' def record_survey_answers_outtake(user_id, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, additional): if q1 == '' or q2 == '' or q3 == '' or q4 == '' or q5 == '' or q6 == '' or q7 == '' or q8 == '' or q9 == '' or q10 == '': return gr.update(visible=True), gr.update(visible=False), 'Please fill in all fields.' record_chat_message(user_id, f"outtake_q1", q1) record_chat_message(user_id, f"outtake_q2", q2) record_chat_message(user_id, f"outtake_q3", q3) record_chat_message(user_id, f"outtake_q4", q4) record_chat_message(user_id, f"outtake_q5", q5) record_chat_message(user_id, f"outtake_q6", q6) record_chat_message(user_id, f"outtake_q7", q7) record_chat_message(user_id, f"outtake_q8", q8) record_chat_message(user_id, f"outtake_q9", q9) record_chat_message(user_id, f"outtake_q10", q10) record_chat_message(user_id, f"outtake_additional_feedback", additional) return gr.update(visible=False), gr.update(visible=True), '' def generate_feedback_and_record(user_id, current_situation, category, u, prompt_strategy, prompt_selection, strategy_list): if u == '' or len(u.split()) < 5: return 'Please write a sentence that contains at least five words! ', 'No' output = generate_feedback_with_mc(current_situation, category, u, prompt_strategy, prompt_selection, strategy_list) ## if mc then use generate_feedback_with_mc strategy = strategy_list[0] record_chat_message(user_id, f"user_message_pre_feedback", u) record_chat_message(user_id, f"feedback_{strategy}", output) return output, 'Yes' def generate_skill_suggestion_and_record(user_id, situation, input_history, demonstration_mode): # inputs=[situation1_convo2, chat_history, demonstration_model_suggest_skill], outputs=[skill_suggestion0, skill_suggestion1, skill_suggestion_reason] skill_suggestion0, skill_suggestion_reason = generate_skill_suggestion(situation, input_history, demonstration_mode) record_chat_message(user_id, f"skill_suggestion", skill_suggestion0) # record_chat_message(user_id, f"skill_suggestion1", skill_suggestion1) record_chat_message(user_id, f"skill_suggestion_reason", skill_suggestion_reason) return skill_suggestion0, skill_suggestion_reason def predict_and_check_edit(user_id, strategy_selection, text, edited_text, input_history, system_input_core, convo_num, skill_suggestion0, skill_suggestion1, skill_suggestion_reason, feedback_text, feedback_check, display): if feedback_check == 'No': message_error_message = 'Please get feedback and improve your response before sending the response. ' return display, input_history, text, gr.update(visible=False), gr.update(visible=False), message_error_message, skill_suggestion0, skill_suggestion1, skill_suggestion_reason, feedback_text, edited_text, strategy_selection, feedback_check if text == edited_text: print (feedback_text.split()[0]) if feedback_text.split()[0][3:].strip() != 'Strong': message_error_message = 'Please make edits based on the feedback before sending the message. ' return display, input_history, text, gr.update(visible=False), gr.update(visible=False), message_error_message, skill_suggestion0, skill_suggestion1, skill_suggestion_reason, feedback_text, edited_text, strategy_selection, feedback_check responses, input_history, text, output, refresh, message_error_message, new_strategy_list = predict(user_id, strategy_selection, edited_text, input_history, system_input_core, convo_num, display) #outputs=[display, chat_history, text, output, refresh, message_error_message] feedback_output # [mturk_id, strategy_selection, edited_text, chat_history, system_prompt1_convo2, convo_num2, skill_suggestion0, skill_suggestion1, skill_suggestion_reason, feedback_text] return responses, input_history, text, output, refresh, message_error_message, '', '', '', '','',new_strategy_list, 'No' # last four: skill_suggestion0, skill_suggestion1, skill_suggestion_reason, feedback_text, edited_text with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"),css=css) as demo: # with gr.Blocks() as demo: gr.Markdown("""# Interpersonal Effectiveness Learning & Practice""") with gr.Column(visible=True) as auth_block: mturk_id = gr.Textbox(label="Please enter your mTurk ID") auth_button = gr.Button("Confirm and start the study") passcode_warning = gr.Markdown(elem_id='emp') with gr.Column(visible=False) as intro: gr.Markdown(""" ## Study Goals We are a group of researchers building an AI-based tool to provide training to participants to improve their communication skills in difficult situations. In this study, you will chat through text with a simulated conversation partner powered by AI. The tool will provide concrete suggestions on good communication strategies and personalized feedback on how well you exercise these strategies. ## You will engage in FOUR conversations in total. For each of the situation, you will engage in an one-on-one conversation where you try to communicate to resolve or improve the situation. The AI model is instructed to play the role of the person you are talking to. For each conversation, you are expected to respond ten times. For each conversation turn, you should first identify the best strategy to use in this turn before writing the response using the select strategy. Conversation 1 - pre-training evaluation This will be about a situation you wrote in the qualification task. In this conversation, you will chat without any feedback or reference materials.
Conversation 2 - training conversation This conversation will be about the same situation as Conversation 1. In this conversation, you will receive suggestions to use a conversation strategy and feedback on how well you exercise the strategy, and improve the response based on the feedback. You will also have access to a reference document about the strategies.
Conversation 3 - post-training evaluation This will be about the first situation again. We want to see if you can improve your communication in the first situation after the training. In this conversation, you will chat without any feedback or reference materials.
Conversation 4 - post-training evaluation This will be about the second situation you wrote in the qualification task. In this conversation, you will chat without any feedback or reference materials.
## You will receive a BONUS of $10 if... Over the course of the conversations 2-4, you are at the top 30\% of the participants in terms of how well you exhibit the skills taught in conversation 2. We will evaluate and assign the bonus after the study is completed (mid-February). The bonus will be $10 in addition to the base payment. The best way to get the bonus is to try your best to learn the strategies in the training conversation and exercise them in the post-training conversations. ## IMPORTANT: How do I confirm the completion of this task? You will be asked to provide a completion code on mTurk interface. You will receive the completion code after you finish the study. Please record the completion code to prove completion of the task. Please note that you will only get the payment if you complete the entire study, i.e. ten conversation responses for each of the four conversations. """) gr.Markdown(""" ## Content Warning This study may contain situations and thoughts that might be disturbing. If you have any questions or concerns, please send us an email (ilin@cs.washington.edu). Should you have a strong negative reaction to some of the content, you can reach a crisis counselor at Crisis Text Line or by texting HOME to 741741. If you have questions about your rights as a research participant, or wish to obtain information, ask questions or discuss any concerns about this study with someone other than the researchers, please contact the University of Washington Human Subjects Division at 206-543-0098. ## Consent to the task """) consent_check = gr.Checkbox(label = "By ticking this box, you are agreeing to be part of this user study. Be sure that questions you have about the study have been answered and that you understand what you are being asked to do. You may contact us if you think of a question later. You are free to release/quit the study at any time. To be compensated for the study, you agree to finish the task in approximately 1 hour. The data collected in the study will be released to the public for research purposes and you should not include any identifiable personal information. To save a copy of the consent form and instructions, you can save/print this webpage.") consent_error_message = gr.Markdown(elem_id='emp') consent_button = gr.Button('Agree and Start the Study') with gr.Column(visible=False) as intake_1: consent_button.click(fn=check_consent_and_start, inputs=[mturk_id, consent_check], outputs=[consent_error_message, intro, intake_1]) gr.Markdown("""# Intake Survey - Situation 1""") gr.Markdown("""In this section, you will answer a few questions about the first situation you wrote in the qualification task. Please answer the questions as honestly as possible. If your answers seem inconsistent, we may not be able to use your data or pay you for the study. """) survey_name1 = gr.Textbox('intake_situation1', visible=False) # write a section of survey questions situation1_intake = gr.Markdown(elem_id='emp') goal1_intake = gr.Markdown(elem_id='emp') difficulty1_intake = gr.Markdown(elem_id='emp') confident_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **confident** about my ability to achieve my goal through having this conversation", interactive=True) worried_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **worried** about achieving my goal through having this conversation", interactive=True) hopeful_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **hopeful** about achieving my goal through having this conversation", interactive=True) motivated_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **motivated** about having this challenging conversation", interactive=True) # Emotions (negative emotions from Plutchik's wheel of emotions) fear_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **fearful** about this situation", interactive=True) anger_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **angry** about this situation", interactive=True) disgust_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **disgusted** about this situation", interactive=True) sad_intake1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **sad** about this situation", interactive=True) intake1_error = gr.Markdown(elem_id='emp') continue_intake1 = gr.Button("Continue to the next step") with gr.Column(visible=False) as intake_2: survey_name2 = gr.Textbox('intake_situation2', visible=False) continue_intake1.click(fn=record_survey_answers, inputs=[survey_name1, mturk_id, confident_intake1, worried_intake1, hopeful_intake1, motivated_intake1, fear_intake1, anger_intake1, disgust_intake1, sad_intake1], outputs=[intake_1, intake_2, intake1_error]) gr.Markdown("""# Intake Survey - Situation 2""") gr.Markdown("""In this section, you will answer a few questions about the second situation you wrote in the qualification task. Please answer the questions as honestly as possible. If your answers seem inconsistent, we may not be able to use your data or pay you for the study. """) # write a section of survey questions situation2_intake = gr.Markdown(elem_id='emp') goal2_intake = gr.Markdown(elem_id='emp') difficulty2_intake = gr.Markdown(elem_id='emp') confident_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **confident** about my ability to achieve my goal through having this conversation", interactive=True) worried_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **worried** about achieving my goal through having this conversation", interactive=True) hopeful_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **hopeful** about achieving my goal through having this conversation", interactive=True) motivated_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **motivated** about having this challenging conversation", interactive=True) # Emotions (negative emotions from Plutchik's wheel of emotions) fear_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **fearful** about this situation", interactive=True) anger_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **angry** about this situation", interactive=True) disgust_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **disgusted** about this situation", interactive=True) sad_intake2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **sad** about this situation", interactive=True) intake2_error = gr.Markdown(elem_id='emp') continue_intake2 = gr.Button("Continue to the next step") # with gr.Column(visible=False) as dearman_info: # continue_intake2.click(fn=record_survey_answers, inputs=[survey_name2, mturk_id, confident_intake2, worried_intake2, hopeful_intake2, motivated_intake2, fear_intake2, anger_intake2, disgust_intake2, sad_intake2], outputs=[intake_2, dearman_info, intake2_error]) # gr.Markdown("""In this study, you will focus on learning the DEAR MAN skills.""") # gr.Markdown(""" # ## DEAR MAN Skills # DEAR MAN skills helps obtain objectives effectively in a difficult situation. The DBT manual defines the skills as shown below. (Source: DBT Skills Training Manual, 2nd Edition. Marsha M. Linehan.) # Describe Describe the current situation (if necessary). Stick to the facts. Tell the person exactly what you are reacting to.
# e.g. You told me you would be home by dinner but you didn't get here until 11.
# Express Express your feelings and opinions about the situation. Don't assume that the other person knows how you feel.
# e.g. When you come home so late, I start worrying about you.
# Assert Assert yourself by asking for what you want or saying no clearly. Do not assume that others will figure out what you want. Remember that others cannot read your mind.
# e.g. I would really like it if you would call me when you are going to be late.
# Reinforce Reinforce the person ahead of time by explaining positive effects of getting what you want or need. If necessary, also clarify the negative consequences of not getting what you want or need.
# e.g. I would be so relieved, and a lot easier to live with, if you do that.
# Mindful Keep your focus on your goals. Maintain your position. Don't be distracted. Don't get off the topic.
# e.g. I would still like a call
# Appear Confident Appear effective and competent. Use a confident voice tone. Avoid saying things like "I'm not sure."
# Negotiate Be willing to give to get. Offer and ask for other solutions to the problem. Reduce your request. Say no, but offer to do something else or to solve the problem another way. Focus on what will work.
# e.g. How about if you text me when you think you might be late?
# In each of the conversations, you will learn to use these skills to communicate in the challenging situations you brought up in the qualification task. \n # Among these skills, Describe, Assert, Reinforce, and Negotiate are conversation strategies you can use in each response. You should always try to be mindful and confident in each response. # """) # continue_dearman = gr.Button("Continue to the next step") with gr.Column(visible=False) as conversation1: # continue_dearman.click(fn=proceed_to_next_chat, inputs=[], outputs=[dearman_info, conversation1]) continue_intake2.click(fn=record_survey_answers, inputs=[survey_name2, mturk_id, confident_intake2, worried_intake2, hopeful_intake2, motivated_intake2, fear_intake2, anger_intake2, disgust_intake2, sad_intake2], outputs=[intake_2, conversation1, intake2_error]) gr.Markdown("""# Conversation 1""") gr.Markdown("""In this section, you will chat with a simulated conversation partner powered by AI. The AI model is instructed to play the role of the person you are talking to. You will chat about the first situation you wrote in the qualification task. You will chat without any feedback or reference materials. You are expected to respond ten times. For each conversation turn, you should do these two steps: \n Step 1. Identify the best strategy or strategies to use in this turn. You can choose more than one strategies.\n Step 2. Write a response that exercise the strategy or strategies you select.\n Step 3. Click the "Send" button to send the response to the chatbot. """) with gr.Accordion("Open to see the list of conversation strategies you can choose from", open=True): gr.Markdown(""" For each response, you can choose one or more strategies from the five below: Describe, Express, Assert, Reinforce, and Negotiate.
Describe Describe the current situation.
Express Express your feelings and opinions about the situation.
Assert Assert yourself by asking for what you want or saying no clearly.
Reinforce Reinforce the person ahead of time by explaining positive effects of getting what you want or need. If necessary, also clarify the negative consequences of not getting what you want or need.
Negotiate Be willing to give to get. Offer and ask for other solutions to the problem.

For all responses, you should always try to stay mindful and confident.
Mindful Keep your focus on your goals. Maintain your position. Don't be distracted. Don't get off the topic.
Appear Confident Appear effective and competent. Use a confident voice tone. Avoid saying things like "I'm not sure."
""") convo_num1 = gr.Textbox("convo_1", visible=False) # chat1 = gr.ChatInterface() situation1_convo1 = gr.Markdown(elem_id='emp') goal1_convo1 = gr.Markdown(elem_id='emp') system_prompt1_convo1 = gr.Markdown(visible=False) difficulty1_convo1 = gr.Markdown(visible=False) chat1_history = gr.State([]) with gr.Row(): display_chat1 = gr.Chatbot(elem_id="chuanhu_chatbot") with gr.Row(): strategy_selection1 = gr.Dropdown(['Describe', 'Express', 'Assert','Reinforce', 'Negotiate'], label='Select one or more strategies', scale=1, interactive=True,multiselect=True, max_choices=7) text_chat1 = gr.Textbox(label='Send response exercising the strategy', scale=2, interactive=True) button_submit_chat1 = gr.Button("Send", scale=0) with gr.Row(): message_error_message1 = gr.Markdown(elem_id='emp') with gr.Row(visible=False) as proceed_chat1: output1= gr.Markdown('You have done 10 turns of conversation! Please click the button below to continue. ') continue_button1 = gr.Button("Continue to the next step") button_submit_chat1.click(fn=predict, inputs=[mturk_id, strategy_selection1, text_chat1, chat1_history, system_prompt1_convo1, convo_num1, display_chat1], outputs=[display_chat1, chat1_history, text_chat1, output1, proceed_chat1, message_error_message1, strategy_selection1]) # TODO: after hitting 'Send Message', strategy selection and Feedback markdown should be refreshed / reset #user_id, strategy_selection, new_input, input_history, system_input_core, system_prompt, convo_num with gr.Accordion("I am asked to respond 10 times for each situation. What if the chatbot already agrees with me before 10 responses?", open=False): gr.Markdown("If the chatbot concurs with you within the first 10 responses, you have the option to terminate the conversation before 10 responses by clicking the button. Please note, to ensure the quality of the dataset, we will conduct a manual review to assess the reasonableness of the agreement, and we will not compensate for conversations where the chatbot did not genuinely reach an agreement. If you engage in at least 10 responses, you are not required to acquire an agreement from the chatbot and you should see a button that clearly says 'You have finished this situation, submit and continue to the next step.'") agreement_proceed_button1 = gr.Button("I confirm I have read and understood the statement above and the chatbot indeed agrees with me before I respond 10 times. End the conversation now and proceed to the next step.") with gr.Column(visible=False) as study: agreement_proceed_button1.click(fn=proceed_to_next_chat, inputs=[], outputs=[conversation1, study]) continue_button1.click(fn=proceed_to_next_chat, inputs=[], outputs=[conversation1, study]) gr.Markdown('# Conversation 2 - Training Conversation') gr.Markdown("""In this section, you will chat with a simulated conversation partner powered by AI. The AI model is instructed to play the role of the person you are talking to. You will chat about the first situation you wrote in the qualification task. In this conversation, you will receive suggestions to use a DEAR MAN skill and get feedback on how well you exercise the skill. You will also have access to a reference document about the strategies. You are expected to respond ten times. For each conversation turn, you should do the following steps: \n Step 1. Click on the "Suggest to me a skill to use" button to get a skill suggestion. \n Step 2. Select the most effective strategy from the dropdown menu. You can either follow the suggestion or use your own judgment. Note that only one strategy can be selected at a time to ensure focused feedback. You can repeat Step 2 - 4 to get feedback about a different strategy on the same response. \n Step 3. Write a response exercising the strategy. \n Step 4. Click on the "Get feedback on your response" button to get feedback on your response. \n For each response, you will get feedback on the following. \n i. How well you exercise the strategy you select. Our model will provide a rating of Strong, Weak, or None based on the response you write. We request that you make edits to your response before sending it to the chatbot if the feedback says your response is Weak or None. \n ii. How well the response shows mindfulness and confidence. If you get feedback on mindfulness and confidence, please make edits to the response before sending it to the chatbot. \n Step 5. Make edits to your response based on the feedback, if the feedback says your response is weak or none on the skill you select. \n Step 6. Click on the "Send message" button to send your response to the chatbot. \n Step 7. Repeat the above steps until you have done 10 turns of the conversation.""") with gr.Accordion("Open to see the list of DEAR MAN skills", open=True): gr.Markdown("""## DEAR MAN Skills DEAR MAN skills helps obtain objectives effectively in a difficult situation. There are seven skills which start with the letters D, E, A, R, M, A, N. Below, we show the definitions of DEAR MAN skills and give an example for each skill. All the examples are regarding the situation where someone wants to talk to their husband about coming home late without warning them. In the exercise, you should try to use these skills to communicate in the challenging situations you brought up. You can always refer to this list of definitions and examples during the chat. \n Among these skills, Describe, Assert, Reinforce, and Negotiate are conversation strategies you can use in each response. You should always try to be Mindful and Appear Confident in each response. \n Describe Describe the current situation (if necessary). Stick to the facts. Tell the person exactly what you are reacting to.
e.g. You told me you would be home by dinner but you didn't get here until 11.
Express Express your feelings and opinions about the situation. Don't assume that the other person knows how you feel.
e.g. When you come home so late, I start worrying about you.
Assert Assert yourself by asking for what you want or saying no clearly. Do not assume that others will figure out what you want. Remember that others cannot read your mind.
e.g. I would really like it if you would call me when you are going to be late.
Reinforce Reinforce the person ahead of time by explaining positive effects of getting what you want or need. If necessary, also clarify the negative consequences of not getting what you want or need.
e.g. I would be so relieved, and a lot easier to live with, if you do that.
Mindful Keep your focus on your goals. Maintain your position. Don't be distracted. Don't get off the topic.
e.g. I would still like a call
Appear Confident Appear effective and competent. Use a confident voice tone. Avoid saying things like "I'm not sure."
Negotiate Be willing to give to get. Offer and ask for other solutions to the problem. Reduce your request. Say no, but offer to do something else or to solve the problem another way. Focus on what will work.
e.g. How about if you text me when you think you might be late?
(Source: DBT Skills Training Manual, 2nd Edition. Marsha M. Linehan.) """) convo_num2 = gr.Textbox("convo_2", visible=False) situation1_convo2 = gr.Markdown(elem_id='emp') goal1_convo2 = gr.Markdown(elem_id='emp') difficulty1_convo2 = gr.Markdown(visible=False) system_prompt1_convo2 = gr.Markdown(visible=False) user_situation_category = gr.Dropdown(choices=['Family', 'Social', 'Work'], label="Step 1a: Select a situation category", value='Social', visible=False) demonstration_model_suggest_skill = gr.Textbox(value="zero_shot", visible=False) chat_history = gr.State([]) # with gr.Row(): display = gr.Chatbot(elem_id="chuanhu_chatbot") gr.Markdown(' Step 1: Get a skill suggestion. ') skill_suggest_button = gr.Button("Click here to get a skill suggestion.") skill_suggestion0 = gr.Markdown(elem_id='emp') # clear skill_suggestion1 = gr.Markdown(elem_id='emp', visible=False) # clear skill_suggestion_reason = gr.Markdown(elem_id='emp') # clear strategy_selection = gr.Dropdown(['Describe', 'Express', 'Assert','Reinforce', 'Negotiate'], label='Step 2: Select a strategy you want to use and get feedback on. You can choose the suggested strategy or use your own judgement to select a strategy.', scale=2, interactive=True,multiselect=True, max_choices=1) # strategy_selection = gr.Dropdown(['Describe', 'Express', 'Assert','Reinforce', 'Negotiate'], scale=2, interactive=True,multiselect=True, max_choices=7) # skill_suggest_button = gr.Button("Suggest to me a skill to use") skill_suggest_button.click(fn=generate_skill_suggestion_and_record, inputs=[mturk_id, situation1_convo2, chat_history, demonstration_model_suggest_skill], outputs=[skill_suggestion0,skill_suggestion_reason]) # situation, input_history, demonstration_mode text = gr.Textbox(label='Step 3: Write a response exercising the selected strategy.') gr.Markdown(' Step 4: Get feedback on how well you exercise the DEAR MAN strategy. This step can take up to 1 minute (on average 30 seconds, but in rare case 1-2 mins), please do not refresh the page since you may lose your progress. While you wait, review the DEAR MAN skills above to familiarize yourself with the skills. If this step takes more than 3 mins, please reach out to ilin@cs.washington.edu') feedback_button = gr.Button("Click here to get feedback on your response") feedback_text = gr.Markdown(elem_id='emp') #clear prompt_strategy = gr.Textbox(value="reason", visible=False) prompt_selection = gr.Textbox(value="all_utterances_knn",visible=False) feedback_check = gr.Textbox(value='No', visible=False) # (all_strategy, current_situation, category, u, prompt_strategy, prompt_selection, strategy_list) # TODO: add mindful and confident message_error_message = gr.Markdown(elem_id='emp') feedback_button.click(fn=generate_feedback_and_record, inputs=[mturk_id, situation1_convo2, user_situation_category, text, prompt_strategy, prompt_selection, strategy_selection], outputs=[feedback_text, feedback_check]) # gr.Markdown(' Step 5: Make edits to your response based on the feedback. This step if optional if the feedback says your response is a strong one. ') edited_text = gr.Textbox(label='Step 5: Make edits to your response based on the feedback. This step if optional if the feedback says your response is a strong one, you can copy your previous strong response if you want to.') # clear gr.Markdown(' Step 6: Send your edited response to the chatbot. ') send_message_button = gr.Button("Click here to send message.") with gr.Column(visible=False) as refresh: output = gr.Markdown('

You have done 10 turns of conversation! Please click the button below to continue to the next step. ') refresh_button = gr.Button("Continue to the next step") # send_message_button.click(fn=predict, inputs=[user_id_text, strategy_selection, text, chat_history, system_prompt1_convo2, situation1_convo2], outputs=[display, chat_history, text, output, refresh, message_error_message]) # TODO: after hitting 'Send Message', strategy selection and Feedback markdown should be refreshed / reset send_message_button.click(fn=predict_and_check_edit, inputs=[mturk_id, strategy_selection, text, edited_text, chat_history, system_prompt1_convo2, convo_num2, skill_suggestion0, skill_suggestion1, skill_suggestion_reason, feedback_text, feedback_check, display], outputs=[display, chat_history, text, output, refresh, message_error_message, skill_suggestion0, skill_suggestion1, skill_suggestion_reason, feedback_text, edited_text, strategy_selection, feedback_check]) with gr.Accordion("I am asked to respond 10 times for each situation. What if the chatbot already agrees with me before 10 responses?", open=False): gr.Markdown("If the chatbot concurs with you within the first 10 responses, you have the option to terminate the conversation before 10 responses by clicking the button. Please note, to ensure the quality of the dataset, we will conduct a manual review to assess the reasonableness of the agreement, and we will not compensate for conversations where the chatbot did not genuinely reach an agreement. If you engage in at least 10 responses, you are not required to acquire an agreement from the chatbot and you should see a button that clearly says 'You have finished this situation, submit and start a new situation' .") agreement_refresh_button = gr.Button("I confirm I have read and understood the statement above and the chatbot indeed agrees with me before I respond 10 times. End the conversation now and proceed to the next step.") with gr.Column(visible=False) as post_training_survey1: agreement_refresh_button.click(fn=proceed_to_next_chat, inputs=[], outputs=[study, post_training_survey1]) refresh_button.click(fn=proceed_to_next_chat, inputs=[], outputs=[study, post_training_survey1]) survey_post_name1 = gr.Textbox('post_situation1', visible=False) # continue_intake1.click(fn=record_survey_answers, inputs=[survey_name1, mturk_id, confident_intake1, worried_intake1, hopeful_intake1, motivated_intake1, fear_intake1, anger_intake1, disgust_intake1, sad_intake1], outputs=[intake_1, intake_2, intake1_error]) gr.Markdown("""# Post Training Survey - Situation 1""") gr.Markdown("""After the training, rethink how do you feel about having a conversation about the same situation. Please answer the following questions. """) # write a section of survey questions situation1_post = gr.Markdown(elem_id='emp') goal1_post = gr.Markdown(elem_id='emp') difficulty1_post = gr.Markdown(visible=False) confident_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **confident** about my ability to achieve my goal through having this conversation", interactive=True) worried_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **worried** about achieving my goal through having this conversation", interactive=True) hopeful_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **hopeful** about achieving my goal through having this conversation", interactive=True) motivated_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **motivated** about having this challenging conversation", interactive=True) # Emotions (negative emotions from Plutchik's wheel of emotions) fear_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **fearful** about this situation", interactive=True) anger_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **angry** about this situation", interactive=True) disgust_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **disgusted** about this situation", interactive=True) sad_post1 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **sad** about this situation", interactive=True) survey_post1_error = gr.Markdown(elem_id='emp') continue_survey_post1 = gr.Button("Continue to the next step") with gr.Column(visible=False) as conversation3: continue_survey_post1.click(fn=record_survey_answers, inputs=[survey_post_name1, mturk_id, confident_post1, worried_post1, hopeful_post1, motivated_post1, fear_post1, anger_post1, disgust_post1, sad_post1], outputs=[post_training_survey1, conversation3, survey_post1_error]) gr.Markdown("""# Conversation 3""") gr.Markdown("""In this section, you will chat with a simulated conversation partner powered by AI. The AI model is instructed to play the role of the person you are talking to. You will chat about the first situation you wrote in the qualification task. You will chat without any feedback or reference materials. You are expected to respond ten times. For each conversation turn, you should do these two steps: \n Step 1. Identify the best strategy or strategies to use in this turn. You can choose more than one strategies.\n Step 2. Write a response that exercise the strategy or strategies you select.\n Step 3. Click the "Send" button to send the response to the chatbot. """) gr.Markdown(""" The quality of this conversation will be used to determine the bonus. If you are able to use the skills you learned in the previous training conversation well (top 30\% of all the participants), you will be able to get the bonus. """) with gr.Accordion("Open to see the list of DEAR MAN skills", open=True): gr.Markdown("""## DEAR MAN Skills DEAR MAN skills helps obtain objectives effectively in a difficult situation. There are seven skills which start with the letters D, E, A, R, M, A, N. Below, we show the definitions of DEAR MAN skills and give an example for each skill. All the examples are regarding the situation where someone wants to talk to their husband about coming home late without warning them. In the exercise, you should try to use these skills to communicate in the challenging situations you brought up. You can always refer to this list of definitions and examples during the chat. \n Describe Describe the current situation (if necessary). Stick to the facts. Tell the person exactly what you are reacting to.
e.g. You told me you would be home by dinner but you didn't get here until 11.
Express Express your feelings and opinions about the situation. Don't assume that the other person knows how you feel.
e.g. When you come home so late, I start worrying about you.
Assert Assert yourself by asking for what you want or saying no clearly. Do not assume that others will figure out what you want. Remember that others cannot read your mind.
e.g. I would really like it if you would call me when you are going to be late.
Reinforce Reinforce the person ahead of time by explaining positive effects of getting what you want or need. If necessary, also clarify the negative consequences of not getting what you want or need.
e.g. I would be so relieved, and a lot easier to live with, if you do that.
Mindful Keep your focus on your goals. Maintain your position. Don't be distracted. Don't get off the topic.
e.g. I would still like a call
Appear Confident Appear effective and competent. Use a confident voice tone. Avoid saying things like "I'm not sure."
Negotiate Be willing to give to get. Offer and ask for other solutions to the problem. Reduce your request. Say no, but offer to do something else or to solve the problem another way. Focus on what will work.
e.g. How about if you text me when you think you might be late?
(Source: DBT Skills Training Manual, 2nd Edition. Marsha M. Linehan.) """) convo_num3 = gr.Textbox("convo_3", visible=False) situation1_convo3 = gr.Markdown(elem_id='emp') goal1_convo3 = gr.Markdown(elem_id='emp') difficulty1_convo3 = gr.Markdown(visible=False) system_prompt1_convo3 = gr.Markdown(visible=False) chat3_history = gr.State([]) with gr.Row(): display_chat3 = gr.Chatbot(elem_id="chuanhu_chatbot") with gr.Row(): strategy_selection3 = gr.Dropdown(['Describe', 'Express', 'Assert','Reinforce', 'Negotiate'], label='Select the most effective strategy', scale=1, interactive=True,multiselect=True, max_choices=7) text_chat3 = gr.Textbox(label='Send response exercising the strategy', scale=2) button_submit_chat3 = gr.Button("Send", scale=0) with gr.Row(): message_error_message3 = gr.Markdown(elem_id='emp') with gr.Row(visible=False) as proceed_chat3: output3= gr.Markdown('

You have done 10 turns of conversation! Please click the button below to continue. ') continue_button3 = gr.Button("Continue to the next step") button_submit_chat3.click(fn=predict, inputs=[mturk_id, strategy_selection3, text_chat3, chat3_history, system_prompt1_convo3, convo_num3, display_chat3], outputs=[display_chat3, chat3_history, text_chat3, output3, proceed_chat3, message_error_message3,strategy_selection3]) # TODO: after hitting 'Send Message', strategy selection and Feedback markdown should be refreshed / reset with gr.Accordion("I am asked to respond 10 times for each situation. What if the chatbot already agrees with me before 10 responses?", open=False): gr.Markdown("If the chatbot concurs with you within the first 10 responses, you have the option to terminate the conversation before 10 responses by clicking the button. Please note, to ensure the quality of the dataset, we will conduct a manual review to assess the reasonableness of the agreement, and we will not compensate for conversations where the chatbot did not genuinely reach an agreement. If you engage in at least 10 responses, you are not required to acquire an agreement from the chatbot and you should see a button that clearly says 'You have finished this situation, submit and continue to the next step.'") agreement_proceed_button3 = gr.Button("I confirm I have read and understood the statement above and the chatbot indeed agrees with me before I respond 10 times. End the conversation now and proceed to the next step.") with gr.Column(visible=False) as post_training_survey2: agreement_proceed_button3.click(fn=proceed_to_next_chat, inputs=[], outputs=[conversation3, post_training_survey2]) continue_button3.click(fn=proceed_to_next_chat, inputs=[], outputs=[conversation3, post_training_survey2]) survey_post_name2 = gr.Textbox('post_situation2', visible=False) # continue_intake1.click(fn=record_survey_answers, inputs=[survey_name1, mturk_id, confident_intake1, worried_intake1, hopeful_intake1, motivated_intake1, fear_intake1, anger_intake1, disgust_intake1, sad_intake1], outputs=[intake_1, intake_2, intake1_error]) gr.Markdown("""# Post Training Survey - Situation 2""") # write a section of survey questions gr.Markdown("""After the training, rethink how do you feel about having a conversation about a new situation. Please answer the following questions. """) situation2_post = gr.Markdown(elem_id='emp') goal2_post = gr.Markdown(elem_id='emp') difficulty2_post = gr.Markdown(visible=False) confident_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **confident** about my ability to achieve my goal through having this conversation", interactive=True) worried_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **worried** about achieving my goal through having this conversation", interactive=True) hopeful_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **hopeful** about achieving my goal through having this conversation", interactive=True) motivated_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **motivated** about having this challenging conversation", interactive=True) # Emotions (negative emotions from Plutchik's wheel of emotions) fear_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **fearful** about this situation", interactive=True) anger_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **angry** about this situation", interactive=True) disgust_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **disgusted** about this situation", interactive=True) sad_post2 = gr.Dropdown(choices=['Strongly Disagree', 'Disagree', 'Somewhat Disagree', 'Neither Agree nor Disagree', 'Somewhat Agree', 'Agree', 'Strongly Agree'], label="I feel **sad** about this situation", interactive=True) survey_post2_error = gr.Markdown(elem_id='emp') continue_survey_post2 = gr.Button("Continue to the next step") with gr.Column(visible=False) as conversation4: continue_survey_post2.click(fn=record_survey_answers, inputs=[survey_post_name2, mturk_id, confident_post2, worried_post2, hopeful_post2, motivated_post2, fear_post2, anger_post2, disgust_post2, sad_post2], outputs=[post_training_survey2, conversation4, survey_post2_error]) gr.Markdown("""# Conversation 4""") gr.Markdown("""In this section, you will chat with a simulated conversation partner powered by AI. The AI model is instructed to play the role of the person you are talking to. You will chat about the *second* situation you wrote in the qualification task. You will chat without any feedback or reference materials. You are expected to respond ten times. For each conversation turn, you should do these two steps: \n Step 1. Identify the best strategy or strategies to use in this turn. You can choose more than one strategies.\n Step 2. Write a response that exercise the strategy or strategies you select.\n Step 3. Click the "Send" button to send the response to the chatbot. """) gr.Markdown(""" The quality of this conversation will be used to determine the bonus. If you are able to use the skills you learned in the previous training conversation well (top 30\% of all the participants), you will be able to get the bonus. """) with gr.Accordion("Open to see the list of DEAR MAN skills", open=True): gr.Markdown("""## DEAR MAN Skills DEAR MAN skills helps obtain objectives effectively in a difficult situation. There are seven skills which start with the letters D, E, A, R, M, A, N. Below, we show the definitions of DEAR MAN skills and give an example for each skill. All the examples are regarding the situation where someone wants to talk to their husband about coming home late without warning them. In the exercise, you should try to use these skills to communicate in the challenging situations you brought up. You can always refer to this list of definitions and examples during the chat. \n Describe Describe the current situation (if necessary). Stick to the facts. Tell the person exactly what you are reacting to.
e.g. You told me you would be home by dinner but you didn't get here until 11.
Express Express your feelings and opinions about the situation. Don't assume that the other person knows how you feel.
e.g. When you come home so late, I start worrying about you.
Assert Assert yourself by asking for what you want or saying no clearly. Do not assume that others will figure out what you want. Remember that others cannot read your mind.
e.g. I would really like it if you would call me when you are going to be late.
Reinforce Reinforce the person ahead of time by explaining positive effects of getting what you want or need. If necessary, also clarify the negative consequences of not getting what you want or need.
e.g. I would be so relieved, and a lot easier to live with, if you do that.
Mindful Keep your focus on your goals. Maintain your position. Don't be distracted. Don't get off the topic.
e.g. I would still like a call
Appear Confident Appear effective and competent. Use a confident voice tone. Avoid saying things like "I'm not sure."
Negotiate Be willing to give to get. Offer and ask for other solutions to the problem. Reduce your request. Say no, but offer to do something else or to solve the problem another way. Focus on what will work.
e.g. How about if you text me when you think you might be late?
(Source: DBT Skills Training Manual, 2nd Edition. Marsha M. Linehan.) """) convo_num4 = gr.Textbox("convo_4", visible=False) # chat1 = gr.ChatInterface() situation2_convo4 = gr.Markdown(elem_id='emp') goal2_convo4 = gr.Markdown(elem_id='emp') system_prompt2_convo4 = gr.Markdown(visible=False) difficulty2_convo4 = gr.Markdown(visible=False) chat4_history = gr.State([]) with gr.Row(): display_chat4 = gr.Chatbot(elem_id="chuanhu_chatbot") with gr.Row(): strategy_selection4 = gr.Dropdown(['Describe', 'Express', 'Assert','Reinforce', 'Negotiate'], label='Select the most effective strategy', scale=1, interactive=True,multiselect=True, max_choices=7) text_chat4 = gr.Textbox(label='Send response exercising the strategy', scale=2) button_submit_chat4 = gr.Button("Send", scale=0) with gr.Row(): message_error_message4 = gr.Markdown(elem_id='emp') with gr.Row(visible=False) as proceed_chat4: output4= gr.Markdown('

You have done 10 turns of conversation! Please click the button below to continue. ') continue_button4 = gr.Button("Continue to the next step") button_submit_chat4.click(fn=predict, inputs=[mturk_id, strategy_selection4, text_chat4, chat4_history, system_prompt2_convo4, convo_num4, display_chat4], outputs=[display_chat4, chat4_history, text_chat4, output4, proceed_chat4, message_error_message4, strategy_selection4]) # TODO: after hitting 'Send Message', strategy selection and Feedback markdown should be refreshed / reset with gr.Accordion("I am asked to respond 10 times for each situation. What if the chatbot already agrees with me before 10 responses?", open=False): gr.Markdown("If the chatbot concurs with you within the first 10 responses, you have the option to terminate the conversation before 10 responses by clicking the button. Please note, to ensure the quality of the dataset, we will conduct a manual review to assess the reasonableness of the agreement, and we will not compensate for conversations where the chatbot did not genuinely reach an agreement. If you engage in at least 10 responses, you are not required to acquire an agreement from the chatbot and you should see a button that clearly says 'You have finished this situation, submit and continue to the next step.'") agreement_proceed_button4 = gr.Button("I confirm I have read and understood the statement above and the chatbot indeed agrees with me before I respond 10 times. End the conversation now and proceed to the next step.") auth_button.click(fn=auth, inputs=[mturk_id], outputs=[passcode_warning, intro, auth_block, situation1_intake, goal1_intake, difficulty1_intake, situation2_intake, goal2_intake, difficulty2_intake, situation1_convo1, goal1_convo1, difficulty1_convo1, situation1_convo2, goal1_convo2, difficulty1_convo2,situation1_post, goal1_post, difficulty1_post, situation1_convo3, goal1_convo3, difficulty1_convo3, situation2_post, goal2_post, difficulty2_post, situation2_convo4, goal2_convo4, difficulty2_convo4, system_prompt1_convo1, system_prompt1_convo3, system_prompt2_convo4]) # TODO: after hitting 'Send Message', strategy selection and Feedback markdown should be refreshed / reset with gr.Column(visible=False) as outtake: # outtake survey gr.Markdown("""# Outtake Survey""") survey_outtake = gr.Textbox('outtake_survey', visible=False) q1_outtake = gr.Dropdown(choices=['Strongly Agree', 'Agree', 'Somewhat Agree', 'Neither Agree nor Disagree', 'Somewhat Disagree', 'Disagree', 'Strongly Disagree'], label="After using this tool, I have a better understanding of DEAR MAN skills.", interactive=True) q2_outtake = gr.Dropdown(choices=['Strongly Agree', 'Agree', 'Somewhat Agree', 'Neither Agree nor Disagree', 'Somewhat Disagree', 'Disagree', 'Strongly Disagree'], label="Using this tool has been helpful to me in communicating in challenging situations I BROUGHT UP.", interactive=True) q3_outtake = gr.Dropdown(choices=['Strongly Agree', 'Agree', 'Somewhat Agree', 'Neither Agree nor Disagree', 'Somewhat Disagree', 'Disagree', 'Strongly Disagree'], label="Using this tool has been helpful to me in communicating in OTHER situations in the future.", interactive=True) q4_outtake = gr.Dropdown(choices=['Strongly Agree', 'Agree', 'Somewhat Agree', 'Neither Agree nor Disagree', 'Somewhat Disagree', 'Disagree', 'Strongly Disagree'], label="Would you be interested in using this tool again in the future to help you practice difficult conversations?", interactive=True) q5_outtake = gr.Dropdown(choices=["Very Likely", "Likely", "Somewhat Likely", "Neutral", "Somewhat Unlikely", "Unlikely", "Very Unlikely"], label="How likely are you to recommend this tool to a friend?", interactive=True) q6_outtake = gr.Dropdown(choices=["Very helpful", "Helpful", "Somewhat helpful", "Neutral", "Somewhat unhelpful", "Unhelpful", "Very unhelpful"], label="If you had to have a challenging conversation through *email*, how much do you think this practice would have helped you?", interactive=True) q7_outtake = gr.Dropdown(choices=["Very helpful", "Helpful", "Somewhat helpful", "Neutral", "Somewhat unhelpful", "Unhelpful", "Very unhelpful"], label="If you had to have a challenging conversation through *text message*, how much do you think this practice would have helped you?", interactive=True) q8_outtake = gr.Dropdown(choices=["Very helpful", "Helpful", "Somewhat helpful", "Neutral", "Somewhat unhelpful", "Unhelpful", "Very unhelpful"], label="If you had to have a challenging conversation through *phone call*, how much do you think this practice would have helped you?", interactive=True) q9_outtake = gr.Dropdown(choices=["Very helpful", "Helpful", "Somewhat helpful", "Neutral", "Somewhat unhelpful", "Unhelpful", "Very unhelpful"], label="If you had to have a challenging conversation through *in person conversation*, how much do you think this practice would have helped you?", interactive=True) q10_outtake = gr.Dropdown(choices=["Much more helpful", "More helpful", "Somewhat more helpful", "No difference", "Somewhat less helpful", "Less helpful", "Much less helpful"], label="If you could have practiced by practicing out loud using your microphone and hearing the simulated conversation partner through speakers/headphones, do you think having the audio component would have been", interactive=True) additional_feedback = gr.Textbox(label='Please provide any additional comments and/or feedback you have about this tool.') outtake_error = gr.Markdown(elem_id='emp') continue_outtake = gr.Button("Continue to the next step") with gr.Column(visible=False) as outro: continue_outtake.click(fn=record_survey_answers_outtake, inputs=[mturk_id, q1_outtake, q2_outtake, q3_outtake, q4_outtake, q5_outtake, q6_outtake, q7_outtake, q8_outtake, q9_outtake, q10_outtake, additional_feedback], outputs=[outtake, outro, outtake_error]) gr.Markdown("""Please record the completion code below to prove you have completed the study. YOU WILL BE ASKED TO PROVIDE THIS CODE IN MTURK SYSTEM.""", elem_id='emp') completion_code = gr.Markdown() completion_code_check = gr.Checkbox(label = "I confirm that I have recorded the completion code provided above.") completion_code_error_message = gr.Markdown(elem_id='emp') finish_button = gr.Button("Finish the study") agreement_proceed_button4.click(fn=proceed_to_next_chat_final, inputs=[mturk_id], outputs=[conversation4, outtake, completion_code]) continue_button4.click(fn=proceed_to_next_chat_final, inputs=[mturk_id], outputs=[conversation4, outtake, completion_code]) with gr.Column(visible=False) as final: gr.Markdown("""# Thank you for completing the study! You may exit the page now.""") finish_button.click(fn=proceed_to_next_chat_completion, inputs=[completion_code_check], outputs=[outro, final, completion_code_error_message]) # 'You must check the box above to continue.', gr.update(visible=False), gr.update(visible=True), '' # demo.launch(share=True) demo.launch() conn.close()