Spaces:
Sleeping
Sleeping
Update src/data_loader.py
Browse files- 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 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
|
|
|
| 221 |
success = _upload_to_huggingface(BOX_PROFILES_FILENAME, profiles)
|
| 222 |
if not success:
|
| 223 |
-
return False, "
|
| 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 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 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:
|