summaryrefslogtreecommitdiff
path: root/stable_diffusion.cpp
blob: 0c42f03184d9e53a3149d6d75335ab64a736ff67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

static void
SD_Txt2Txt(sd_state *SD)
{
    char JSONPayload[1024];
    char CurlCommand[1024];
    char *Test[] = { "prompt", "negative_prompt", "steps", "width", "height", "cfg_scale" };
    void *Test2[6] = { (void *)SD->Prompt, (void *)SD->NegPrompt,
                       (void *)&SD->Steps, (void *)&SD->Width,
                       (void *)&SD->Height, (void *)&SD->CFG };
    int Type[6] = { 0, 0, 1, 1, 1, 2};
    sprintf(JSONPayload, "%s{\n", JSONPayload);
    for (int i = 0; i < 6; i++) {
        if (Type[i] == 0) {
            sprintf(JSONPayload, "%s\"%s\": \"%s\",\n",   JSONPayload, Test[i], (char *)Test2[i]);
        } else if (Type[i] == 1) {
            sprintf(JSONPayload, "%s\"%s\": %i,\n",   JSONPayload, Test[i], *(int *)Test2[i]);
        } else if (Type[i] == 2) {
            sprintf(JSONPayload, "%s\"%s\": %.2f,\n", JSONPayload, Test[i], *(real32 *)Test2[i]);
        } else {
            Assert(0);
        }
    }
    sprintf(JSONPayload, "%s}\n", JSONPayload);
    sprintf(CurlCommand, "curl -X POST -H 'Content-Type: application/json' -i '%s/sdapi/v1/txt2img' --data '%s'",
            SD->ServerAddress, JSONPayload);
    printf("%s\n", CurlCommand);
};