Waqasjan123 commited on
Commit
d6caaf5
·
verified ·
1 Parent(s): aada611

Update src/data_loader.py

Browse files
Files changed (1) hide show
  1. src/data_loader.py +19 -16
src/data_loader.py CHANGED
@@ -211,16 +211,17 @@ def save_box_profile(profile_data: dict) -> Tuple[bool, str]:
211
  # Add new profile
212
  profiles.append(profile_data)
213
 
214
- # Save locally first
215
- local_path = BASE_DIR / "data" / BOX_PROFILES_FILENAME
216
- with open(local_path, "w") as f:
217
- json.dump(profiles, f, indent=2)
218
-
219
- # Sync to HuggingFace if not in dev mode
220
- if not DEV_MODE:
 
221
  success = _upload_to_huggingface(BOX_PROFILES_FILENAME, profiles)
222
  if not success:
223
- return False, "Saved locally but failed to sync to cloud"
224
 
225
  return True, f"Profile '{profile_data['name']}' saved successfully!"
226
  except Exception as e:
@@ -248,14 +249,16 @@ def delete_box_profile(profile_id: str) -> Tuple[bool, str]:
248
  if len(profiles) == original_count:
249
  return False, "Profile not found"
250
 
251
- # Save locally
252
- local_path = BASE_DIR / "data" / BOX_PROFILES_FILENAME
253
- with open(local_path, "w") as f:
254
- json.dump(profiles, f, indent=2)
255
-
256
- # Sync to HuggingFace if not in dev mode
257
- if not DEV_MODE:
258
- _upload_to_huggingface(BOX_PROFILES_FILENAME, profiles)
 
 
259
 
260
  return True, "Profile deleted successfully!"
261
  except Exception as e:
 
211
  # Add new profile
212
  profiles.append(profile_data)
213
 
214
+ if DEV_MODE:
215
+ # Save locally in development mode
216
+ local_path = BASE_DIR / "data" / BOX_PROFILES_FILENAME
217
+ with open(local_path, "w") as f:
218
+ json.dump(profiles, f, indent=2)
219
+ else:
220
+ # In production (HF Spaces), upload directly to HuggingFace
221
+ # HF Spaces filesystem is read-only, so we can't save locally
222
  success = _upload_to_huggingface(BOX_PROFILES_FILENAME, profiles)
223
  if not success:
224
+ return False, "Failed to save to cloud storage"
225
 
226
  return True, f"Profile '{profile_data['name']}' saved successfully!"
227
  except Exception as e:
 
249
  if len(profiles) == original_count:
250
  return False, "Profile not found"
251
 
252
+ if DEV_MODE:
253
+ # Save locally in development mode
254
+ local_path = BASE_DIR / "data" / BOX_PROFILES_FILENAME
255
+ with open(local_path, "w") as f:
256
+ json.dump(profiles, f, indent=2)
257
+ else:
258
+ # In production (HF Spaces), upload directly to HuggingFace
259
+ success = _upload_to_huggingface(BOX_PROFILES_FILENAME, profiles)
260
+ if not success:
261
+ return False, "Failed to delete from cloud storage"
262
 
263
  return True, "Profile deleted successfully!"
264
  except Exception as e: