Others HTML How to add stable diffusion local api calls to Twine 2 Harlowe 3?

Throwongawayyyy

New Member
Jun 7, 2024
1
0
I've seen some people do it, like the free cities mod. How do they do it? I presume they use javascript or something? I'm not really sure how to do this, I'm pretty good at Twine but not any other coding language, though I could probably learn it eventually. I have stable diffusion set up locally - and i add the --api in the console so it can receive requests. Then what? Chatgpt doesn't seem to help, unsurprisingly. Anyone tried this before? This is a really good idea, as I want to make a sandbox life-sim with random characters - random parameters like age, body type, hair and eye colors, etc. And for each image I just put the prompt in and replace the variables and boom, infinite characters.
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,787
5,195
Depending on exactly what local StableDiffusion package you are running, there will probably be a configurable REST API that can be enabled. This is how, for example, how the integration of image generation into Oobabooga or Silly Tavern is done.

For the Automatic1111 StabDiff implementation the docs for the API are here:

To send requests to that API from your Twine game code, you'll need a javascript API client package (actually, you could write one yourself using pure javascript, but ain't noone got time for dat).

Here's a NPM package that implements such a client: Stable-canvas/sd-webui-a1111-client

You'll obviously need to have at least some Javascript dev knowledge to put all this together - or at least be ready to spend the time to learn. For example, the api docs page (first link above) has an example of using the API from python code - you could adapt that to Javascript as a starting point.

disclaimer: i haven't tried doing any of this stuff myself, just know what to google due to $dayjob experience.