Giter Site home page Giter Site logo

Comments (5)

vicmortelmans avatar vicmortelmans commented on May 14, 2024 1

Hi, thanks!!

I got the API working, mainly by inspecting the calls made by the web GUI.

There are two fields in the posted data that I don't know what they're for and that seem to be mandatory:

  • fn_index: when inspecting, it was set to 10. I tried other values of 0 or 1, but then there's an error. It works with 10, but what's the purpose of this field?
  • session_hash: I can guess that this is used by the GUI to identify when making subsequent calls to the server. It works with a fixed string (that I copied when inspecting the GUI). I suppose it would be better if I'd generate my own hashes, but how are they built?

The data array contains all the settings that are available in the GUI. So far I copied the defaults (again: upon inspection) and only tried modifying the text and the size fields.

Here's code that works for me:

#!/bin/sh
curl --header "Content-Type: application/json" \
     --request POST \
     --data '{"fn_index":10,"data": ["<text goes here>","","None","None",20,"Euler a",false,false,1,1,7,-1,-1,0,0,0,false,512,512,false,false,0.7,"None",false,false,null,"","Seed","","Steps","",true,null,"",""],"session_hash":"ejz5r41u2pi2"}' \
        http://localhost:7860/api/predict/

And in Python:

#!/usr/bin/python3
import requests
from requests.structures import CaseInsensitiveDict
import json
from base64 import urlsafe_b64decode

url = "http://localhost:7860/api/predict/"

headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json"

text = "<text goes here>"
size = 512

data_json = {"fn_index":10,"data": [text,"","None","None",20,"Euler a",False,False,1,1,7,-1,-1,0,0,0,False,size,size,False,False,0.7,"None",False,False,None,"","Seed","","Steps","",True,None,"",""],"session_hash":"ejz5r41u2pi"}
data = json.dumps(data_json)

resp = requests.post(url, headers=headers, data=data)

if resp.status_code == 200:
    with open("predict.png","wb") as f:
        b64string = resp.json()["data"][0][0].split(',')[1]
        f.write(urlsafe_b64decode(b64string))
    print("Image saved to file")
else:
    print(json.dumps(resp.json()))
    print("Status code: " + str(resp.status_code))
    print("Nothing saved to file")

from stable-diffusion-webui-docker.

AbdBarho avatar AbdBarho commented on May 14, 2024

@vicmortelmans when you open the ui, there is a button at the bottom to view the api, you can then curl against it with the prompts / parameters, and get the result from the output folder. I haven't tried it personally, but it should work, in theory at least.

from stable-diffusion-webui-docker.

AbdBarho avatar AbdBarho commented on May 14, 2024

Glad it worked! the questions you have rely on the internals of gradio and the UI itself, which is unfortunately out of scope of this repo (here are the containers only).

You can definitely try asking your questions in the main repo:
https://github.com/AUTOMATIC1111/stable-diffusion-webui

The community there is much larger and you would probably find the answers you are looking for 👍

from stable-diffusion-webui-docker.

github-actions avatar github-actions commented on May 14, 2024

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

from stable-diffusion-webui-docker.

github-actions avatar github-actions commented on May 14, 2024

This issue was closed because it has been stalled for 7 days with no activity.

from stable-diffusion-webui-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.