-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomfyui_api.py
More file actions
51 lines (37 loc) · 1.5 KB
/
comfyui_api.py
File metadata and controls
51 lines (37 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import os
import requests
import tempfile
import shutil
auto_tex_no_mask_depth_name = "auto_tex_no_mask_depth.png"
auto_tex_mask_albedo_name = "auto_tex_mask_albedo.png"
def queue_prompt(prompt):
response = requests.post("http://127.0.0.1:8188/prompt", json=prompt)
return response
def upload_tex(tex_name, tex_path):
files = [('image', (tex_name, open(tex_path, 'rb'), 'image/png')),]
response = requests.post("http://127.0.0.1:8188/upload/image", data={"overwrite": "1"}, files=files)
return response
def do_rander(auto_tex_no_mask_depth_path=None, auto_tex_mask_albedo_path=None):
prompt_path = os.path.join(os.path.dirname(__file__), "prompt.json")
with open(prompt_path, "r") as f:
prompt = json.load(f)
if auto_tex_no_mask_depth_path != None:
upload_tex(auto_tex_no_mask_depth_name, auto_tex_no_mask_depth_path)
if auto_tex_mask_albedo_path != None:
upload_tex(auto_tex_mask_albedo_name, auto_tex_mask_albedo_path)
# queue_prompt(prompt)
def download_file(url, path):
print("Downloading file from: " + url)
r = requests.get(url, stream=True)
if not r.ok:
print("Get error code: " + str(r.status_code))
print(r.text)
return
with open(os.path.realpath(path), 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
print("File downloaded to: " + path)
if __name__ == "__main__":
# do_rander("/tmp/tmp/no_mask_depth0001.png","/tmp/tmp/mask_albedo0001.png")
...