Spaces:
Sleeping
Sleeping
TTsamurai
commited on
Commit
·
51dcb2b
1
Parent(s):
2e4b337
add personality
Browse files
app.py
CHANGED
@@ -53,9 +53,12 @@ SYSTEM_INSTRUCTION_NON_PERSONALIZATION_FILE = os.path.join(
|
|
53 |
STATIC_FILE, "txt/system_instruction_non_personalization.txt"
|
54 |
)
|
55 |
SYSTEM_INSTRUCTION_PERSONALITY_FILE = os.path.join(STATIC_FILE, "txt/system_instruction_personality.txt")
|
56 |
-
|
57 |
STATIC_FILE, "txt/system_instruction_preference_elicitation.txt"
|
58 |
)
|
|
|
|
|
|
|
59 |
SUMMARIZATION_PROMPT_FILE = os.path.join(STATIC_FILE, "txt/system_summarization_user_preference_elicitation.txt")
|
60 |
PERSONALITY_EXT_FILE = os.path.join(STATIC_FILE, "txt/personality_ext.txt")
|
61 |
PERSONALITY_INT_FILE = os.path.join(STATIC_FILE, "txt/personality_int.txt")
|
@@ -116,7 +119,10 @@ FINAL_EVALUATION = load_static_content(FINAL_EVALUATION_FILE)
|
|
116 |
SYSTEM_INSTRUCTION_PERSONALIZATION = load_static_content(SYSTEM_INSTRUCTION_PERSONALIZATION_FILE)
|
117 |
SYSTEM_INSTRUCTION_NON_PERSONALIZATION = load_static_content(SYSTEM_INSTRUCTION_NON_PERSONALIZATION_FILE)
|
118 |
SYSTEM_INSTRUCTION_PERSONALITY = load_static_content(SYSTEM_INSTRUCTION_PERSONALITY_FILE)
|
119 |
-
|
|
|
|
|
|
|
120 |
SUMMARIZATION_PROMPT = load_static_content(SUMMARIZATION_PROMPT_FILE)
|
121 |
PERSONALITY_EXT = load_static_content(PERSONALITY_EXT_FILE)
|
122 |
PERSONALITY_INT = load_static_content(PERSONALITY_INT_FILE)
|
@@ -584,7 +590,9 @@ def create_demo():
|
|
584 |
[tab_session, reason, likelihood, confidence, familiarity, evaluation_send_button, textbox],
|
585 |
)
|
586 |
|
587 |
-
def click_control_preference_stage(
|
|
|
|
|
588 |
(
|
589 |
start_conversation,
|
590 |
msg_button,
|
@@ -604,7 +612,7 @@ def create_demo():
|
|
604 |
user_id,
|
605 |
user_preference_elicitation_data,
|
606 |
history,
|
607 |
-
|
608 |
user_elicitation=True,
|
609 |
),
|
610 |
[user_id, user_preference_elicitation_session, elicitation_chatbot],
|
@@ -616,7 +624,7 @@ def create_demo():
|
|
616 |
tab_data,
|
617 |
message,
|
618 |
tab_data["history"],
|
619 |
-
|
620 |
user_elicitation=True,
|
621 |
),
|
622 |
[user_id, user_preference_elicitation_session, msg, elicitation_chatbot],
|
@@ -627,7 +635,7 @@ def create_demo():
|
|
627 |
user_id,
|
628 |
tab_data,
|
629 |
tab_data["history"],
|
630 |
-
|
631 |
user_elicitation=True,
|
632 |
),
|
633 |
[user_id, user_preference_elicitation_session, elicitation_chatbot],
|
@@ -1117,6 +1125,14 @@ def create_demo():
|
|
1117 |
elif experiment_id == "3":
|
1118 |
return SYSTEM_INSTRUCTION_PERSONALITY.format(personality=PERSONALITY_INT)
|
1119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1120 |
def get_stock_related_context(narrative_id, user_in_narrative_id):
|
1121 |
raw_context_list = build_raw_context_list(context_info_list[int(narrative_id)])
|
1122 |
stock_context_list = build_context(context_info_list[int(narrative_id)])
|
@@ -1129,6 +1145,9 @@ def create_demo():
|
|
1129 |
user_id, user_in_narrative_id, narrative_id, experiment_id = set_user_id(request)
|
1130 |
# System instruction without prompt
|
1131 |
system_description_without_context = get_inst_without_context(experiment_id)
|
|
|
|
|
|
|
1132 |
# Stock related context
|
1133 |
raw_context_list, stock_context_list = get_stock_related_context(narrative_id, user_in_narrative_id)
|
1134 |
# User Narrative
|
@@ -1158,6 +1177,7 @@ def create_demo():
|
|
1158 |
narrative_id,
|
1159 |
experiment_id,
|
1160 |
system_description_without_context,
|
|
|
1161 |
raw_context_list,
|
1162 |
stock_context_list,
|
1163 |
user_narrative,
|
@@ -1190,6 +1210,7 @@ def create_demo():
|
|
1190 |
narrative_id = gr.State()
|
1191 |
experiment_id = gr.State()
|
1192 |
system_description_without_context = gr.State()
|
|
|
1193 |
# Context data
|
1194 |
raw_context_list = gr.State()
|
1195 |
stock_context_list = gr.State()
|
@@ -1229,7 +1250,10 @@ def create_demo():
|
|
1229 |
user_preference_elicitation_tab = tab_creation_preference_stage()
|
1230 |
user_narrative = user_preference_elicitation_tab["user_narrative"]
|
1231 |
click_control_preference_stage(
|
1232 |
-
user_preference_elicitation_tab,
|
|
|
|
|
|
|
1233 |
)
|
1234 |
with gr.Tab("Financial Decision Stage") as financial_decision:
|
1235 |
# Experiment Tag
|
@@ -1309,6 +1333,7 @@ def create_demo():
|
|
1309 |
narrative_id,
|
1310 |
experiment_id,
|
1311 |
system_description_without_context,
|
|
|
1312 |
raw_context_list,
|
1313 |
stock_context_list,
|
1314 |
user_narrative,
|
|
|
53 |
STATIC_FILE, "txt/system_instruction_non_personalization.txt"
|
54 |
)
|
55 |
SYSTEM_INSTRUCTION_PERSONALITY_FILE = os.path.join(STATIC_FILE, "txt/system_instruction_personality.txt")
|
56 |
+
SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION_FILE = os.path.join(
|
57 |
STATIC_FILE, "txt/system_instruction_preference_elicitation.txt"
|
58 |
)
|
59 |
+
SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION_PERSONALITY_FILE = os.path.join(
|
60 |
+
STATIC_FILE, "txt/system_instruction_preference_elicitation_personality.txt"
|
61 |
+
)
|
62 |
SUMMARIZATION_PROMPT_FILE = os.path.join(STATIC_FILE, "txt/system_summarization_user_preference_elicitation.txt")
|
63 |
PERSONALITY_EXT_FILE = os.path.join(STATIC_FILE, "txt/personality_ext.txt")
|
64 |
PERSONALITY_INT_FILE = os.path.join(STATIC_FILE, "txt/personality_int.txt")
|
|
|
119 |
SYSTEM_INSTRUCTION_PERSONALIZATION = load_static_content(SYSTEM_INSTRUCTION_PERSONALIZATION_FILE)
|
120 |
SYSTEM_INSTRUCTION_NON_PERSONALIZATION = load_static_content(SYSTEM_INSTRUCTION_NON_PERSONALIZATION_FILE)
|
121 |
SYSTEM_INSTRUCTION_PERSONALITY = load_static_content(SYSTEM_INSTRUCTION_PERSONALITY_FILE)
|
122 |
+
SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION = load_static_content(SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION_FILE)
|
123 |
+
SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION_PERSONALITY = load_static_content(
|
124 |
+
SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION_PERSONALITY_FILE
|
125 |
+
)
|
126 |
SUMMARIZATION_PROMPT = load_static_content(SUMMARIZATION_PROMPT_FILE)
|
127 |
PERSONALITY_EXT = load_static_content(PERSONALITY_EXT_FILE)
|
128 |
PERSONALITY_INT = load_static_content(PERSONALITY_INT_FILE)
|
|
|
590 |
[tab_session, reason, likelihood, confidence, familiarity, evaluation_send_button, textbox],
|
591 |
)
|
592 |
|
593 |
+
def click_control_preference_stage(
|
594 |
+
tabs, user_id, user_preference_elicitation_session, system_description_user_elicitation
|
595 |
+
):
|
596 |
(
|
597 |
start_conversation,
|
598 |
msg_button,
|
|
|
612 |
user_id,
|
613 |
user_preference_elicitation_data,
|
614 |
history,
|
615 |
+
system_description_user_elicitation,
|
616 |
user_elicitation=True,
|
617 |
),
|
618 |
[user_id, user_preference_elicitation_session, elicitation_chatbot],
|
|
|
624 |
tab_data,
|
625 |
message,
|
626 |
tab_data["history"],
|
627 |
+
system_description_user_elicitation,
|
628 |
user_elicitation=True,
|
629 |
),
|
630 |
[user_id, user_preference_elicitation_session, msg, elicitation_chatbot],
|
|
|
635 |
user_id,
|
636 |
tab_data,
|
637 |
tab_data["history"],
|
638 |
+
system_description_user_elicitation,
|
639 |
user_elicitation=True,
|
640 |
),
|
641 |
[user_id, user_preference_elicitation_session, elicitation_chatbot],
|
|
|
1125 |
elif experiment_id == "3":
|
1126 |
return SYSTEM_INSTRUCTION_PERSONALITY.format(personality=PERSONALITY_INT)
|
1127 |
|
1128 |
+
def get_user_preference_elicitation(experiment_id):
|
1129 |
+
if experiment_id == "0" or experiment_id == "1":
|
1130 |
+
return SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION
|
1131 |
+
elif experiment_id == "2":
|
1132 |
+
return SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION_PERSONALITY.format(personality=PERSONALITY_EXT)
|
1133 |
+
elif experiment_id == "3":
|
1134 |
+
return SYSTEM_INSTRUCTION_PREFERENCE_ELICITATION_PERSONALITY.format(personality=PERSONALITY_INT)
|
1135 |
+
|
1136 |
def get_stock_related_context(narrative_id, user_in_narrative_id):
|
1137 |
raw_context_list = build_raw_context_list(context_info_list[int(narrative_id)])
|
1138 |
stock_context_list = build_context(context_info_list[int(narrative_id)])
|
|
|
1145 |
user_id, user_in_narrative_id, narrative_id, experiment_id = set_user_id(request)
|
1146 |
# System instruction without prompt
|
1147 |
system_description_without_context = get_inst_without_context(experiment_id)
|
1148 |
+
# user_preference_elicitation
|
1149 |
+
system_description_user_elicitation = get_user_preference_elicitation(experiment_id)
|
1150 |
+
print(system_description_user_elicitation)
|
1151 |
# Stock related context
|
1152 |
raw_context_list, stock_context_list = get_stock_related_context(narrative_id, user_in_narrative_id)
|
1153 |
# User Narrative
|
|
|
1177 |
narrative_id,
|
1178 |
experiment_id,
|
1179 |
system_description_without_context,
|
1180 |
+
system_description_user_elicitation,
|
1181 |
raw_context_list,
|
1182 |
stock_context_list,
|
1183 |
user_narrative,
|
|
|
1210 |
narrative_id = gr.State()
|
1211 |
experiment_id = gr.State()
|
1212 |
system_description_without_context = gr.State()
|
1213 |
+
system_description_user_elicitation = gr.State()
|
1214 |
# Context data
|
1215 |
raw_context_list = gr.State()
|
1216 |
stock_context_list = gr.State()
|
|
|
1250 |
user_preference_elicitation_tab = tab_creation_preference_stage()
|
1251 |
user_narrative = user_preference_elicitation_tab["user_narrative"]
|
1252 |
click_control_preference_stage(
|
1253 |
+
user_preference_elicitation_tab,
|
1254 |
+
user_id,
|
1255 |
+
user_preference_elicitation_session,
|
1256 |
+
system_description_user_elicitation,
|
1257 |
)
|
1258 |
with gr.Tab("Financial Decision Stage") as financial_decision:
|
1259 |
# Experiment Tag
|
|
|
1333 |
narrative_id,
|
1334 |
experiment_id,
|
1335 |
system_description_without_context,
|
1336 |
+
system_description_user_elicitation,
|
1337 |
raw_context_list,
|
1338 |
stock_context_list,
|
1339 |
user_narrative,
|