Spaces:
Sleeping
Sleeping
innawy commited on
Commit ·
d45cb48
1
Parent(s): b69c9ca
add edge case
Browse files- app.py +1 -1
- feedback_generation_function.py +33 -27
app.py
CHANGED
|
@@ -872,7 +872,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="purple"
|
|
| 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
|
| 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)
|
|
|
|
| 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.</span> 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. <b>While you wait, review the DEAR MAN skills above to familiarize yourself with the skills.</b> If this step takes more than 3 mins, please reach out to ilin@cs.washington.edu')
|
| 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)
|
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 |
-
|
| 18 |
MAX_RETRIES = 5
|
| 19 |
all_strategy = pd.read_csv("all_strategy_with_generated_reason.csv")
|
| 20 |
|
|
@@ -424,36 +424,42 @@ def generate_feedback(current_situation, category, u, prompt_strategy, prompt_se
|
|
| 424 |
# return all_concat
|
| 425 |
|
| 426 |
def generate_feedback_with_mc(current_situation, category, u, prompt_strategy, prompt_selection, strategy_list):
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
strategy_rating = strategy_output.split(f'{strategy} Rating:')[1].split('###')[0].strip()
|
| 433 |
-
strategy_suggestion = strategy_output.split(f'{strategy} Rating:')[1].split('Suggestion for improvement: ')[1].split('###')[0].strip()
|
| 434 |
-
|
| 435 |
-
strategy_feedback = strategy_rating + '<br/>' + strategy_suggestion
|
| 436 |
-
|
| 437 |
-
mindful_rating = mindful_output.split('Mindful Rating:')[1].split('###')[0].strip()
|
| 438 |
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
mindful_feedback = "Mindfulness check: Well done! 👍 "
|
| 443 |
-
else:
|
| 444 |
-
mindful_feedback = "Mindfulness check: " + mindful_output.split('Mindful Rating:')[1].split('Suggestion for improvement: ')[1].split('###')[0].strip()
|
| 445 |
|
|
|
|
|
|
|
|
|
|
| 446 |
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
confident_feedback = ''
|
| 451 |
-
|
| 452 |
-
confident_feedback = "Confidence check: Well done! 👍 "
|
| 453 |
-
else:
|
| 454 |
-
confident_feedback = "Confidence check: " + confident_output.split('Confident Rating:')[1].split('Suggestion for improvement: ')[1].split('###')[0].strip()
|
| 455 |
-
|
| 456 |
-
|
| 457 |
print (strategy_output, mindful_output, confident_output)
|
| 458 |
all_concat = strategy_feedback + '</br> </br>' + mindful_feedback + '</br>' + confident_feedback
|
| 459 |
|
|
|
|
| 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 |
|
|
|
|
| 424 |
# return all_concat
|
| 425 |
|
| 426 |
def generate_feedback_with_mc(current_situation, category, u, prompt_strategy, prompt_selection, strategy_list):
|
| 427 |
+
try:
|
| 428 |
+
strategy_output = generate_feedback(current_situation, category, u, prompt_strategy, prompt_selection, strategy_list)
|
| 429 |
+
strategy = strategy_list[0]
|
| 430 |
+
strategy_rating = strategy_output.split(f'{strategy} Rating:')[1].split('###')[0].strip()
|
| 431 |
+
strategy_suggestion = strategy_output.split(f'{strategy} Rating:')[1].split('Suggestion for improvement: ')[1].split('###')[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
|
| 433 |
+
strategy_feedback = strategy_rating + '<br/>' + strategy_suggestion
|
| 434 |
+
except:
|
| 435 |
+
strategy_feedback = 'The model does not have a feedback for this utterance. Please try a slightly different wording.'
|
|
|
|
|
|
|
|
|
|
| 436 |
|
| 437 |
+
try:
|
| 438 |
+
mindful_output = generate_feedback(current_situation, category, u, prompt_strategy, prompt_selection, ['mindful'])
|
| 439 |
+
mindful_rating = mindful_output.split('Mindful Rating:')[1].split('###')[0].strip()
|
| 440 |
|
| 441 |
+
if mindful_rating != 'Yes' and mindful_rating != 'No':
|
| 442 |
+
mindful_feedback = ''
|
| 443 |
+
elif mindful_rating == 'Yes':
|
| 444 |
+
mindful_feedback = "Mindfulness check: Well done! 👍 "
|
| 445 |
+
else:
|
| 446 |
+
mindful_feedback = "Mindfulness check: " + mindful_output.split('Mindful Rating:')[1].split('Suggestion for improvement: ')[1].split('###')[0].strip()
|
| 447 |
|
| 448 |
+
except:
|
| 449 |
+
mindful_feedback = ''
|
| 450 |
+
try:
|
| 451 |
+
confident_output = generate_feedback(current_situation, category, u, prompt_strategy, prompt_selection, ['confident'])
|
| 452 |
+
confident_rating = confident_output.split('Confident Rating:')[1].split('###')[0].strip()
|
| 453 |
+
|
| 454 |
+
if confident_rating != 'Yes' and confident_rating != 'No':
|
| 455 |
+
confident_feedback = ''
|
| 456 |
+
elif confident_rating == 'Yes':
|
| 457 |
+
confident_feedback = "Confidence check: Well done! 👍 "
|
| 458 |
+
else:
|
| 459 |
+
confident_feedback = "Confidence check: " + confident_output.split('Confident Rating:')[1].split('Suggestion for improvement: ')[1].split('###')[0].strip()
|
| 460 |
+
except:
|
| 461 |
confident_feedback = ''
|
| 462 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
print (strategy_output, mindful_output, confident_output)
|
| 464 |
all_concat = strategy_feedback + '</br> </br>' + mindful_feedback + '</br>' + confident_feedback
|
| 465 |
|