pollinations.ai Image generator

Created a nice software using SpiderBasic ? Post you link here !
User avatar
Peter
Posts: 1068
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

pollinations.ai Image generator

Post by Peter »

A little gimmick to generate images with pollinations.ai. ;)

(Sometimes the image generation takes a little while. So have a little patience.)

Code: Select all

EnableExplicit

Enumeration
  #Window
  #lblPrompt
  #lblWait
  #txtPrompt
  #cmdExecutePrompt
  #ImageGadget
EndEnumeration

Procedure InProgress(Flag)
  
  DisableGadget(#txtPrompt, Flag)
  DisableGadget(#cmdExecutePrompt, Flag)
  HideGadget(#ImageGadget, Flag)
  HideGadget(#lblWait, Bool(Flag=#False))
  
EndProcedure


Procedure cmdExecutePromptEvent()
  
  If GetGadgetText(#txtPrompt) = "" : ProcedureReturn : EndIf
  
  InProgress(#True)  
  
  LoadImage(0, "https://image.pollinations.ai/prompt/" + URLEncoder(GetGadgetText(#txtPrompt))) ; + "&seed=" + ElapsedMilliseconds()
  
EndProcedure

Procedure Loaded(Type, Filename$, ObjectId)
  SetGadgetState(#ImageGadget, ImageID(ObjectId))
  InProgress(#False)  
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
  DisableGadget(#cmdExecutePrompt, #False)
  InProgress(#False)  
EndProcedure

OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 532, 444, "pollinations.ai Image generator", #PB_Window_ScreenCentered)

TextGadget(#lblPrompt, 10, 10, 50, 30, "Prompt:", #PB_Text_VerticalCenter)
StringGadget(#txtPrompt, 60, 10, 400, 30, "PureBasic Programmer")
ButtonGadget(#cmdExecutePrompt, 470, 10, 55, 30, "Execute")
TextGadget(#lblWait, 0, 0, WindowWidth(#Window), WindowHeight(#Window), "Please wait...", #PB_Text_VerticalCenter | #PB_Text_Center)
ImageGadget(#ImageGadget, 10, 50, 512, 384, 0)

InProgress(#False)  

BindGadgetEvent(#cmdExecutePrompt, @cmdExecutePromptEvent())

BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
Image
Dirk Geppert
Posts: 275
Joined: Fri Sep 22, 2017 7:02 am

Re: pollinations.ai Image generator

Post by Dirk Geppert »

:o :D thx Peter!
Post Reply