Skip to content

Instantly share code, notes, and snippets.

@opparco
Created November 15, 2022 05:22
Show Gist options
  • Save opparco/1937c6797c0b69d1e54352e0a8a0b157 to your computer and use it in GitHub Desktop.
Save opparco/1937c6797c0b69d1e54352e0a8a0b157 to your computer and use it in GitHub Desktop.
gradio api txt2img client sample
import requests
def main():
prompt = "((masterpiece)), ((best quality)), ((illustration)), nsfw, beautiful thicc cute victorian girl, loli face, Feminine, Anders Zorn, ((cleavage of huge breasts)), puffy nipple, :d, blouse, long skirt"
negative_prompt = "[[octane]], [[nsfw]], low hand,low arms,hand,arms,fingers,legs, lower body,thighs, cropped, worst quality, low quality,quality"
sampling_methods = [
"Euler a",
"Euler",
"DPM++ 2M",
"DPM++ 2M Karras",
]
sampling_method = sampling_methods[3]
data = [
prompt, # represents sample input to preprocess. of 'Prompt' Textbox component
negative_prompt, # represents sample input to preprocess. of 'Negative prompt' Textbox component
"None", # represents selected choice of 'Style 1' Dropdown component
"None", # represents selected choice of 'Style 2' Dropdown component
40, # represents null of 'Sampling Steps' Slider component
sampling_method, # represents selected choice of 'Sampling method' Radio component
False, # represents null of 'Restore faces' Checkbox component
False, # represents null of 'Tiling' Checkbox component
4, # represents null of 'Batch count' Slider component
1, # represents null of 'Batch size' Slider component
7.5, # represents null of 'CFG Scale' Slider component
-1, # represents numeric input of 'Seed' Number component
-1, # represents numeric input of 'Variation seed' Number component
0.0, # represents null of 'Variation strength' Slider component
0, # represents null of 'Resize seed from height' Slider component
0, # represents null of 'Resize seed from width' Slider component
False, # represents null of 'Extra' Checkbox component
768, # represents null of 'Height' Slider component
512, # represents null of 'Width' Slider component
False, # represents null of 'Highres. fix' Checkbox component
0.7, # represents null of 'Denoising strength' Slider component
0, # represents null of 'Firstpass width' Slider component
0, # represents null of 'Firstpass height' Slider component
"None", # represents selected choice of 'Script' Dropdown component
0.9, # represents null of 'Aesthetic weight' Slider component
5, # represents null of 'Aesthetic steps' Slider component
"0.0001", # represents sample input to preprocess. of 'Aesthetic learning rate' Textbox component
False, # represents null of 'Slerp interpolation' Checkbox component
"None", # represents selected choice of 'Aesthetic imgs embedding' Dropdown component
"", # represents sample input to preprocess. of 'Aesthetic text for imgs' Textbox component
0.1, # represents null of 'Slerp angle' Slider component
False, # represents null of 'Is negative text' Checkbox component
False, # represents null of 'Put variable parts at start of prompt' Checkbox component
False, # represents null of 'Iterate seed every line' Checkbox component
None, # represents List of JSON objects with filename as 'name' property and base64 data as 'data' property of 'Upload prompt inputs' File component
None, # represents sample input to preprocess. of 'List of prompt inputs' Textbox component
"Seed", # represents selected choice of 'X type' Dropdown component
None, # represents sample input to preprocess. of 'X values' Textbox component
"Nothing", # represents selected choice of 'Y type' Dropdown component
None, # represents sample input to preprocess. of 'Y values' Textbox component
True, # represents null of 'Draw legend' Checkbox component
True, # represents null of 'Include Separate Images' Checkbox component
False, # represents null of 'Keep -1 for seeds' Checkbox component
]
seeds = [
843429515,
]
for seed in seeds:
data[11] = seed
params = {"data": data}
print("start seed={}".format(seed))
r = requests.post(url="http://localhost:7860/api/txt2img", json=params)
if __name__ == "__main__":
main()
# http://localhost:7860/api/txt2img
# {
# "data": [
# List[str], # represents list of string file paths to images in temp directory of 'Output' Gallery component
# str | None, # represents text of the Textbox component
# None, # represents null of the Html component
# ],
# "duration": (float) # number of seconds to run function call
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment