Spaces:
Sleeping
Sleeping
Oscar Wang
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,11 @@ def get_file_size(filename):
|
|
29 |
# Data generation and saving function
|
30 |
def generate_and_save_data():
|
31 |
global file_index, current_file, file_paths, combined_tokens
|
|
|
|
|
|
|
|
|
|
|
32 |
while True:
|
33 |
try:
|
34 |
# Generate a prompt
|
@@ -94,11 +99,11 @@ def generate_and_save_data():
|
|
94 |
file_index += 1
|
95 |
current_file = os.path.join(DATA_DIRECTORY, f'data{file_index}.csv')
|
96 |
file_paths.append(current_file)
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
|
103 |
# Wait for the next update interval
|
104 |
time.sleep(UPDATE_INTERVAL)
|
|
|
29 |
# Data generation and saving function
|
30 |
def generate_and_save_data():
|
31 |
global file_index, current_file, file_paths, combined_tokens
|
32 |
+
|
33 |
+
# Create the initial file if it doesn't exist
|
34 |
+
if not os.path.isfile(current_file):
|
35 |
+
pd.DataFrame(columns=["prompt", "response"]).to_csv(current_file, index=False)
|
36 |
+
|
37 |
while True:
|
38 |
try:
|
39 |
# Generate a prompt
|
|
|
99 |
file_index += 1
|
100 |
current_file = os.path.join(DATA_DIRECTORY, f'data{file_index}.csv')
|
101 |
file_paths.append(current_file)
|
102 |
+
# Create the new file with headers
|
103 |
+
data.to_csv(current_file, mode='w', header=True, index=False)
|
104 |
+
else:
|
105 |
+
# Append data to the current file
|
106 |
+
data.to_csv(current_file, mode='a', header=False, index=False)
|
107 |
|
108 |
# Wait for the next update interval
|
109 |
time.sleep(UPDATE_INTERVAL)
|