Commit
·
7e8dc67
1
Parent(s):
52de1e3
Add automatic token detection for HF authentication
Browse files- Use get_token() to auto-detect token from huggingface-cli login
- Check HF_TOKEN env var and --hf-token argument
- Provide clear error messages when no token is found
- classify-dataset.py +17 -4
classify-dataset.py
CHANGED
|
@@ -40,7 +40,7 @@ from typing import List, Dict, Any, Optional
|
|
| 40 |
|
| 41 |
import torch
|
| 42 |
from datasets import load_dataset, Dataset
|
| 43 |
-
from huggingface_hub import HfApi
|
| 44 |
from vllm import LLM, SamplingParams
|
| 45 |
from vllm.sampling_params import GuidedDecodingParams
|
| 46 |
|
|
@@ -140,8 +140,8 @@ def parse_args():
|
|
| 140 |
parser.add_argument(
|
| 141 |
"--hf-token",
|
| 142 |
type=str,
|
| 143 |
-
default=
|
| 144 |
-
help="Hugging Face API token (default: HF_TOKEN env var)"
|
| 145 |
)
|
| 146 |
parser.add_argument(
|
| 147 |
"--split",
|
|
@@ -341,12 +341,25 @@ def main():
|
|
| 341 |
success_rate = (valid_texts / total_texts * 100) if total_texts > 0 else 0
|
| 342 |
logger.info(f"Classification success rate: {success_rate:.1f}%")
|
| 343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
# Save to Hub
|
| 345 |
logger.info(f"Pushing dataset to Hub: {args.output_dataset}")
|
| 346 |
try:
|
| 347 |
dataset.push_to_hub(
|
| 348 |
args.output_dataset,
|
| 349 |
-
token=
|
| 350 |
commit_message=f"Add classifications using {args.model} with structured outputs"
|
| 351 |
)
|
| 352 |
logger.info(f"Successfully pushed to: https://huggingface.co/datasets/{args.output_dataset}")
|
|
|
|
| 40 |
|
| 41 |
import torch
|
| 42 |
from datasets import load_dataset, Dataset
|
| 43 |
+
from huggingface_hub import HfApi, get_token
|
| 44 |
from vllm import LLM, SamplingParams
|
| 45 |
from vllm.sampling_params import GuidedDecodingParams
|
| 46 |
|
|
|
|
| 140 |
parser.add_argument(
|
| 141 |
"--hf-token",
|
| 142 |
type=str,
|
| 143 |
+
default=None,
|
| 144 |
+
help="Hugging Face API token (default: auto-detect from HF_TOKEN env var or huggingface-cli login)"
|
| 145 |
)
|
| 146 |
parser.add_argument(
|
| 147 |
"--split",
|
|
|
|
| 341 |
success_rate = (valid_texts / total_texts * 100) if total_texts > 0 else 0
|
| 342 |
logger.info(f"Classification success rate: {success_rate:.1f}%")
|
| 343 |
|
| 344 |
+
# Get token for authentication
|
| 345 |
+
token = args.hf_token
|
| 346 |
+
if not token:
|
| 347 |
+
# Try to get token from environment or huggingface-cli login
|
| 348 |
+
token = os.environ.get("HF_TOKEN") or get_token()
|
| 349 |
+
|
| 350 |
+
if not token:
|
| 351 |
+
logger.error("No authentication token found. Please either:")
|
| 352 |
+
logger.error("1. Run 'huggingface-cli login'")
|
| 353 |
+
logger.error("2. Set HF_TOKEN environment variable")
|
| 354 |
+
logger.error("3. Pass --hf-token argument")
|
| 355 |
+
sys.exit(1)
|
| 356 |
+
|
| 357 |
# Save to Hub
|
| 358 |
logger.info(f"Pushing dataset to Hub: {args.output_dataset}")
|
| 359 |
try:
|
| 360 |
dataset.push_to_hub(
|
| 361 |
args.output_dataset,
|
| 362 |
+
token=token,
|
| 363 |
commit_message=f"Add classifications using {args.model} with structured outputs"
|
| 364 |
)
|
| 365 |
logger.info(f"Successfully pushed to: https://huggingface.co/datasets/{args.output_dataset}")
|