Update app.py
Browse files
app.py
CHANGED
|
@@ -207,6 +207,37 @@ def get_default_system_prompt(personalized_data):
|
|
| 207 |
print(DEFAULT_SYSTEM_PROMPT)
|
| 208 |
return DEFAULT_SYSTEM_PROMPT
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
## trust-game-llama-2-7b-chat
|
| 211 |
# app.py
|
| 212 |
def construct_input_prompt(chat_history, message, personalized_data):
|
|
@@ -330,45 +361,40 @@ def generate(
|
|
| 330 |
|
| 331 |
# Print the onPage value
|
| 332 |
print("onPage for session_index =", session_index, ":", onPage)
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
# Save chat history to .csv file on HuggingFace Hub
|
| 335 |
# Generate filename with bot id and session id
|
| 336 |
-
filename = f"{session_index}_{
|
| 337 |
data_file = os.path.join(DATA_DIRECTORY, filename)
|
| 338 |
|
| 339 |
# Generate timestamp
|
| 340 |
timestamp = datetime.datetime.now()
|
| 341 |
-
|
| 342 |
# Check if the file already exists
|
| 343 |
if os.path.exists(data_file):
|
| 344 |
# If file exists, load existing data
|
| 345 |
existing_data = pd.read_csv(data_file)
|
| 346 |
|
| 347 |
-
# Add timestamp
|
| 348 |
conversation_df = pd.DataFrame(conversation)
|
| 349 |
-
#conversation_df = pd.DataFrame()
|
| 350 |
-
conversation_df['message'] = message
|
| 351 |
-
conversation_df['input_prompt'] = input_prompt
|
| 352 |
conversation_df['readable_sentence'] = readable_sentence
|
| 353 |
conversation_df['timestamp'] = timestamp
|
| 354 |
-
|
| 355 |
# Append new conversation to existing data
|
| 356 |
updated_data = pd.concat([existing_data, conversation_df], ignore_index=True)
|
| 357 |
updated_data.to_csv(data_file, index=False)
|
| 358 |
else:
|
| 359 |
# If file doesn't exist, create new file with conversation data
|
| 360 |
conversation_df = pd.DataFrame(conversation)
|
| 361 |
-
#conversation_df = pd.DataFrame()
|
| 362 |
-
conversation_df['message'] = message
|
| 363 |
-
conversation_df['input_prompt'] = input_prompt
|
| 364 |
conversation_df['readable_sentence'] = readable_sentence
|
| 365 |
conversation_df['timestamp'] = timestamp
|
| 366 |
conversation_df.to_csv(data_file, index=False)
|
| 367 |
|
| 368 |
print("Updating .csv")
|
| 369 |
-
|
| 370 |
-
timestamp = datetime.datetime.now()
|
| 371 |
-
repo.push_to_hub(blocking=False, commit_message=f"Updating data at {timestamp}")
|
| 372 |
|
| 373 |
chat_interface = gr.ChatInterface(
|
| 374 |
fn=generate,
|
|
|
|
| 207 |
print(DEFAULT_SYSTEM_PROMPT)
|
| 208 |
return DEFAULT_SYSTEM_PROMPT
|
| 209 |
|
| 210 |
+
def map_onPage(onPage):
|
| 211 |
+
# Define the mapping of onPage values to onPage_filename and onPage_prompt
|
| 212 |
+
onPage_mapping = {
|
| 213 |
+
"stage407906.php": ("stage 1", "Welcome"),
|
| 214 |
+
"stage407908.php": ("stage 2", "Trust Game Instructions 1/3"),
|
| 215 |
+
"stage407909.php": ("stage 3", "Trust Game Instructions 2/3"),
|
| 216 |
+
"stage407915.php": ("stage 4", "Trust Game Instructions 3/3"),
|
| 217 |
+
"stage407923.php": ("stage 5", "Lobby with AI"),
|
| 218 |
+
"stage407924.php": ("stage 6", "Round 1: Investor’s turn with AI"),
|
| 219 |
+
"stage407925.php": ("stage 7", "Round 1: Dealer’s turn with AI"),
|
| 220 |
+
"stage407926.php": ("stage 8", "Round 2: Investor’s turn with AI"),
|
| 221 |
+
"stage407927.php": ("stage 9", "Round 2: Investor’s turn with AI"),
|
| 222 |
+
"stage407928.php": ("stage 10", "Results with AI after 2 rounds"),
|
| 223 |
+
"stage407929.php": ("stage 11", "Round 3: Investor’s turn with AI"),
|
| 224 |
+
"stage407930.php": ("stage 12", "Round 3: Dealer’s turn with AI"),
|
| 225 |
+
"stage407931.php": ("stage 13", "Overall Questionnaire"),
|
| 226 |
+
"stage407932.php": ("stage 14", "Results with AI after 3 rounds"),
|
| 227 |
+
"stage407933.php": ("stage 15", "Redirect to Prolific - Dropout no compensation"),
|
| 228 |
+
"stage407934.php": ("stage 16", "Not used yet: Redirect to Prolific - Win"),
|
| 229 |
+
"stage407935.php": ("stage 17", "Not used yet: Redirect to Prolific - Completion"),
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
# Check if onPage is in the mapping
|
| 233 |
+
if onPage in onPage_mapping:
|
| 234 |
+
onPage_filename, onPage_prompt = onPage_mapping[onPage]
|
| 235 |
+
else:
|
| 236 |
+
# If onPage is not in the mapping, set onPage_filename and onPage_prompt to "unknown"
|
| 237 |
+
onPage_filename, onPage_prompt = "unknown", "unknown"
|
| 238 |
+
|
| 239 |
+
return onPage_filename, onPage_prompt
|
| 240 |
+
|
| 241 |
## trust-game-llama-2-7b-chat
|
| 242 |
# app.py
|
| 243 |
def construct_input_prompt(chat_history, message, personalized_data):
|
|
|
|
| 361 |
|
| 362 |
# Print the onPage value
|
| 363 |
print("onPage for session_index =", session_index, ":", onPage)
|
| 364 |
+
onPage_filename, onPage_prompt = map_onPage(onPage)
|
| 365 |
+
print("onPage_filename:", onPage_filename)
|
| 366 |
+
print("onPage_prompt:", onPage_prompt)
|
| 367 |
|
| 368 |
# Save chat history to .csv file on HuggingFace Hub
|
| 369 |
# Generate filename with bot id and session id
|
| 370 |
+
filename = f"{session_index}_{DATA_FILENAME}"
|
| 371 |
data_file = os.path.join(DATA_DIRECTORY, filename)
|
| 372 |
|
| 373 |
# Generate timestamp
|
| 374 |
timestamp = datetime.datetime.now()
|
| 375 |
+
|
| 376 |
# Check if the file already exists
|
| 377 |
if os.path.exists(data_file):
|
| 378 |
# If file exists, load existing data
|
| 379 |
existing_data = pd.read_csv(data_file)
|
| 380 |
|
| 381 |
+
# Add timestamp column
|
| 382 |
conversation_df = pd.DataFrame(conversation)
|
|
|
|
|
|
|
|
|
|
| 383 |
conversation_df['readable_sentence'] = readable_sentence
|
| 384 |
conversation_df['timestamp'] = timestamp
|
| 385 |
+
|
| 386 |
# Append new conversation to existing data
|
| 387 |
updated_data = pd.concat([existing_data, conversation_df], ignore_index=True)
|
| 388 |
updated_data.to_csv(data_file, index=False)
|
| 389 |
else:
|
| 390 |
# If file doesn't exist, create new file with conversation data
|
| 391 |
conversation_df = pd.DataFrame(conversation)
|
|
|
|
|
|
|
|
|
|
| 392 |
conversation_df['readable_sentence'] = readable_sentence
|
| 393 |
conversation_df['timestamp'] = timestamp
|
| 394 |
conversation_df.to_csv(data_file, index=False)
|
| 395 |
|
| 396 |
print("Updating .csv")
|
| 397 |
+
repo.push_to_hub(blocking=False, commit_message=f"Updating data at {timestamp}")
|
|
|
|
|
|
|
| 398 |
|
| 399 |
chat_interface = gr.ChatInterface(
|
| 400 |
fn=generate,
|