luicl commited on
Commit
a98dbeb
·
verified ·
1 Parent(s): 9f36f0e

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Version1.0.1 +0 -0
  2. Test/123 → Version1.0.1.md +0 -0
  3. hf-upload.ps1 +48 -0
Version1.0.1 DELETED
File without changes
Test/123 → Version1.0.1.md RENAMED
File without changes
hf-upload.ps1 ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ param(
2
+ [string]$RepoId,
3
+ [string]$LocalPath = ".",
4
+ [ValidateSet("dataset", "model", "space")]
5
+ [string]$RepoType,
6
+ [switch]$DryRun
7
+ )
8
+
9
+ if ([string]::IsNullOrWhiteSpace($RepoId)) {
10
+ Write-Error "RepoId is required. Usage: .\hf-upload.ps1 <repo_id> [local_path] -RepoType <dataset|model|space> [-DryRun]"
11
+ exit 1
12
+ }
13
+
14
+ if ([string]::IsNullOrWhiteSpace($RepoType)) {
15
+ Write-Error "RepoType is required. Pass -RepoType dataset, -RepoType model, or -RepoType space explicitly."
16
+ exit 1
17
+ }
18
+
19
+ $gitignorePath = Join-Path $LocalPath ".gitignore"
20
+
21
+ if (-not (Test-Path $gitignorePath)) {
22
+ Write-Error ".gitignore not found at $gitignorePath"
23
+ exit 1
24
+ }
25
+
26
+ $patterns = Get-Content $gitignorePath |
27
+ Where-Object { $_ -notmatch '^\s*#' } |
28
+ Where-Object { $_ -notmatch '^\s*$' } |
29
+ ForEach-Object { $_.Trim() } |
30
+ Where-Object { -not $_.StartsWith('!') } |
31
+ ForEach-Object { if ($_.EndsWith('/')) { $_ + '**' } else { $_ } } |
32
+ ForEach-Object { $_.TrimStart('/') }
33
+ # hf upload 的 --exclude 是用 fnmatch 比對「相對路徑」(不含開頭斜線)。
34
+ # .gitignore 的根目錄錨定語法(leading "/", 例如 "/Binaries/") 若原封不動
35
+ # 轉成 --exclude="/Binaries/**",會因為實際路徑沒有開頭斜線而永遠比對不到,
36
+ # 導致規則形同虛設。這裡統一移除開頭斜線;因為 fnmatch 本來就是整串比對,
37
+ # 去掉斜線後的 "Binaries/**" 本身已經等同「只比對根目錄開頭」,效果不變。
38
+
39
+ $ignoreArgs = $patterns | ForEach-Object { "--exclude=`"$_`"" }
40
+
41
+ $cmd = "hf upload $RepoId $LocalPath --repo-type=$RepoType --delete=`"*`" " + ($ignoreArgs -join " ")
42
+
43
+ if ($DryRun) {
44
+ Write-Host "[dry-run] $cmd"
45
+ } else {
46
+ Write-Host "Running: $cmd"
47
+ Invoke-Expression $cmd
48
+ }