Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -68,10 +68,14 @@ if img_file_buffer is not None:
|
|
68 |
# Check if the CSV file exists
|
69 |
file_path = os.path.join("data", "data.csv")
|
70 |
if os.path.exists(file_path):
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
75 |
else:
|
76 |
# Create new CSV file with data
|
77 |
df.to_csv(file_path, index=False)
|
|
|
68 |
# Check if the CSV file exists
|
69 |
file_path = os.path.join("data", "data.csv")
|
70 |
if os.path.exists(file_path):
|
71 |
+
try:
|
72 |
+
# Append new data to existing CSV file
|
73 |
+
existing_df = pd.read_csv(file_path)
|
74 |
+
updated_df = pd.concat([existing_df, df], ignore_index=True)
|
75 |
+
updated_df.to_csv(file_path, index=False)
|
76 |
+
except pd.errors.EmptyDataError:
|
77 |
+
# If the file is empty, write the new data to it
|
78 |
+
df.to_csv(file_path, index=False)
|
79 |
else:
|
80 |
# Create new CSV file with data
|
81 |
df.to_csv(file_path, index=False)
|