finish image route link

This commit is contained in:
BennyKok
2023-11-14 16:09:35 -08:00
parent f957bcf4b4
commit 2dc693f474
2 changed files with 52 additions and 1 deletions
+28
View File
@@ -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(
{
+24 -1
View File
@@ -152,4 +152,27 @@ async def post_input_file(request):
with open(filename, "wb") as f:
f.write(post)
return web.json_response({})
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)
})