Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: can I start a rendering from the command line? #92

Closed
vicmortelmans opened this issue Sep 23, 2022 · 5 comments
Closed

Question: can I start a rendering from the command line? #92

vicmortelmans opened this issue Sep 23, 2022 · 5 comments
Labels
awaiting-response Waiting for the issuer to respond Stale

Comments

@vicmortelmans
Copy link

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 vicmortelmans added the bug Something isn't working label Sep 23, 2022
@AbdBarho AbdBarho added awaiting-response Waiting for the issuer to respond and removed bug Something isn't working labels Sep 24, 2022
@AbdBarho
Copy link
Owner

@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.

@vicmortelmans
Copy link
Author

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")

@AbdBarho
Copy link
Owner

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 👍

@github-actions
Copy link

github-actions bot commented Oct 9, 2022

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.

@github-actions github-actions bot added the Stale label Oct 9, 2022
@github-actions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response Waiting for the issuer to respond Stale
Projects
None yet
Development

No branches or pull requests

2 participants