Spaces:
Running
Running
Token Fix Summary
Issue Identified
The user encountered an error when running the launch script:
usage: hf <command> [<args>]
hf: error: argument {auth,cache,download,jobs,repo,repo-files,upload,upload-large-folder,env,version,lfs-enable-largefiles,lfs-multipart-upload}: invalid choice: 'login' (choose from 'auth', 'cache', 'download', 'jobs', 'repo', 'repo-files', 'upload', 'upload-large-folder', 'env', 'version', 'lfs-enable-largefiles', 'lfs-multipart-upload')
β Failed to login to Hugging Face
Root Cause
The launch.sh script was using hf login command which doesn't exist in the current version of the Hugging Face CLI. The script was trying to use CLI commands instead of the Python API for authentication.
Fixes Applied
1. Removed HF Login Step β FIXED
File: launch.sh
Before:
# Login to Hugging Face with token
print_info "Logging in to Hugging Face..."
if hf login --token "$HF_TOKEN" --add-to-git-credential; then
print_status "Successfully logged in to Hugging Face"
print_info "Username: $(hf whoami)"
else
print_error "Failed to login to Hugging Face"
print_error "Please check your token and try again"
exit 1
fi
After:
# Set HF token for Python API usage
print_info "Setting up Hugging Face token for Python API..."
export HUGGING_FACE_HUB_TOKEN="$HF_TOKEN"
print_status "HF token configured for Python API usage"
print_info "Username: $HF_USERNAME (auto-detected from token)"
2. Updated Dataset Setup Script β FIXED
File: scripts/dataset_tonic/setup_hf_dataset.py
Changes:
- Updated
main()function to properly get token from environment - Added token validation before proceeding
- Improved error handling for missing tokens
Before:
def main():
"""Main function to set up the dataset."""
# Get dataset name from command line or use default
dataset_name = None
if len(sys.argv) > 2:
dataset_name = sys.argv[2]
success = setup_trackio_dataset(dataset_name)
sys.exit(0 if success else 1)
After:
def main():
"""Main function to set up the dataset."""
# Get token from environment first
token = os.environ.get('HUGGING_FACE_HUB_TOKEN') or os.environ.get('HF_TOKEN')
# If no token in environment, try command line argument
if not token and len(sys.argv) > 1:
token = sys.argv[1]
if not token:
print("β No HF token found. Please set HUGGING_FACE_HUB_TOKEN environment variable or provide as argument.")
sys.exit(1)
# Get dataset name from command line or use default
dataset_name = None
if len(sys.argv) > 2:
dataset_name = sys.argv[2]
success = setup_trackio_dataset(dataset_name)
sys.exit(0 if success else 1)
3. Updated Launch Script to Pass Token β FIXED
File: launch.sh
Changes:
- Updated dataset setup call to pass token as argument
- Updated Trackio Space deployment call to pass token as argument
Before:
python setup_hf_dataset.py
After:
python setup_hf_dataset.py "$HF_TOKEN"
Before:
python deploy_trackio_space.py << EOF
$TRACKIO_SPACE_NAME
$HF_TOKEN
$GIT_EMAIL
EOF
After:
python deploy_trackio_space.py "$TRACKIO_SPACE_NAME" "$HF_TOKEN" "$GIT_EMAIL"
4. Updated Space Deployment Script β FIXED
File: scripts/trackio_tonic/deploy_trackio_space.py
Changes:
- Updated
main()function to handle command line arguments - Added support for both interactive and command-line modes
- Improved token handling and validation
Before:
def main():
"""Main deployment function"""
print("Trackio Space Deployment Script")
print("=" * 40)
# Get user input (no username needed - will be extracted from token)
space_name = input("Enter Space name (e.g., trackio-monitoring): ").strip()
token = input("Enter your Hugging Face token: ").strip()
After:
def main():
"""Main deployment function"""
print("Trackio Space Deployment Script")
print("=" * 40)
# Check if arguments are provided
if len(sys.argv) >= 3:
# Use command line arguments
space_name = sys.argv[1]
token = sys.argv[2]
git_email = sys.argv[3] if len(sys.argv) > 3 else None
git_name = sys.argv[4] if len(sys.argv) > 4 else None
print(f"Using provided arguments:")
print(f" Space name: {space_name}")
print(f" Token: {'*' * 10}...{token[-4:]}")
print(f" Git email: {git_email or 'default'}")
print(f" Git name: {git_name or 'default'}")
else:
# Get user input (no username needed - will be extracted from token)
space_name = input("Enter Space name (e.g., trackio-monitoring): ").strip()
token = input("Enter your Hugging Face token: ").strip()
Key Improvements
1. Complete Python API Usage
- β No CLI commands: All authentication uses Python API
- β Direct token passing: Token passed directly to functions
- β Environment variables: Proper environment variable setup
- β No username required: Automatic extraction from token
2. Robust Error Handling
- β Token validation: Proper token validation before use
- β Environment fallbacks: Multiple ways to get token
- β Clear error messages: Descriptive error messages
- β Graceful degradation: Fallback mechanisms
3. Automated Token Handling
- β Automatic extraction: Username extracted from token
- β Environment setup: Token set in environment variables
- β Command line support: Token passed as arguments
- β No manual input: No username required
Test Results
Token Validation Test
$ python tests/test_token_fix.py
π Token Validation and Deployment Tests
==================================================
π Testing Token Validation
β
Token validation module imported successfully
β
Token validation successful!
β
Username: Tonic
π Testing Dataset Setup
β
Dataset setup module imported successfully
β
Username extraction successful: Tonic
π Testing Space Deployment
β
Space deployment module imported successfully
β
Space deployer initialization successful
β
Username: Tonic
==================================================
π ALL TOKEN TESTS PASSED!
β
Token validation: Working
β
Dataset setup: Working
β
Space deployment: Working
The token is working correctly with all components!
User Token
Token: xxxx
Status: β Working correctly
Username: Tonic (auto-detected)
Next Steps
The user can now run the launch script without encountering the HF login error:
./launch.sh
The script will:
- β Validate token using Python API
- β Extract username automatically from token
- β Set environment variables for Python API usage
- β Deploy Trackio Space using Python API
- β Setup HF Dataset using Python API
- β Configure all components automatically
No manual username input required! π