Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Generate-txt2img {
- Param(
- [Parameter(Mandatory=$true,HelpMessage="Prompt to an image of",Position=0)] $Prompt,
- [Parameter(Mandatory=$false,HelpMessage="Image Width divisible by 32")] [Int]$W,
- [Parameter(Mandatory=$false,HelpMessage="Image Height divisible by 32")] [Int]$H,
- [Parameter(Mandatory=$false,HelpMessage="how closely the AI follows your prompt")] $Scale,
- [Parameter(Mandatory=$false,HelpMessage="specifies how many times to run the sampling loop")] [Int]$Iterations,
- [Parameter(Mandatory=$false,HelpMessage="specifies directory images will be saved to")] [String[]]$outdir,
- [Parameter(Mandatory=$false,HelpMessage="specifies the seed used for results. This allows for reproducible results")] [Int]$seed,
- [Parameter(Mandatory=$false,HelpMessage="specifies the aspect ratio. 1:1 is default. Acceptable values are 3:2, 2:3, 16:9, and 9:16. This will override Width and Height if they were defined")] [String[]]$ar,
- [Parameter(Mandatory=$false,HelpMessage="specifies the number of sampling steps in the Diffusion process. Increasing this number will increase computation time but may improve results.")] [Int]$steps,
- [Parameter(Mandatory=$false,HelpMessage="Use optional parameters not defined here. Things like --plms, --ckpt, --precision, --f, --C, etc")] $opt
- )
- if (!$W) { [int]$W = '512' }
- if (!$H) { [int]$H = '512' }
- if (!$Scale) { $Scale = '7.5' }
- if (!$Iterations) { [int]$Iterations = '4' }
- if (!$outdir) { $outdir = "E:\stable-diffusion-main\outputs\txt2img" } ## Hardcoded path - Please ensure this matches your environment
- if (!$seed) { $seed = Get-Random -Minimum 1 -Maximum 999999 }
- if (!$steps) { $steps = '50' }
- if ($ar -eq '3:2') { [int]$W = '768'; [int]$H = '512' }
- if ($ar -eq '2:3') { [int]$W = '512'; [int]$H = '768' }
- if ($ar -eq '16:9') { [int]$W = '768'; [int]$H = '448' }
- if ($ar -eq '9:16') { [int]$W = '448'; [int]$H = '768' }
- $dir = "E:\stable-diffusion-main" ## Root path for your Stable Diffusion instance - Please ensure this matches your environment
- $currentPath = get-location
- set-location $dir
- if (!((get-module).name -match "Conda")) {
- write-host "Loading Miniconda PowerShell module"
- if (test-path "C:\ProgramData\Miniconda3\shell\condabin\conda-hook.ps1") { & 'C:\ProgramData\Miniconda3\shell\condabin\conda-hook.ps1' }
- else { & "$env:userprofile\Miniconda3\shell\condabin\conda-hook.ps1" }
- conda activate ldm ## Conda instance name - Please ensure this matches your environment
- }
- else { write-host "Conda module already loaded`n`n;)`n`n" }
- $starttime = get-date
- $rundeets = "Prompt: `"$prompt`"`nHeight: $H`nWidth: $W`nSeed: $seed`nIterations $Iterations`nSteps: $steps`nScale: $Scale"
- write-output "Processing text. Images will be saved somewhere here: `"$outdir`"`n$rundeets"
- ## Python script to use can be updated below. This uses the default scripts with the main repo and probably most forks.
- python $dir\scripts\txt2img.py --outdir "$outdir" --prompt "$prompt" --H $H --W $W --seed $seed --n_iter $Iterations --ddim_steps $steps --n_samples 1 --scale $scale --skip_grid $opt
- write-output "Process complete. Recap:`nImages will be saved somewhere here: `"$outdir`"`n$rundeets"
- $newimg = gci "$outdir\samples" | where { $_.creationTime -gt $starttime }
- # if (Get-Process -name EXCEL) { Get-Process -name EXCEL | Stop-Process }
- if (!(Test-path "$outdir\runbook_txt2img.csv")) {
- $logbook = {} | Select "Filename","Prompt","Width","Height","Scale","Iterations","Seed","Steps","FullPath" | Export-Csv "$outdir\runbook_txt2img.csv" -NoTypeInformation
- Get-Content "$outdir\runbook_txt2img.csv" | Where { $_.Replace(",","") -ne "" } | Out-File "$outdir\runbook_txt2img.csv"
- }
- $tempbook = {} | Select "Filename","Prompt","Width","Height","Scale","Iterations","Seed","Steps","FullPath" | Export-Csv "$env:temp\runbook_txt2img.csv" -NoTypeInformation
- $runbook = Import-Csv "$env:temp\runbook_txt2img.csv"
- $newimg | % {
- $runbook.Filename = $_.name
- $runbook.Prompt = $Prompt
- $runbook.Width = $W
- $runbook.Height = $H
- $runbook.Scale = $Scale
- $runbook.Iterations = $Iterations
- $runbook.Seed = $seed
- $runbook.Steps = $steps
- $runbook.FullPath = $_.fullname
- $runbook | export-csv "$outdir\runbook_txt2img.csv" -Append -NoTypeInformation
- $seed++
- }
- set-location $currentPath
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement