diff --git a/js/AvatarPreview.js b/js/AvatarPreview.js index 911bf33..3b5b628 100644 --- a/js/AvatarPreview.js +++ b/js/AvatarPreview.js @@ -43,6 +43,31 @@ async function uploadImage() { const jsonWorkflowLoading = van.state(true); +async function prepareImageFromUrlRedirect(stage) { + await new Promise(resolve => setTimeout(resolve, 2000)); + const queue_id = new URLSearchParams(window.location.search).get('queue-id') + if ( + queue_id && queue_id != "" + ) { + console.log(queue_id); + stage.val = 1 + const graph = app.graph; + const node = graph.findNodesByType("LoadImage"); + const imageName = "create_avatar_endpoint_" + queue_id + ".png" + console.log(node[0]); + node[0].widgets_values[0] = imageName + node[0].widgets[0].value = imageName + node[0].widgets[0]._value = imageName + graph.change() + previewImg.val = api.apiURL( + `/view?filename=${encodeURIComponent( + imageName + )}&type=input&subfolder=${""}${app.getPreviewFormatParam()}` + ); + console.log(previewImg); + } +} + export function AvatarPreview() { console.log("getting workflow json now"); loadJSONWorkflow().then(() => { @@ -64,6 +89,9 @@ export function AvatarPreview() { const email = van.state(""); const stage = van.state(0); // 0: upload image, 1: edit segment, 2: generate + // This will wait 2 seconds until the everything is loaded + prepareImageFromUrlRedirect(stage) + const renderSteps = () => { return div( { diff --git a/routes.py b/routes.py index 496414f..b8cd78d 100644 --- a/routes.py +++ b/routes.py @@ -152,4 +152,27 @@ async def post_input_file(request): with open(filename, "wb") as f: f.write(post) - return web.json_response({}) \ No newline at end of file + return web.json_response({}) + +import uuid + +@server.PromptServer.instance.routes.post("/create_avatar_from_image") +async def post_input_file(request): + post = await request.read() + + # Doesn't seems working when file isnt png / or nothing is uploaded + if not post: + raise web.HTTPBadRequest(reason="No image data received") + + queue_id = uuid.uuid4() + + output_dir = os.path.join(folder_paths.base_path, "input") + os.makedirs(output_dir, exist_ok=True) + + filename = os.path.join(output_dir, "create_avatar_endpoint_" + str(queue_id) + ".png") + with open(filename, "wb") as f: + f.write(post) + + return web.json_response({ + "redirect_url": "https://ai-assistant.avatech.ai?queue-id=" + str(queue_id) + }) \ No newline at end of file