innawy commited on
Commit
b4b09b0
·
1 Parent(s): dc027ed

fix some texts

Browse files
Files changed (2) hide show
  1. app.py +18 -8
  2. feedback_generation_function.py +2 -2
app.py CHANGED
@@ -31,7 +31,7 @@ DB_NAME = "postgres"
31
  openai.api_key = os.environ["OPENAI_API_KEY"]
32
  # openai.api_key = os.getenv("OPENAI_API_KEY")
33
 
34
- TABLE_NAME = "annotations" #TODO: change this table name
35
 
36
  css = """
37
 
@@ -294,7 +294,7 @@ def predict(user_id, strategy_selection, new_input, input_history, system_input_
294
  response = openai.ChatCompletion.create(
295
  model=MODEL_NAME,
296
  messages = prompt,
297
- # max_tokens = 128
298
  )
299
  print ('stopped trying')
300
 
@@ -490,8 +490,8 @@ def auth(mturk_id):
490
  conn.commit()
491
  conn.close()
492
 
493
- difficulty1_text = "You rated the difficulty of the situation as: " + str(difficulty1) + " out of 10."
494
- difficulty2_text = "You rated the difficulty of the situation as: " + str(difficulty2) + " out of 10."
495
  print (situation1)
496
  system_prompt1_convo1 = generate_system_input_situation_only(mturk_id, situation1, "situation1")
497
  system_prompt1_convo3 = system_prompt1_convo1
@@ -525,6 +525,12 @@ def format_markdown(text_type, text):
525
  def proceed_to_next_chat():
526
  return gr.update(visible=False), gr.update(visible=True)
527
 
 
 
 
 
 
 
528
  def proceed_to_next_chat_final(mturk_id):
529
  generated_completion_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 6))
530
 
@@ -589,7 +595,7 @@ def generate_feedback_and_record(user_id, current_situation, category, u, prompt
589
  def generate_skill_suggestion_and_record(user_id, situation, input_history, demonstration_mode):
590
  # inputs=[situation1_convo2, chat_history, demonstration_model_suggest_skill], outputs=[skill_suggestion0, skill_suggestion1, skill_suggestion_reason]
591
  skill_suggestion0, skill_suggestion_reason = generate_skill_suggestion(situation, input_history, demonstration_mode)
592
- record_chat_message(user_id, f"skill_suggestion0", skill_suggestion0)
593
  # record_chat_message(user_id, f"skill_suggestion1", skill_suggestion1)
594
  record_chat_message(user_id, f"skill_suggestion_reason", skill_suggestion_reason)
595
 
@@ -866,7 +872,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"
866
  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
867
 
868
  text = gr.Textbox(label='Step 3: Write a response exercising the selected strategy.')
869
- gr.Markdown('<span id="step"> Step 4: Get feedback on how well you exercise the DEAR MAN strategy. This step can take up to 60 seconds (on average, 20-30 seconds), please do not refresh the page since you may lose your progress. While you wait, review the DEAR MAN skills above to </span>')
870
  feedback_button = gr.Button("Click here to get feedback on your response")
871
  feedback_text = gr.Markdown(elem_id='emp') #clear
872
  prompt_strategy = gr.Textbox(value="reason", visible=False)
@@ -881,7 +887,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"
881
 
882
  # gr.Markdown('<span id="step"> 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. </span>')
883
 
884
- 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.') # clear
885
 
886
  gr.Markdown('<span id="step"> Step 6: Send your edited response to the chatbot. </span>')
887
  send_message_button = gr.Button("Click here to send message.")
@@ -905,6 +911,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"
905
  survey_post_name1 = gr.Textbox('post_situation1', visible=False)
906
  # 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])
907
  gr.Markdown("""# Post Training Survey - Situation 1""")
 
 
908
  # write a section of survey questions
909
  situation1_post = gr.Markdown(elem_id='emp')
910
  goal1_post = gr.Markdown(elem_id='emp')
@@ -996,6 +1004,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"
996
  # 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])
997
  gr.Markdown("""# Post Training Survey - Situation 2""")
998
  # write a section of survey questions
 
999
  situation2_post = gr.Markdown(elem_id='emp')
1000
  goal2_post = gr.Markdown(elem_id='emp')
1001
  difficulty2_post = gr.Markdown(visible=False)
@@ -1114,6 +1123,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"
1114
  completion_code = gr.Markdown()
1115
  completion_code_check = gr.Checkbox(label = "I confirm that I have recorded the completion code provided above.")
1116
  completion_code_error_message = gr.Markdown(elem_id='emp')
 
1117
  finish_button = gr.Button("Finish the study")
1118
 
1119
  agreement_proceed_button4.click(fn=proceed_to_next_chat_final, inputs=[mturk_id], outputs=[conversation4, outtake, completion_code])
@@ -1122,7 +1132,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"
1122
  with gr.Column(visible=False) as final:
1123
  gr.Markdown("""# Thank you for completing the study! You may exit the page now.""")
1124
 
1125
- finish_button.click(fn=proceed_to_next_chat, inputs=[], outputs=[outro, final]) # 'You must check the box above to continue.', gr.update(visible=False), gr.update(visible=True), ''
1126
  # demo.launch(share=True)
1127
  demo.launch()
1128
 
 
31
  openai.api_key = os.environ["OPENAI_API_KEY"]
32
  # openai.api_key = os.getenv("OPENAI_API_KEY")
33
 
34
+ TABLE_NAME = "user_study" #TODO: change this table name
35
 
