|
|
|
|
| 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.'
|
|
|