| | #!/bin/bash |
| |
|
| | |
| | |
| | |
| |
|
| | set -euo pipefail |
| |
|
| | |
| | HF_HOME="${HF_HOME:-/workspace/.hf_home}" |
| | CONFIG_DIR="/etc/dto/huggingface" |
| | LOG_DIR="/var/log/dto" |
| |
|
| | |
| | RED='\033[0;31m' |
| | GREEN='\033[0;32m' |
| | YELLOW='\033[1;33m' |
| | NC='\033[0m' |
| |
|
| | |
| | log() { |
| | echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1" |
| | } |
| |
|
| | error() { |
| | echo -e "${RED}[ERROR]${NC} $1" >&2 |
| | } |
| |
|
| | warning() { |
| | echo -e "${YELLOW}[WARNING]${NC} $1" |
| | } |
| |
|
| | |
| | install_huggingface_hub() { |
| | log "Installing Hugging Face Hub" |
| | |
| | pip install huggingface_hub --upgrade |
| | |
| | |
| | if python -c "import huggingface_hub; print('huggingface_hub available')" 2>/dev/null; then |
| | log "Hugging Face Hub installed successfully" |
| | else |
| | error "Hugging Face Hub installation failed" |
| | exit 1 |
| | fi |
| | } |
| |
|
| | |
| | configure_huggingface() { |
| | log "Configuring Hugging Face environment" |
| | |
| | |
| | mkdir -p "$CONFIG_DIR" "$LOG_DIR" "$HF_HOME" |
| | |
| | |
| | echo "export HF_HOME=$HF_HOME" > "$CONFIG_DIR/environment" |
| | echo "export HF_TOKEN=\"\"" >> "$CONFIG_DIR/environment" |
| | |
| | |
| | chmod 755 "$HF_HOME" |
| | chmod 644 "$CONFIG_DIR/environment" |
| | |
| | log "Hugging Face environment configured" |
| | } |
| |
|
| | |
| | setup_authentication() { |
| | log "Setting up Hugging Face authentication" |
| | |
| | if [ -n "$HF_TOKEN" ]; then |
| | log "HF_TOKEN environment variable found" |
| | |
| | if python -c " |
| | from huggingface_hub import HfApi |
| | try: |
| | api = HfApi(token='$HF_TOKEN') |
| | user = api.whoami() |
| | print(f'Authenticated as: {user[\"name\"]}') |
| | except Exception as e: |
| | print(f'Authentication failed: {e}') |
| | exit(1) |
| | " 2>/dev/null; then |
| | log "Hugging Face authentication successful" |
| | else |
| | warning "Hugging Face authentication test failed" |
| | fi |
| | else |
| | warning "HF_TOKEN not set. Please set HF_TOKEN environment variable for full access" |
| | echo "# To authenticate with Hugging Face Hub:" >> "$CONFIG_DIR/README" |
| | echo "# 1. Get your token from https://huggingface.co/settings/tokens" >> "$CONFIG_DIR/README" |
| | echo "# 2. Export it: export HF_TOKEN=your_token_here" >> "$CONFIG_DIR/README" |
| | echo "# 3. Or add to environment file" >> "$CONFIG_DIR/README" |
| | fi |
| | } |
| |
|
| | |
| | install_dependencies() { |
| | log "Installing dependencies" |
| | |
| | |
| | apt-get update || yum update || { |
| | warning "Package manager update failed - continuing anyway" |
| | } |
| | |
| | |
| | if command -v apt-get >/dev/null 2>&1; then |
| | apt-get install -y curl python3-pip |
| | elif command -v yum >/dev/null 2>&1; then |
| | yum install -y curl python3-pip |
| | elif command -v dnf >/dev/null 2>&1; then |
| | dnf install -y curl python3-pip |
| | else |
| | warning "Unknown package manager - please install curl and python3-pip manually" |
| | fi |
| | } |
| |
|
| | |
| | test_integration() { |
| | log "Testing Hugging Face integration" |
| | |
| | |
| | if python -c " |
| | from huggingface_hub import HfApi, HfFolder |
| | print('Hugging Face Hub available') |
| | print('HF_HOME:', HfFolder.path) |
| | " 2>/dev/null; then |
| | log "Hugging Face integration test passed" |
| | else |
| | error "Hugging Face integration test failed" |
| | exit 1 |
| | fi |
| | } |
| |
|
| | |
| | main() { |
| | log "Starting Hugging Face Hub installation for DTO Framework" |
| | |
| | install_dependencies |
| | install_huggingface_hub |
| | configure_huggingface |
| | setup_authentication |
| | test_integration |
| | |
| | log "Hugging Face Hub installation completed successfully!" |
| | log "Next steps:" |
| | log " 1. Set HF_TOKEN environment variable for authentication" |
| | log " 2. Configure repositories in integrations/huggingface_config.yaml" |
| | log " 3. Use integrations/huggingface_client.py for operations" |
| | log " 4. Xet backend is automatically handled by Hugging Face" |
| | } |
| |
|
| | |
| | main "$@" |