36
  css = """
37
 
 
294
  response = openai.ChatCompletion.create(
295
  model=MODEL_NAME,
296
  messages = prompt,
297
+ max_tokens = 512
298
  )
299
  print ('stopped trying')
300
 
 
490
  conn.commit()
491
  conn.close()
492
 
493
+ difficulty1_text = "You rated the difficulty of the situation as: " + str(difficulty1) + " out of 9."
494
+ difficulty2_text = "You rated the difficulty of the situation as: " + str(difficulty2) + " out of 9."
495
  print (situation1)
496
  system_prompt1_convo1 = generate_system_input_situation_only(mturk_id, situation1, "situation1")
497
  system_prompt1_convo3 = system_prompt1_convo1
 
525
  def proceed_to_next_chat():
526
  return gr.update(visible=False), gr.update(visible=True)
527
 
528
+ def proceed_to_next_chat_completion(code_check):
529
+ if code_check:
530
+ return gr.update(visible=False), gr.update(visible=True), ''
531
+ else:
532
+ return gr.update(visible=True), gr.update(visible=False), '<span style="color: red;">Please confirm you have recorded your completion code and check the above to continue.</span>'
533
+
534
  def proceed_to_next_chat_final(mturk_id):
535
  generated_completion_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 6))
536
 
 
595
  def generate_skill_suggestion_and_record(user_id, situation, input_history, demonstration_mode):
596
  # inputs=[situation1_convo2, chat_history, demonstration_model_suggest_skill], outputs=[skill_suggestion0, skill_suggestion1, skill_suggestion_reason]
597
  skill_suggestion0, skill_suggestion_reason = generate_skill_suggestion(situation, input_history, demonstration_mode)
598
+ record_chat_message(user_id, f"skill_suggestion", skill_suggestion0)
599
  # record_chat_message(user_id, f"skill_suggestion1", skill_suggestion1)
600
  record_chat_message(user_id, f"skill_suggestion_reason", skill_suggestion_reason)
601
 
 
872
  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
873
 
874
  text = gr.Textbox(label='Step 3: Write a response exercising the selected strategy.')
875
+ gr.Markdown('<span id="step"> Step 4: Get feedback on how well you exercise the DEAR MAN strategy. This step can take up to 60 seconds (on average, 20-30 seconds), 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. </span>')
876
  feedback_button = gr.Button("Click here to get feedback on your response")
877
  feedback_text = gr.Markdown(elem_id='emp') #clear
878
  prompt_strategy = gr.Textbox(value="reason", visible=False)
 
887
 
888
  # gr.Markdown('<span id="step"> 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. </span>')
889
 
890
+ 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
891
 
892
  gr.Markdown('<span id="step"> Step 6: Send your edited response to the chatbot. </span>')
893
  send_message_button = gr.Button("Click here to send message.")
 
911
  survey_post_name1 = gr.Textbox('post_situation1', visible=False)
912
  # 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])
913
  gr.Markdown("""# Post Training Survey - Situation 1""")
914
+ gr.Markdown("""After the training, rethink how do you feel about having a conversation about the same situation. Please answer the following questions. """)
915
+
916
  # write a section of survey questions
917
  situation1_post = gr.Markdown(elem_id='emp')
918
  goal1_post = gr.Markdown(elem_id='emp')
 
1004
  # 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])
1005
  gr.Markdown("""# Post Training Survey - Situation 2""")
1006
  # write a section of survey questions
1007
+ gr.Markdown("""After the training, rethink how do you feel about having a conversation about a new situation. Please answer the following questions. """)
1008
  situation2_post = gr.Markdown(elem_id='emp')
1009
  goal2_post = gr.Markdown(elem_id='emp')
1010
  difficulty2_post = gr.Markdown(visible=False)
 
1123
  completion_code = gr.Markdown()
1124
  completion_code_check = gr.Checkbox(label = "I confirm that I have recorded the completion code provided above.")
1125
  completion_code_error_message = gr.Markdown(elem_id='emp')
1126
+
1127
  finish_button = gr.Button("Finish the study")
1128
 
1129
  agreement_proceed_button4.click(fn=proceed_to_next_chat_final, inputs=[mturk_id], outputs=[conversation4, outtake, completion_code])
 
1132
  with gr.Column(visible=False) as final:
1133
  gr.Markdown("""# Thank you for completing the study! You may exit the page now.""")
1134
 
1135
+ 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), ''
1136
  # demo.launch(share=True)
1137
  demo.launch()
1138
 
feedback_generation_function.py CHANGED
@@ -13,8 +13,8 @@ import json
13
 
14
  print ("finished import")
15
  openai.api_key = os.environ["OPENAI_API_KEY"]
16
- # MODEL_NAME = 'gpt-3.5-turbo-0613' # GPT 4 alternative: 'gpt-4-0613'
17
- MODEL_NAME = 'gpt-4-1106-preview'
18
  MAX_RETRIES = 5
19
  all_strategy = pd.read_csv("all_strategy_with_generated_reason.csv")
20
 
 
13
 
14
  print ("finished import")
15
  openai.api_key = os.environ["OPENAI_API_KEY"]
16
+ MODEL_NAME = 'gpt-3.5-turbo-0613' # GPT 4 alternative: 'gpt-4-0613'
17
+ # MODEL_NAME = 'gpt-4-1106-preview'
18
  MAX_RETRIES = 5
19
  all_strategy = pd.read_csv("all_strategy_with_generated_reason.csv")
20