Spaces:
Running
on
Zero
Running
on
Zero
Fix: Use HF_TOKEN secret for dataset contributions
Browse files
app.py
CHANGED
|
@@ -34,11 +34,15 @@ def get_device_info():
|
|
| 34 |
|
| 35 |
def contribute_to_dataset(features, labels, num_legit, num_cheaters, seed):
|
| 36 |
try:
|
| 37 |
-
from huggingface_hub import HfApi
|
| 38 |
import tempfile
|
| 39 |
import os
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
contribution_id = f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}"
|
| 44 |
|
|
@@ -62,9 +66,9 @@ def contribute_to_dataset(features, labels, num_legit, num_cheaters, seed):
|
|
| 62 |
with open(meta_path, "w") as f:
|
| 63 |
json.dump(metadata, f, indent=2)
|
| 64 |
|
| 65 |
-
upload_file(path_or_fileobj=features_path, path_in_repo=f"contributions/features_{contribution_id}.npy", repo_id=DATASET_REPO, repo_type="dataset")
|
| 66 |
-
upload_file(path_or_fileobj=labels_path, path_in_repo=f"contributions/labels_{contribution_id}.npy", repo_id=DATASET_REPO, repo_type="dataset")
|
| 67 |
-
upload_file(path_or_fileobj=meta_path, path_in_repo=f"contributions/meta_{contribution_id}.json", repo_id=DATASET_REPO, repo_type="dataset")
|
| 68 |
|
| 69 |
return True, contribution_id
|
| 70 |
except Exception as e:
|
|
|
|
| 34 |
|
| 35 |
def contribute_to_dataset(features, labels, num_legit, num_cheaters, seed):
|
| 36 |
try:
|
| 37 |
+
from huggingface_hub import HfApi
|
| 38 |
import tempfile
|
| 39 |
import os
|
| 40 |
|
| 41 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 42 |
+
if not hf_token:
|
| 43 |
+
return False, "HF_TOKEN not configured"
|
| 44 |
+
|
| 45 |
+
api = HfApi(token=hf_token)
|
| 46 |
|
| 47 |
contribution_id = f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{uuid.uuid4().hex[:8]}"
|
| 48 |
|
|
|
|
| 66 |
with open(meta_path, "w") as f:
|
| 67 |
json.dump(metadata, f, indent=2)
|
| 68 |
|
| 69 |
+
api.upload_file(path_or_fileobj=features_path, path_in_repo=f"contributions/features_{contribution_id}.npy", repo_id=DATASET_REPO, repo_type="dataset")
|
| 70 |
+
api.upload_file(path_or_fileobj=labels_path, path_in_repo=f"contributions/labels_{contribution_id}.npy", repo_id=DATASET_REPO, repo_type="dataset")
|
| 71 |
+
api.upload_file(path_or_fileobj=meta_path, path_in_repo=f"contributions/meta_{contribution_id}.json", repo_id=DATASET_REPO, repo_type="dataset")
|
| 72 |
|
| 73 |
return True, contribution_id
|
| 74 |
except Exception as e:
|