From 1e8187530e2f3fe3c1e20576a76ecef2e656834a Mon Sep 17 00:00:00 2001 From: Edwin Wong Date: Tue, 14 Nov 2023 19:35:40 -0500 Subject: [PATCH] fix folder and path --- js/AvatarPreview.js | 35 +++++++++++++++++++++++++++++------ routes.py | 29 ++++++++++++++++++----------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/js/AvatarPreview.js b/js/AvatarPreview.js index 3b5b628..fbdabcc 100644 --- a/js/AvatarPreview.js +++ b/js/AvatarPreview.js @@ -53,7 +53,7 @@ async function prepareImageFromUrlRedirect(stage) { stage.val = 1 const graph = app.graph; const node = graph.findNodesByType("LoadImage"); - const imageName = "create_avatar_endpoint_" + queue_id + ".png" + const imageName = queue_id + ".png" console.log(node[0]); node[0].widgets_values[0] = imageName node[0].widgets[0].value = imageName @@ -62,7 +62,7 @@ async function prepareImageFromUrlRedirect(stage) { previewImg.val = api.apiURL( `/view?filename=${encodeURIComponent( imageName - )}&type=input&subfolder=${""}${app.getPreviewFormatParam()}` + )}&type=input&subfolder=create_avatar_endpoint${app.getPreviewFormatParam()}` ); console.log(previewImg); } @@ -218,6 +218,9 @@ export function AvatarPreview() { const imageNodes = graph.findNodesByType("LoadImage"); if (!imageNodes[0].imgs) return; document.getElementById("queue-button").click(); + console.log("scrolling???"); + window.scrollTo({ top: 0, behavior: "smooth" }); + console.log("hi???"); }, }, div({ class: "badge badge-neutral" }, "3"), @@ -309,7 +312,7 @@ export function AvatarPreview() { return button( { class: () => - "btn flex flex-row btn-ghost text-black normal-case px-4 rounded-md left-0 top-0 z-[200] w-fit pointer-events-auto ", + "btn flex flex-row btn-ghost text-black normal-case rounded-md left-0 top-0 z-[200] pointer-events-auto sm:btn-md btn-sm ", onclick: () => { showPreview.val = false; }, @@ -322,11 +325,28 @@ export function AvatarPreview() { ); }; + const renderRestartButton = () => { + return button( + { + class: () => + "btn flex flex-row btn-ghost text-black normal-case rounded-md left-0 top-0 z-[200] pointer-events-auto sm:btn-md btn-sm ", + onclick: () => { + fetch("https://7a49f4ad27be4dcf.ngrok.app/restart"); + }, + }, + span({ + class: "iconify text-lg", + "data-icon": "mdi:restart", + "data-inline": "false", + }) + ); + }; + const renderChangeWorkflowButton = () => { return button( { class: () => - "btn text-black flex flex-row btn-ghost normal-case px-4 rounded-md left-0 top-0 z-[200] w-fit pointer-events-auto ", + "btn text-black flex flex-row btn-ghost normal-case rounded-md left-0 top-0 z-[200] pointer-events-auto sm:btn-md btn-sm ", onclick: () => { let input = document.createElement("input"); input.type = "file"; @@ -347,7 +367,9 @@ export function AvatarPreview() { "data-icon": "ic:round-swap-vert", "data-inline": "false", }), - () => (jsonWorkflowLoading.val ? "Loading" : "Change workflow") + span({ class: "sm:flex hidden" }, () => + jsonWorkflowLoading.val ? "Loading" : "Change workflow" + ) ); }; @@ -355,7 +377,7 @@ export function AvatarPreview() { return button( { class: () => - "absolute top-4 right-4 btn text-black btn-ghost w-24 text-xs !px-0 normal-case", + "absolute top-4 right-4 btn sm:w-10 w-32 text-black btn-ghost text-xs !px-0 normal-case sm:btn-md btn-sm", onclick: () => window.open("https://twitter.com/avatech_gg", "_blank"), }, "Twitter" @@ -384,6 +406,7 @@ export function AvatarPreview() { class: "absolute top-4 left-4 flex flex-row gap-2", }, renderCloseButton(), + renderRestartButton(), renderChangeWorkflowButton() ), renderTwitter(), diff --git a/routes.py b/routes.py index b8cd78d..52d3e7d 100644 --- a/routes.py +++ b/routes.py @@ -164,15 +164,22 @@ async def post_input_file(request): if not post: raise web.HTTPBadRequest(reason="No image data received") - queue_id = uuid.uuid4() + try: + 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 + output_dir = os.path.join(folder_paths.base_path, "input","create_avatar_endpoint") + os.makedirs(output_dir, exist_ok=True) + + filename = os.path.join(output_dir,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) + }) + except Exception as e: + print(e) + return web.json_response({ + "error": e + }) +