stable-diffusion-webui-docker
stable-diffusion-webui-docker copied to clipboard
Question: can I start a rendering from the command line?
Hi,
I've been trying a number of stable-diffusion installation methods that should work without GPU, but this one is the only one that I got working (out of the box!) without any breaking issue.
That's very good, but problem is that I was actually looking for an installation that would allow renderings to be run from the command line (scripted)...
So my question (which is definitely not a bug, as the repo says it's about offering a GUI): is it still possible somehow to render images without using the GUI?
Best regards, Vic
@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.
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")
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 👍
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.
This issue was closed because it has been stalled for 7 days with no activity.