Skip to content

Instantly share code, notes, and snippets.

@BananaAcid
Last active January 24, 2026 20:55
Show Gist options
  • Select an option

  • Save BananaAcid/c73539e160238f1d6cfb2d6cbe4c9e41 to your computer and use it in GitHub Desktop.

Select an option

Save BananaAcid/c73539e160238f1d6cfb2d6cbe4c9e41 to your computer and use it in GitHub Desktop.
Powershell - Pode Server + PollinationsAI-Text

Powershell - Pode Server + PollinationsAI-Image

  1. save all of the files from this repo to your test folder
  2. use install.ps1 to setup the basics
  3. edit server.ps1 and add your PollinationsAI key (if no env is set already)
  4. start server.ps1
  5. open http://localhost:8080

Note

After your terminal session was closed, you need to use Import-Module ".\Modules\Pode\<version>\Pode.psd1" before starting ./server.ps1

Function Get-PodeVersion {
(Get-Module -Name Pode | select -Last 1 | select -ExpandProperty Version).Version.ToString()
}
Function Get-PodeVersionFromModulesPath {
# get latest version folder name from .\Modules\Pode\*
Get-ChildItem ".\Modules\Pode" | select -Last 1 | select -ExpandProperty Name
}
# Create a folder for the module
if (-not (Test-Path ".\Modules")) {
New-Item -ItemType Directory -Path ".\Modules"
}
# create PollinationsAI module and force to create subfolders
@'
Function PollinationsAI-Img { $p = $PSScriptRoot; if ($args -contains "-?") { $x = & $p\ask.pollinations_image.ps1 -?; $x -replace "ask.pollinations_image.ps1", "PollinationsAI-Img"} else { & $p\ask.pollinations_image.ps1 @args } }
Function PollinationsAI-Text { $p = $PSScriptRoot; if ($args -contains "-?") { $x = & $p\ask.pollinations_text.ps1 -?; $x -replace "ask.pollinations_text.ps1", "PollinationsAI-Text"} else { & $p\ask.pollinations_text.ps1 @args } }
# $env:POLLINATIONSAI_API_KEY = "sk_..."
'@ | Out-File .\Modules\PollinationsAI\init.ps1 -Force
# download PollinationsAI scripts
Invoke-WebRequest 'https://gist.githubusercontent.com/BananaAcid/6bc2fc33d948d28d255674a7613f120c/raw/ask.pollinations_image.ps1' -out .\Modules\PollinationsAI\ask.pollinations_image.ps1;
Invoke-WebRequest 'https://gist.githubusercontent.com/BananaAcid/331cc3c073564f2cb5a831e04aef35e5/raw/ask.pollinations_text.ps1' -out .\Modules\PollinationsAI\ask.pollinations_text.ps1;
# create Public and Cache folder
if (-not (Test-Path ".\Public\Cache")) {
New-Item -ItemType Directory -Path ".\Public\Cache" -Force
}
@'
body {
background-color: black;
color: #ddd;
font-family: Helvetica, Arial, sans-serif;
}
a {
color: rgb(105, 169, 253);
}
'@ | Out-File .\Public\styles\main.css -Force
if (-not (Get-PodeVersionFromModulesPath)) {
# Download the module to that folder
Save-Module -Name Pode -Path ".\Modules"
}
$version = Get-PodeVersionFromModulesPath
# Import it from that specific path when you need it
Import-Module ".\Modules\Pode\$version\Pode.psd1"
{
"author": "BananaAcid",
"name": "pode-ai-server",
"license": "MIT",
"version": "1.0.0",
"description": "",
"repository": {
"url": "https://gist.github.com/BananaAcid/c73539e160238f1d6cfb2d6cbe4c9e41"
},
"scripts": {
"start": "./server.ps1",
"test": "invoke-pester ./tests/*.ps1",
"build": "psake",
"install": "yarn install --force --ignore-scripts --modules-folder pode_modules"
},
"main": "./server.ps1"
}
# $env:POLLINATIONSAI_API_KEY = "sk_..."
Start-PodeServer {
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging -Levels Error, Warning, Informational
New-PodeLoggingMethod -Terminal | Enable-PodeRequestLogging
Add-PodeEndpoint -Address localhost -Port 8080 -Protocol Http
# set the engine to use and render Pode files
Set-PodeViewEngine -Type Pode
# import the PollinationsAI module into isolated scopes (this will make them available to all routes)
Import-PodeModule -Path .\Modules\PollinationsAI\init.ps1
# Fun ... open this as a new window in windows
#Show-PodeGui -Title 'Pode Desktop Application' -ResizeMode 'NoResize'
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
$query = $WebEvent.Query['query']
Write-PodeViewResponse -Path 'index' -Data @{
'query' = $query
}
}
Add-PodeRoute -Method Get -Path '/ping' -ScriptBlock {
Write-PodeJsonResponse -Value @{ value = 'pong' }
}
# #! shows full path to folder in output !! Files do not open and 404
# Add-PodeRoute -Method Get -Path '/files' -ScriptBlock {
# Write-PodeDirectoryResponse -Path .\public\cache
# }
#* Better use this.
Add-PodeStaticRoute -Path '/files' -Source .\public\cache -FileBrowser
Add-PodeRoute -Method Get -Path '/create' -ScriptBlock {
$prompt = $WebEvent.Query['prompt'] ?? "a very cute cat"
$pathAbs = PollinationsAI-Img "$prompt" -bypass -out (".\public\cache\" + (Get-Date).Ticks + (Get-Random))
$path = (Resolve-Path -Path $pathAbs -Relative -RelativeBasePath ($PSScriptRoot + "\public\")) -replace '\\', '/'
Write-PodeHtmlResponse "<style>body{place-content:center;justify-self:center;}</style> <div><h1>`"$prompt`"</h1><img src=`"$path`" /></div>"
}
Add-PodeRoute -Method Get -Path '/img' -ScriptBlock {
$details = PollinationsAI-Img "a very cute cat" -bypass -out (".\public\cache\" + (Get-Date).Ticks + (Get-Random)) -Details
# save headers and info
$details | select -ExcludeProperty Content | ConvertTo-Json | Out-File -FilePath ($details.FilePath + ".details.json")
#! 404 !!! --> THIS DOES NOT WORK: File in -Path not found ... so what is -Data for ?
#Write-PodeFileResponse -Data $details.Content -Path ($details.FilePath | Split-Path -Leaf) -ContentType "image/jpg" #-ContentType $details.Headers.'Content-Type'[0]
Add-PodeHeader -Name "Content-Disposition" -Value "inline; filename=`"$($details.FilePath | Split-Path -Leaf)`""
Write-PodeTextResponse -Bytes $details.Content -ContentType $details.Headers.'Content-Type'[0]
}
}
@{
Web = @{
ErrorPages = @{
ShowExceptions = $true
}
}
}
<html>
<head>
<title>Home Page</title>
<link rel="stylesheet" type="text/css" href="/styles/main.css">
</head>
<body>
<h1>Hello, world!</h1>
<p><a href="/files">/files</a></p>
<br>
<p><a href="/create">/create</a></p>
<p><a href="/create?prompt=a darth vader style cat">/create?prompt=a darth vader style cat</a></p>
<p><a href="/img">/img</a> (directly output the image)</p>
<p><a href="/img" download>/img</a> (directly download the image)</p>
<span>$([DateTime]::Now.ToString('yyyy-MM-dd HH:mm:ss');)</span>
<div>
Query: $($data.query;)
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment