Update app.py
Browse files
app.py
CHANGED
|
@@ -377,14 +377,23 @@ def generate(
|
|
| 377 |
print(groupNrStart)
|
| 378 |
print(playerNr)
|
| 379 |
|
|
|
|
| 380 |
# Save chat history to .csv file on HuggingFace Hub
|
| 381 |
# Generate filename with bot id and session id
|
| 382 |
filename = f"{groupNrStart}_{playerNr}_{PROLIFIC_PID}_{onPage}_{DATA_FILENAME}"
|
| 383 |
data_file = os.path.join(DATA_DIRECTORY, filename)
|
| 384 |
-
|
| 385 |
# Generate timestamp
|
| 386 |
timestamp = datetime.datetime.now()
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
# Create a DataFrame for the current conversation turn
|
| 389 |
turn_data = {
|
| 390 |
"turn_id": len(existing_data) + 1 if existing_data is not None else 1,
|
|
@@ -396,14 +405,10 @@ def generate(
|
|
| 396 |
}
|
| 397 |
turn_df = pd.DataFrame([turn_data])
|
| 398 |
|
| 399 |
-
# Check if the
|
| 400 |
-
if
|
| 401 |
-
# If file exists, load existing data
|
| 402 |
-
existing_data = pd.read_csv(data_file)
|
| 403 |
-
# Append the new conversation turn to the existing data
|
| 404 |
updated_data = pd.concat([existing_data, turn_df], ignore_index=True)
|
| 405 |
else:
|
| 406 |
-
# If file doesn't exist, create new DataFrame with the current conversation turn
|
| 407 |
updated_data = turn_df
|
| 408 |
|
| 409 |
# Write the updated data to the CSV file
|
|
|
|
| 377 |
print(groupNrStart)
|
| 378 |
print(playerNr)
|
| 379 |
|
| 380 |
+
|
| 381 |
# Save chat history to .csv file on HuggingFace Hub
|
| 382 |
# Generate filename with bot id and session id
|
| 383 |
filename = f"{groupNrStart}_{playerNr}_{PROLIFIC_PID}_{onPage}_{DATA_FILENAME}"
|
| 384 |
data_file = os.path.join(DATA_DIRECTORY, filename)
|
| 385 |
+
|
| 386 |
# Generate timestamp
|
| 387 |
timestamp = datetime.datetime.now()
|
| 388 |
|
| 389 |
+
# Check if the file already exists
|
| 390 |
+
if os.path.exists(data_file):
|
| 391 |
+
# If file exists, load existing data
|
| 392 |
+
existing_data = pd.read_csv(data_file)
|
| 393 |
+
else:
|
| 394 |
+
# If file doesn't exist, set existing_data to None
|
| 395 |
+
existing_data = None
|
| 396 |
+
|
| 397 |
# Create a DataFrame for the current conversation turn
|
| 398 |
turn_data = {
|
| 399 |
"turn_id": len(existing_data) + 1 if existing_data is not None else 1,
|
|
|
|
| 405 |
}
|
| 406 |
turn_df = pd.DataFrame([turn_data])
|
| 407 |
|
| 408 |
+
# Check if existing_data is not None and concatenate the new conversation turn
|
| 409 |
+
if existing_data is not None:
|
|
|
|
|
|
|
|
|
|
| 410 |
updated_data = pd.concat([existing_data, turn_df], ignore_index=True)
|
| 411 |
else:
|
|
|
|
| 412 |
updated_data = turn_df
|
| 413 |
|
| 414 |
# Write the updated data to the CSV file
|