forge
Explore
Log in

Don't you dare go Hollow

hezarfen_text_to_podcast

Clone
★ 0

0 watching0 forksPython351.2 KiBbca8bffAhmet Kaan Gümüş2 months ago27 commits

setup-models.ps1121 lines, 4.7 KiBHistoryRawDownload
1[CmdletBinding()]
2param(
3 [string]$Volume = "podcast-models",
4 [string]$VoiceModels = "C:\PROJECTS\podcast\data\ses_modelleri",
5 [string]$HfCache = "$env:USERPROFILE\.cache\huggingface\hub",
6 [string]$HelperImage = "docker.io/library/python:3.10-slim",
7 [switch]$Check,
8 [switch]$Refresh
9)
10$ErrorActionPreference = "Stop"
11
12function Invoke-Quiet {
13 param([Parameter(Mandatory)][string]$Command, [string[]]$Arg = @())
14 $previousEAP = $ErrorActionPreference
15 $ErrorActionPreference = 'Continue'
16 try { & $Command @Arg *> $null } finally { $ErrorActionPreference = $previousEAP }
17 return $LASTEXITCODE
18}
19
20
21function Find-Podman {
22 $c = (Get-Command podman -ErrorAction SilentlyContinue).Source
23 if ($c) { return $c }
24 foreach ($p in @("$env:LOCALAPPDATA\Programs\Podman\podman.exe",
25 "$env:ProgramFiles\RedHat\Podman\podman.exe")) {
26 if (Test-Path $p) { return $p }
27 }
28 throw "podman.exe bulunamadi. winget install RedHat.Podman"
29}
30$PODMAN = Find-Podman
31Write-Host "[model] podman: $PODMAN"
32$previousEAP = $ErrorActionPreference
33$ErrorActionPreference = 'Continue'
34& $PODMAN machine start *> $null
35$ErrorActionPreference = $previousEAP
36
37$writer = "podcast-model-yazici"
38
39function Start-Writer {
40 Invoke-Quiet $PODMAN @('rm','-f',$writer) | Out-Null
41 & $PODMAN run -d --name $writer -v "${Volume}:/models" $HelperImage sleep 7200 | Out-Null
42 if ($LASTEXITCODE -ne 0) { throw "Yazici container baslatilamadi ($HelperImage cekilmemis olabilir: podman pull $HelperImage)" }
43 & $PODMAN exec $writer mkdir -p /models/ses_modelleri /models/hf/hub /models/torch | Out-Null
44}
45function Stop-Writer {
46 Invoke-Quiet $PODMAN @('rm','-f',$writer) | Out-Null
47}
48
49Invoke-Quiet $PODMAN @('volume','create',$Volume) | Out-Null
50
51if ($Check) {
52 Start-Writer
53 try {
54 Write-Host "`n[model] '$Volume' hacminin icerigi:"
55 & $PODMAN exec $writer sh -c "du -sh /models/* /models/ses_modelleri/* /models/hf/hub/* 2>/dev/null | sort -k2"
56 } finally { Stop-Writer }
57 return
58}
59
60$jobs = @(
61 @{ name = "supertonic-3";
62 source = (Join-Path $VoiceModels "supertonic-3");
63 target = "/models/ses_modelleri";
64 probe = "/models/ses_modelleri/supertonic-3/onnx/vocoder.onnx";
65 download = "python -c ""from huggingface_hub import snapshot_download; snapshot_download('Supertone/supertonic-3', local_dir='data/ses_modelleri/supertonic-3')""" },
66 @{ name = "faster_whisper (medium)";
67 source = (Join-Path $VoiceModels "faster_whisper");
68 target = "/models/ses_modelleri";
69 probe = "/models/ses_modelleri/faster_whisper/models--Systran--faster-whisper-medium";
70 download = "python -c ""from faster_whisper import WhisperModel; WhisperModel('medium', device='cpu', compute_type='int8', download_root='data/ses_modelleri/faster_whisper')""" },
71 @{ name = "multilingual-e5-large";
72 source = (Join-Path $HfCache "models--intfloat--multilingual-e5-large");
73 target = "/models/hf/hub";
74 probe = "/models/hf/hub/models--intfloat--multilingual-e5-large";
75 download = "python -c ""from huggingface_hub import snapshot_download; snapshot_download('intfloat/multilingual-e5-large')""" }
76)
77
78Start-Writer
79$missing = @()
80try {
81 foreach ($job in $jobs) {
82 $name = $job.name
83 $null = Invoke-Quiet $PODMAN @('exec',$writer,'test','-e',$job.probe)
84 $exists = ($LASTEXITCODE -eq 0)
85 if ($exists -and -not $Refresh) {
86 Write-Host "[model] $name -> hacimde ZATEN VAR, atlandi (-Refresh ile ez)"
87 continue
88 }
89 if (-not (Test-Path -LiteralPath $job.source)) {
90 Write-Host "[model] $name -> YEREL KOPYA YOK: $($job.source)"
91 $missing += $job
92 continue
93 }
94 $mb = ((Get-ChildItem -LiteralPath $job.source -Recurse -Force -File |
95 Measure-Object -Property Length -Sum).Sum) / 1MB
96 Write-Host ("[model] $name -> kopyalaniyor ({0:N0} MB, WSL uzerinden dakikalar surebilir)..." -f $mb)
97 & $PODMAN cp $job.source "${writer}:$($job.target)"
98 if ($LASTEXITCODE -ne 0) { throw "podman cp basarisiz: $name" }
99 }
100
101 Write-Host "[model] izinler aciliyor (a+rX)..."
102 & $PODMAN exec $writer sh -c "chmod -R a+rX /models" | Out-Null
103
104 Write-Host "`n[model] hacim icerigi:"
105 & $PODMAN exec $writer sh -c "du -sh /models/ses_modelleri/* /models/hf/hub/* 2>/dev/null"
106} finally {
107 Stop-Writer
108}
109
110if ($missing.Count -gt 0) {
111 Write-Host "`n[model] !!! EKSIK AGIRLIKLAR - betik BILEREK indirmedi (4 GB'a operator karar verir):"
112 foreach ($job in $missing) {
113 Write-Host "`n * $($job.name)"
114 Write-Host " beklenen yerel yol : $($job.source)"
115 Write-Host " indirme komutu : cd C:\PROJECTS\podcast ; $($job.download)"
116 }
117 Write-Host "`n Indirdikten sonra bu betigi TEKRAR calistir."
118 exit 1
119}
120
121Write-Host "`n[model] TAMAM. Siradaki: pwsh -File deploy/run-stack.ps1"