File size: 2,142 Bytes
52c0a32 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/env pwsh
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ScriptDir
if (Test-Path .env) {
Get-Content .env | ForEach-Object {
$line = $_.Trim()
if ($line -eq '' -or $line.StartsWith('#')) { return }
$parts = $line.Split('=', 2)
if ($parts.Count -ne 2) { return }
$name = $parts[0].Trim()
$value = $parts[1].Trim()
if ($value.StartsWith('"') -and $value.EndsWith('"')) {
$value = $value.Substring(1, $value.Length - 2)
} elseif ($value.StartsWith("'") -and $value.EndsWith("'")) {
$value = $value.Substring(1, $value.Length - 2)
}
if ($name -match '^[A-Za-z_][A-Za-z0-9_]*$') {
[Environment]::SetEnvironmentVariable($name, $value, 'Process')
}
}
}
$BucketUri = if ($env:HF_BUCKET_URI) { $env:HF_BUCKET_URI } else { 'hf://buckets/lukhsaankumar/DeepFakeDetectorBackend-storage' }
$LocalDir = if ($args.Count -gt 0 -and $args[0]) { $args[0] } elseif ($env:HF_BUCKET_LOCAL_DIR) { $env:HF_BUCKET_LOCAL_DIR } else { './data' }
$DeleteFlag = if ($env:HF_BUCKET_DELETE) { $env:HF_BUCKET_DELETE } else { 'false' }
if (-not (Get-Command hf -ErrorAction SilentlyContinue)) {
Write-Error 'Hugging Face CLI (hf) is not installed. Install guide: https://hf.co/docs/huggingface_hub/guides/cli'
}
try {
hf auth whoami | Out-Null
} catch {
Write-Error 'Hugging Face CLI is not authenticated. Run: hf auth login'
}
if (-not (Test-Path $LocalDir -PathType Container)) {
Write-Error "Local directory does not exist: $LocalDir"
}
Write-Host 'Syncing local directory to HF bucket'
Write-Host " Local : $LocalDir"
Write-Host " Bucket: $BucketUri"
if ($DeleteFlag -eq 'true') {
Write-Host ' Mode : mirror (delete remote files not present locally)'
hf sync $LocalDir $BucketUri --delete
} else {
Write-Host ' Mode : additive (no remote deletes)'
hf sync $LocalDir $BucketUri
}
Write-Host 'Bucket sync completed successfully.'
|