Comments (5)
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.
@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.
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.
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.
This issue was closed because it has been stalled for 7 days with no activity.
from stable-diffusion-webui-docker.
Related Issues (20)
- download-1 | exec /docker/download.sh: exec format error HOT 25
- Could not connect to server while getting `aria2` and `parallel` HOT 1
- Efficiency nodes import failed with ComfyUI HOT 7
- Device cuda:0 does not support the torch.fft functions used in the FreeU node, switching to CPU HOT 4
- Attempt to run today with failure HOT 3
- httpcore and httpx 0.24.1 needed to run latest version. HOT 5
- Failed to build invoke ui - get "ImportError" on "ModelSearchArguments" HOT 2
- Adding Fooocus support
- After starting the environment, it will stop running immediately. HOT 3
- Error with auto and invoke: libnvidia-ml.so.1 (apparently missing) HOT 4
- Cannot start Container on Synology DS224+ (DSM7.2 + Container Manager) HOT 1
- Save Image - no file dialog to save image HOT 1
- Permission denied (13) error HOT 1
- it cant start auto image and stuck at " removing nvidia-cudnn-cu11" HOT 2
- Windows 10: pytorch error on build HOT 7
- rsync: chown "/data/models/VAE-approx/.model.pt.pA3bXk" failed: Operation not permitted (1) HOT 1
- OSError: Can't load tokenizer for 'openai/clip-vit-large-patch14'. HOT 6
- Taking up 16 GB of Ram on startup - automatically renders maybe? HOT 5
- Undefined Symbol Error HOT 3
- can not download stablediffusion.git HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stable-diffusion-webui-docker.