Vikas01 commited on
Commit
d19f7f6
·
1 Parent(s): 2a3aeec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
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
- # Append new data to existing CSV file
72
- existing_df = pd.read_csv(file_path)
73
- updated_df = pd.concat([existing_df, df], ignore_index=True)
74
- updated_df.to_csv(file_path, index=False)
 
 
 
 
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)