-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhfall.ps1
More file actions
251 lines (218 loc) · 8.01 KB
/
hfall.ps1
File metadata and controls
251 lines (218 loc) · 8.01 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
param(
[Parameter(Mandatory = $true, HelpMessage = "The podcast folder name to process.")]
[string]$PodcastFolder
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"
$CurrentYear = 2026
$RepoId = "All-Shell-Game"
$SuccessColor = "Green"
$WarningColor = "Yellow"
$ErrorColor = "Red"
$InfoColor = "Cyan"
function Write-ColoredOutput
{
param(
[string]$Message,
[string]$Color = "White"
)
Write-Host $Message -ForegroundColor $Color
}
function Invoke-HfCommand
{
param(
[string[]]$Arguments
)
Write-ColoredOutput " -> hf $($Arguments -join ' ')" -Color $InfoColor
$output = & hf @Arguments 2>&1
$exitCode = $LASTEXITCODE
$output | ForEach-Object { Write-Host $_ }
return [PSCustomObject]@{
ExitCode = $exitCode
Output = @($output)
}
}
$CurrentPath = (Get-Location).ProviderPath
$PodcastPath = Join-Path -Path $CurrentPath -ChildPath $PodcastFolder
if (-not (Test-Path -Path $PodcastPath -PathType Container))
{
Write-ColoredOutput "ERROR: Podcast folder '$PodcastFolder' not found at '$PodcastPath'" -Color $ErrorColor
exit 1
}
Write-ColoredOutput "`n========================================" -Color $SuccessColor
Write-ColoredOutput "ALL YEARS HUGGING FACE DATASET SCRIPT" -Color $SuccessColor
Write-ColoredOutput "========================================`n" -Color $SuccessColor
Write-ColoredOutput "Podcast: $PodcastFolder" -Color $InfoColor
Write-ColoredOutput "Location: $PodcastPath" -Color $InfoColor
Write-ColoredOutput "Dataset repo: $RepoId" -Color $InfoColor
Write-ColoredOutput "Current year (will skip): $CurrentYear`n" -Color $InfoColor
Write-ColoredOutput "`nEnsuring dataset repo exists..." -Color $InfoColor
$createResult = Invoke-HfCommand -Arguments @("repo", "create", $RepoId, "--repo-type", "dataset", "--exist-ok")
if ($createResult.ExitCode -ne 0)
{
Write-ColoredOutput "ERROR: Failed to ensure dataset repo '$RepoId' exists." -Color $ErrorColor
exit 1
}
$createOutputText = ($createResult.Output | Out-String)
if ($createOutputText -match '(?i)already exists')
{
Write-ColoredOutput "[SKIP] Dataset repo already exists" -Color $WarningColor
} else
{
Write-ColoredOutput "[OK] Dataset repo created" -Color $SuccessColor
}
$ReadmeTempPath = $null
try
{
$ReadmeContent = @"
---
license: mit
task_categories:
- summarization
language:
- en
tags:
- transcript
- summary
- podcast
- show
pretty_name: All Shell Game Transcripts
---
# All Shell Game Transcripts
Complete transcripts from every episode of the Shell Game podcast from 2024 to present.
Generated from [this GitHub repository](https://github.com/willtheorangeguy/Shell-Game-Transcripts).
"@
$ReadmeTempPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath "$RepoId-README.md"
Set-Content -Path $ReadmeTempPath -Value $ReadmeContent -Encoding UTF8
$readmeUploadResult = Invoke-HfCommand -Arguments @(
"upload",
$RepoId,
$ReadmeTempPath,
"README.md",
"--repo-type",
"dataset",
"--commit-message",
"docs: update README",
"--quiet"
)
if ($readmeUploadResult.ExitCode -ne 0)
{
Write-ColoredOutput "ERROR: Failed to upload README.md" -Color $ErrorColor
exit 1
}
Write-ColoredOutput "[OK] Uploaded README.md" -Color $SuccessColor
} finally
{
if ($ReadmeTempPath -and (Test-Path -Path $ReadmeTempPath -PathType Leaf))
{
Remove-Item -Path $ReadmeTempPath -Force -ErrorAction SilentlyContinue
}
}
Write-ColoredOutput "`nScanning recursively for year folders..." -Color $InfoColor
$YearDirectories = @(Get-ChildItem -Path $PodcastPath -Directory -Recurse | Where-Object {
$_.Name -match '^\d{4}$' -and [int]$_.Name -ne $CurrentYear
} | Sort-Object { [int]$_.Name }, FullName)
if ($YearDirectories.Count -eq 0)
{
Write-ColoredOutput "No year folders found (excluding $CurrentYear)" -Color $WarningColor
Write-ColoredOutput "Exiting." -Color $WarningColor
exit 0
}
Write-ColoredOutput "Found year folders: $($YearDirectories.Name -join ', ')`n" -Color $SuccessColor
$ProcessedYears = 0
$SkippedNoFiles = 0
$ErrorCount = 0
foreach ($YearDirectory in $YearDirectories)
{
$Year = $YearDirectory.Name
$YearPath = $YearDirectory.FullName
$YearHadErrors = $false
$UploadedFileCount = 0
Write-ColoredOutput "`n-------------------------------------------" -Color $InfoColor
Write-ColoredOutput "Processing year: $Year" -Color $InfoColor
Write-ColoredOutput "Source path: $YearPath" -Color $InfoColor
Write-ColoredOutput "Repo folder: $Year/" -Color $InfoColor
Write-ColoredOutput "-------------------------------------------" -Color $InfoColor
$TranscriptFiles = @(Get-ChildItem -Path $YearPath -File -Recurse -Filter "*_transcript.txt" | Sort-Object FullName)
$SummaryFiles = @(Get-ChildItem -Path $YearPath -File -Recurse -Filter "*_summary.txt" | Sort-Object FullName)
if (($TranscriptFiles.Count + $SummaryFiles.Count) -eq 0)
{
Write-ColoredOutput " [SKIP] No *_transcript.txt or *_summary.txt files found" -Color $WarningColor
$SkippedNoFiles++
$ProcessedYears++
continue
}
if ($TranscriptFiles.Count -gt 0)
{
Write-ColoredOutput " Uploading $($TranscriptFiles.Count) transcript files in one commit..." -Color $InfoColor
$transcriptUploadResult = Invoke-HfCommand -Arguments @(
"upload",
$RepoId,
$YearPath,
$Year,
"--repo-type",
"dataset",
"--include",
"*_transcript.txt",
"--commit-message",
"add all $Year transcripts",
"--quiet"
)
if ($transcriptUploadResult.ExitCode -ne 0)
{
Write-ColoredOutput " [ERROR] Failed to upload transcript files" -Color $ErrorColor
$YearHadErrors = $true
} else
{
$UploadedFileCount += $TranscriptFiles.Count
Write-ColoredOutput " [OK] Uploaded transcript files with commit: add all $Year transcripts" -Color $SuccessColor
}
} else
{
Write-ColoredOutput " [SKIP] No *_transcript.txt files found for transcript commit" -Color $WarningColor
}
if (-not $YearHadErrors -and $SummaryFiles.Count -gt 0)
{
Write-ColoredOutput " Uploading $($SummaryFiles.Count) summary files in one commit..." -Color $InfoColor
$summaryUploadResult = Invoke-HfCommand -Arguments @(
"upload",
$RepoId,
$YearPath,
$Year,
"--repo-type",
"dataset",
"--include",
"*_summary.txt",
"--commit-message",
"add all $Year summaries",
"--quiet"
)
if ($summaryUploadResult.ExitCode -ne 0)
{
Write-ColoredOutput " [ERROR] Failed to upload summary files" -Color $ErrorColor
$YearHadErrors = $true
} else
{
$UploadedFileCount += $SummaryFiles.Count
Write-ColoredOutput " [OK] Uploaded summary files with commit: add all $Year summaries" -Color $SuccessColor
}
} elseif (-not $YearHadErrors)
{
Write-ColoredOutput " [SKIP] No *_summary.txt files found for summary commit" -Color $WarningColor
}
if ($YearHadErrors)
{
$ErrorCount++
} else
{
Write-ColoredOutput " [OK] Year $Year complete ($UploadedFileCount files uploaded)" -Color $SuccessColor
$ProcessedYears++
}
}
Write-ColoredOutput "`n========================================" -Color $SuccessColor
Write-ColoredOutput "SUMMARY" -Color $SuccessColor
Write-ColoredOutput "========================================" -Color $SuccessColor
Write-ColoredOutput "Years processed successfully: $ProcessedYears" -Color $SuccessColor
Write-ColoredOutput "Years skipped (no matching files): $SkippedNoFiles" -Color $WarningColor
Write-ColoredOutput "Years with errors: $ErrorCount" -Color $ErrorColor
Write-ColoredOutput "`n[OK] Script completed.`n" -Color $SuccessColor