Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
8c692c91
Commit
8c692c91
authored
Feb 22, 2023
by
comfyanonymous
Browse files
Add a basic example for how to use the ComfyUI api.
parent
2976c1ad
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
0 deletions
+118
-0
script_examples/basic_api_example.py
script_examples/basic_api_example.py
+118
-0
No files found.
script_examples/basic_api_example.py
0 → 100644
View file @
8c692c91
import
json
from
urllib
import
request
,
parse
import
random
#this is the ComfyUI api prompt format. If you want it for a specific workflow you can copy it from the prompt section
#of the image metadata of images generated with ComfyUI
#keep in mind ComfyUI is pre alpha software so this format will change a bit.
#this is the one for the default workflow
prompt_text
=
"""
{
"3": {
"class_type": "KSampler",
"inputs": {
"cfg": 8,
"denoise": 1,
"latent_image": [
"5",
0
],
"model": [
"4",
0
],
"negative": [
"7",
0
],
"positive": [
"6",
0
],
"Random seed after every gen": true,
"sampler_name": "sample_euler",
"scheduler": "normal",
"seed": 8566257,
"steps": 20
}
},
"4": {
"class_type": "CheckpointLoader",
"inputs": {
"ckpt_name": "v1-5-pruned-emaonly.ckpt",
"config_name": "v1-inference.yaml"
}
},
"5": {
"class_type": "EmptyLatentImage",
"inputs": {
"batch_size": 1,
"height": 512,
"width": 512
}
},
"6": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "masterpiece best quality girl"
}
},
"7": {
"class_type": "CLIPTextEncode",
"inputs": {
"clip": [
"4",
1
],
"text": "bad hands"
}
},
"8": {
"class_type": "VAEDecode",
"inputs": {
"samples": [
"3",
0
],
"vae": [
"4",
2
]
}
},
"9": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
}
}
}
"""
def
queue_prompt
(
prompt
):
p
=
{
"prompt"
:
prompt
}
data
=
json
.
dumps
(
p
).
encode
(
'utf-8'
)
req
=
request
.
Request
(
"http://127.0.0.1:8188/prompt"
,
data
=
data
)
request
.
urlopen
(
req
)
prompt
=
json
.
loads
(
prompt_text
)
#set the text prompt for our positive CLIPTextEncode
prompt
[
"6"
][
"inputs"
][
"text"
]
=
"masterpiece best quality man"
#set the seed for our KSampler node
prompt
[
"3"
][
"inputs"
][
"seed"
]
=
5
queue_prompt
(
prompt
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment