first commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string] $Prompt,
|
||||
[string] $Out = "outputs\imagegen.png",
|
||||
[string] $Size = "1024x1024",
|
||||
[ValidateSet("low", "medium", "high", "auto")][string] $Quality = "low",
|
||||
[string] $Model = "gpt-image-2",
|
||||
[string] $BaseUrl = "",
|
||||
[switch] $Force
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$pythonSelector = Join-Path $scriptDir "runtime.py"
|
||||
$generator = Join-Path $scriptDir "generate_image.py"
|
||||
function Get-ImageGenPython {
|
||||
if ($env:CODEX_IMAGEGEN_PYTHON) {
|
||||
$command = Get-Command $env:CODEX_IMAGEGEN_PYTHON -ErrorAction SilentlyContinue
|
||||
if ($command) { return $command.Source }
|
||||
}
|
||||
$embedded = Join-Path $env:USERPROFILE ".cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe"
|
||||
if (Test-Path -LiteralPath $embedded) { return $embedded }
|
||||
$command = Get-Command python.exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if ($command) { return $command.Source }
|
||||
$command = Get-Command py.exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if ($command) { return $command.Source }
|
||||
throw "Python 3 not found; install Python or set CODEX_IMAGEGEN_PYTHON."
|
||||
}
|
||||
|
||||
$python = Get-ImageGenPython
|
||||
$runtime = & $python $pythonSelector
|
||||
if ($LASTEXITCODE -ne 0 -or -not $runtime) { throw "Could not bootstrap Python runtime." }
|
||||
$args = @($generator, "--model", $Model, "--prompt", $Prompt, "--size", $Size, "--quality", $Quality, "--out", $Out)
|
||||
if ($BaseUrl) { $args += @("--base-url", $BaseUrl) }
|
||||
if ($Force) { $args += "--force" }
|
||||
& $runtime @args
|
||||
if ($LASTEXITCODE -ne 0) { throw "Image generation failed with exit code $LASTEXITCODE." }
|
||||
Reference in New Issue
Block a user