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

api callback return raw data #193

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions agent_scheduler/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def api_callback(callback_url: str, task_id: str, status: TaskStatus, images: li
data={"task_id": task_id, "status": status.value},
files=files,
)
def api_callback_raw(callback_url: str, task_id: str, status: TaskStatus, images: list, info: str):

return requests.post(
callback_url,
timeout=50,
json={"task_id": task_id, "status": status.value, "images": images, "info": info},
)


def on_task_finished(
Expand All @@ -67,14 +74,26 @@ def on_task_finished(
# handle api task callback
if not task.api_task_callback:
return

upload = lambda: api_callback(
task.api_task_callback,
task_id=task_id,
status=status,
images=result["images"],
)

if shared.cmd_opts.agent_scheduler_api_raw:
images = [
base64.b64encode(open(image, "rb").read()).decode("utf-8")
for image in result["images"]
if os.path.isfile(image)
]
upload = lambda: api_callback_raw(
task.api_task_callback,
task_id=task_id,
status=status,
images=images,
info=result["geninfo"],
)
else:
upload = lambda: api_callback(
task.api_task_callback,
task_id=task_id,
status=status,
images=result["images"],
)
request_with_retry(upload)


Expand Down Expand Up @@ -471,16 +490,23 @@ def get_task_results(id: str, zip: Optional[bool] = False):
headers={"Content-Disposition": f"attachment; filename=results-{id}.zip"},
)
else:
data = [
{
"image": encode_image_to_base64(Image.open(image)),
"infotext": infotexts[i],
}
for i, image in enumerate(result["images"])
if Path(image).is_file()
]

return {"success": True, "data": data}
if shared.cmd_opts.agent_scheduler_api_raw:
images = [
base64.b64encode(open(image, "rb").read()).decode("utf-8")
for image in result["images"]
if Path(image).is_file()
]
return {"images": images, "info": json.dumps(geninfo)}
else:
data = [
{
"image": encode_image_to_base64(Image.open(image)),
"infotext": infotexts[i],
}
for i, image in enumerate(result["images"])
if Path(image).is_file()
]
return {"success": True, "data": data}

@app.post("/agent-scheduler/v1/pause", dependencies=deps, deprecated=True)
@app.post("/agent-scheduler/v1/queue/pause", dependencies=deps)
Expand Down
8 changes: 7 additions & 1 deletion preload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ def preload(parser):
"--agent-scheduler-sqlite-file",
help="sqlite file to use for the database connection. It can be abs or relative path(from base path) default: task_scheduler.sqlite3",
default="task_scheduler.sqlite3",
)
)
parser.add_argument(
"--agent-scheduler-api-raw",
action='store_true',
help="api return raw sd data"
)