Spaces:
Runtime error
Runtime error
Raymond Weitekamp
commited on
Commit
·
85e0f0a
1
Parent(s):
3dd19ea
fix: properly handle OAuth token for private dataset operations
Browse files
app.py
CHANGED
@@ -471,12 +471,20 @@ def create_gradio_interface():
|
|
471 |
stripped_image.save(temp_path_private)
|
472 |
|
473 |
try:
|
474 |
-
#
|
475 |
-
|
|
|
476 |
try:
|
477 |
-
|
|
|
478 |
except Exception:
|
479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
|
481 |
features = datasets.Features({
|
482 |
'text': datasets.Value('string'),
|
@@ -485,7 +493,8 @@ def create_gradio_interface():
|
|
485 |
})
|
486 |
|
487 |
try:
|
488 |
-
dataset
|
|
|
489 |
except Exception:
|
490 |
# If dataset doesn't exist yet, create an empty one
|
491 |
dataset = datasets.Dataset.from_dict({
|
@@ -501,8 +510,13 @@ def create_gradio_interface():
|
|
501 |
'timestamp': timestamp
|
502 |
})
|
503 |
|
504 |
-
# Push to hub
|
505 |
-
dataset.push_to_hub(
|
|
|
|
|
|
|
|
|
|
|
506 |
os.remove(temp_path_private)
|
507 |
|
508 |
except Exception as e:
|
|
|
471 |
stripped_image.save(temp_path_private)
|
472 |
|
473 |
try:
|
474 |
+
# Initialize HfApi with the token
|
475 |
+
hf_api = HfApi(token=token)
|
476 |
+
|
477 |
try:
|
478 |
+
# Try to get dataset info first
|
479 |
+
hf_api.dataset_info(private_repo_id)
|
480 |
except Exception:
|
481 |
+
# Create repo if it doesn't exist
|
482 |
+
hf_api.create_repo(
|
483 |
+
repo_id=private_repo_id,
|
484 |
+
repo_type="dataset",
|
485 |
+
private=True,
|
486 |
+
token=token # Explicitly pass token here
|
487 |
+
)
|
488 |
|
489 |
features = datasets.Features({
|
490 |
'text': datasets.Value('string'),
|
|
|
493 |
})
|
494 |
|
495 |
try:
|
496 |
+
# Load dataset with explicit token
|
497 |
+
dataset = datasets.load_dataset(private_repo_id, split="train", token=token)
|
498 |
except Exception:
|
499 |
# If dataset doesn't exist yet, create an empty one
|
500 |
dataset = datasets.Dataset.from_dict({
|
|
|
510 |
'timestamp': timestamp
|
511 |
})
|
512 |
|
513 |
+
# Push to hub with explicit token
|
514 |
+
dataset.push_to_hub(
|
515 |
+
private_repo_id,
|
516 |
+
split="train",
|
517 |
+
token=token,
|
518 |
+
private=True
|
519 |
+
)
|
520 |
os.remove(temp_path_private)
|
521 |
|
522 |
except Exception as e:
|