Spaces:
Running
Running
Force push code via HfApi (Git fallback)
Browse files- app.py +12 -1
- scripts/sync_data.py +4 -0
app.py
CHANGED
|
@@ -142,17 +142,28 @@ class SyncManager:
|
|
| 142 |
try:
|
| 143 |
if filenames is None:
|
| 144 |
# Push everything (including images)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
self.api.upload_folder(
|
| 146 |
folder_path=self.data_dir,
|
| 147 |
repo_id=self.repo_id,
|
| 148 |
repo_type="dataset",
|
| 149 |
commit_message="Sync update",
|
| 150 |
path_in_repo=".",
|
| 151 |
-
ignore_patterns=
|
| 152 |
)
|
| 153 |
else:
|
| 154 |
# Push specific files
|
| 155 |
for filename in filenames:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
path = self.data_dir / filename
|
| 157 |
if path.exists():
|
| 158 |
self.api.upload_file(
|
|
|
|
| 142 |
try:
|
| 143 |
if filenames is None:
|
| 144 |
# Push everything (including images)
|
| 145 |
+
# If running locally (not in Space), exclude visits.jsonl to prevent overwriting live data
|
| 146 |
+
ignore_patterns = ["*.tmp", ".*"]
|
| 147 |
+
if not os.getenv("SPACE_ID"):
|
| 148 |
+
print("Sync: Local environment detected. Excluding visits.jsonl from bulk push to protect live data.")
|
| 149 |
+
ignore_patterns.append("visits.jsonl")
|
| 150 |
+
|
| 151 |
self.api.upload_folder(
|
| 152 |
folder_path=self.data_dir,
|
| 153 |
repo_id=self.repo_id,
|
| 154 |
repo_type="dataset",
|
| 155 |
commit_message="Sync update",
|
| 156 |
path_in_repo=".",
|
| 157 |
+
ignore_patterns=ignore_patterns
|
| 158 |
)
|
| 159 |
else:
|
| 160 |
# Push specific files
|
| 161 |
for filename in filenames:
|
| 162 |
+
# Safety check for visits.jsonl in local env
|
| 163 |
+
if filename == "visits.jsonl" and not os.getenv("SPACE_ID"):
|
| 164 |
+
print("Sync: Skipping explicit push of visits.jsonl in local environment to protect live data.")
|
| 165 |
+
continue
|
| 166 |
+
|
| 167 |
path = self.data_dir / filename
|
| 168 |
if path.exists():
|
| 169 |
self.api.upload_file(
|
scripts/sync_data.py
CHANGED
|
@@ -29,6 +29,10 @@ if __name__ == "__main__":
|
|
| 29 |
|
| 30 |
print(f"Token: {HF_TOKEN[:4]}...")
|
| 31 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
manager.push()
|
| 33 |
print("Sync completed successfully.")
|
| 34 |
except Exception as e:
|
|
|
|
| 29 |
|
| 30 |
print(f"Token: {HF_TOKEN[:4]}...")
|
| 31 |
try:
|
| 32 |
+
# Pull first to ensure we have latest visits (though app.py logic now prevents local push of visits)
|
| 33 |
+
# manager.pull()
|
| 34 |
+
|
| 35 |
+
# Push all (app.py will exclude visits.jsonl if local)
|
| 36 |
manager.push()
|
| 37 |
print("Sync completed successfully.")
|
| 38 |
except Exception as e:
|