feat: 워크 플로우 선택 후 파일 업로드 시 AI 실행 결과물을 다운로드 할 수 있도록 구현

This commit is contained in:
hyojeong 2024-07-11 17:10:57 +09:00
parent ffe0bb0a33
commit 108e7aa35c
6 changed files with 6842 additions and 0 deletions

207
web/comfyui-custom.html Normal file
View File

@ -0,0 +1,207 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ComfyUI</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="./lib/litegraph.css" />
<link rel="stylesheet" type="text/css" href="./style.css" />
<link rel="stylesheet" type="text/css" href="./user.css" />
<script type="text/javascript" src="./lib/litegraph.core.js"></script>
<script type="text/javascript" src="./lib/litegraph.extensions.js" defer></script>
<script type="module">
import { app } from "./scripts/app.js";
await app.setup();
window.app = app;
window.graph = app.graph;
let workflowJson = "";
async function loadWorkflow() {
const selectElement = document.getElementById('workflow-select');
const fileName = selectElement.value;
const response = await fetch(`../workflow/${fileName}.json`);
if (!response.ok) {
throw new Error('Network response was not ok' + response.statusText);
}
workflowJson = await response.json();
await app.loadGraphData(workflowJson);
}
async function uploadFileAndDisplay(input) {
const fileInput = input.files[0];
if (!fileInput) {
alert('No file selected.');
return;
}
const formData = new FormData();
formData.append('image', fileInput);
const response = await fetch('/upload/image', {
method: 'POST',
body: formData,
headers: {
'Accept': 'application/json'
}
});
if (response.ok) {
const result = await response.json();
const fileName = result.name;
const viewResponse = await fetch(`/view?filename=${fileName}&subfolder=&type=input&rand=${Math.random()}`);
if (viewResponse.ok) {
const img = document.getElementById('input-image');
img.src = `/view?filename=${fileName}&subfolder=&type=input&rand=${Math.random()}`;
img.style.display = 'block';
for (let node of workflowJson.nodes) {
if (node.type === "LoadImage" && node.widgets_values) {
node.widgets_values[0] = fileName;
}
}
await app.loadGraphData(workflowJson);
} else {
alert('Failed to load the image.');
}
} else {
alert('File upload failed.');
}
}
async function executeWorkflow() {
const progressText = document.getElementById('progress-text');
progressText.textContent = "executing";
await app.queuePrompt(0, app.batchCount);
}
window.loadWorkflow = loadWorkflow;
window.executeWorkflow = executeWorkflow;
window.uploadFileAndDisplay = uploadFileAndDisplay;
</script>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.top-section {
height: 50vh;
padding: 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
.litegraph {
height: 0;
width: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.input-group, .output-group {
display: flex;
align-items: center;
}
.input-group select, .input-group input, .input-group button, .output-group a {
margin: 0 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
.input-group button {
background-color: #007BFF;
color: white;
border: none;
cursor: pointer;
}
.input-group button:hover {
background-color: #0056b3;
}
#image-link {
color: white;
background-color: black;
text-decoration: none;
padding: 10px;
border-radius: 5px;
}
#image-link:hover {
background-color: #333;
}
/* Hide the canvas element */
#graph-canvas {
display: none;
}
.comfy-menu {
display: none;
}
</style>
</head>
<body>
<div class="container">
<div class="top-section" id="top-section">
<div class="input-group">
workflow:
<select id="workflow-select" onchange="loadWorkflow()">
<option value="" selected>선택</option>
<option value="고급화그림">고급화그림</option>
<option value="누끼제거">누끼제거</option>
<option value="이미지To3D">이미지To3D</option>
<option value="포즈기반이미지To영상">포즈기반이미지To영상</option>
</select>
Input:
<input type="file" id="input-image-file" accept="image/*" onchange="uploadFileAndDisplay(this)" />
<img id="input-image" src="" alt="Input Image" style="display: none; max-height: 100px;" />
<button id="execute-button" onclick="executeWorkflow()">Execute</button>
</div>
<div class="output-group">
Output:
<div id="progress-text">Ready</div>
<a id="image-link" href="" download>Download</a>
</div>
</div>
<div class="litegraph">
<div id="comfy-user-selection" class="comfy-user-selection">
<main class="comfy-user-selection-inner">
<h1>ComfyUI</h1>
<form>
<section>
<label>New user:
<input placeholder="Enter a username" />
</label>
</section>
<div class="comfy-user-existing">
<span class="or-separator">OR</span>
<section>
<label>
Existing user:
<select>
<option hidden disabled selected value> Select a user </option>
</select>
</label>
</section>
</div>
<footer>
<span class="comfy-user-error">&nbsp;</span>
<button class="comfy-btn comfy-user-button-next">Next</button>
</footer>
</form>
</main>
</div>
</div>
</div>
</body>
</html>

View File

@ -1361,11 +1361,31 @@ export class ComfyApp {
} else { } else {
this.nodeOutputs[detail.node] = detail.output; this.nodeOutputs[detail.node] = detail.output;
} }
let filename = "";
if (detail.output.images && detail.output.images.length > 0 && detail.output.images[0].type !== "temp") {
filename = detail.output.images[0].filename;
}
if (detail.output.mesh && detail.output.mesh.length > 0 && detail.output.mesh[0].type !== "temp") {
filename = detail.output.mesh[0].filename;
}
if(filename) {
const imageDisplay = document.getElementById('image-link');
imageDisplay.href = `/output/${filename}`;
imageDisplay.download = `${filename}`;
const progressText = document.getElementById('progress-text');
progressText.textContent = "executed";
}
const node = this.graph.getNodeById(detail.node); const node = this.graph.getNodeById(detail.node);
if (node) { if (node) {
if (node.onExecuted) if (node.onExecuted)
node.onExecuted(detail.output); node.onExecuted(detail.output);
} }
}); });
api.addEventListener("execution_start", ({ detail }) => { api.addEventListener("execution_start", ({ detail }) => {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,236 @@
{
"last_node_id": 29,
"last_link_id": 31,
"nodes": [
{
"id": 15,
"type": "RemBGSession+",
"pos": [
-170,
326
],
"size": {
"0": 315,
"1": 82
},
"flags": {},
"order": 0,
"mode": 0,
"outputs": [
{
"name": "REMBG_SESSION",
"type": "REMBG_SESSION",
"links": [
13
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "RemBGSession+"
},
"widgets_values": [
"u2net: general purpose",
"CPU"
]
},
{
"id": 10,
"type": "ImageRemoveBackground+",
"pos": [
234,
469
],
"size": {
"0": 241.79998779296875,
"1": 46
},
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "rembg_session",
"type": "REMBG_SESSION",
"link": 13,
"slot_index": 0
},
{
"name": "image",
"type": "IMAGE",
"link": 31,
"slot_index": 1
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
15
],
"shape": 3,
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": [],
"shape": 3,
"slot_index": 1
}
],
"properties": {
"Node name for S&R": "ImageRemoveBackground+"
}
},
{
"id": 16,
"type": "Reroute",
"pos": [
414,
359
],
"size": [
75,
26
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 15,
"slot_index": 0
}
],
"outputs": [
{
"name": "",
"type": "IMAGE",
"links": [
30
],
"slot_index": 0
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
},
{
"id": 28,
"type": "SaveImage",
"pos": [
740.5532322770055,
408.34797427018646
],
"size": {
"0": 315,
"1": 270
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 30
}
],
"properties": {},
"widgets_values": [
"ComfyUI"
]
},
{
"id": 29,
"type": "LoadImage",
"pos": [
-218,
545
],
"size": [
315,
314.0000228881836
],
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
31
],
"shape": 3,
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null,
"shape": 3
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"cat (20).png",
"image"
]
}
],
"links": [
[
13,
15,
0,
10,
0,
"REMBG_SESSION"
],
[
15,
10,
0,
16,
0,
"*"
],
[
30,
16,
0,
28,
0,
"IMAGE"
],
[
31,
29,
0,
10,
1,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.7513148009015777,
"offset": [
451.5689869130959,
-32.26232158243161
]
}
},
"version": 0.4
}

View File

@ -0,0 +1,336 @@
{
"last_node_id": 12,
"last_link_id": 10,
"nodes": [
{
"id": 1,
"type": "TripoSRModelLoader",
"pos": [
389,
280
],
"size": {
"0": 315,
"1": 82
},
"flags": {},
"order": 0,
"mode": 0,
"outputs": [
{
"name": "TRIPOSR_MODEL",
"type": "TRIPOSR_MODEL",
"links": [
1
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "TripoSRModelLoader"
},
"widgets_values": [
"model.ckpt",
8192
]
},
{
"id": 11,
"type": "RemBGSession+",
"pos": [
36,
308
],
"size": {
"0": 315,
"1": 82
},
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "REMBG_SESSION",
"type": "REMBG_SESSION",
"links": [
9
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "RemBGSession+"
},
"widgets_values": [
"u2net: general purpose",
"CPU"
]
},
{
"id": 3,
"type": "TripoSRSampler",
"pos": [
848.3013735596055,
342.30822708483936
],
"size": {
"0": 315,
"1": 122
},
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "TRIPOSR_MODEL",
"link": 1
},
{
"name": "reference_image",
"type": "IMAGE",
"link": 7,
"slot_index": 1
},
{
"name": "reference_mask",
"type": "MASK",
"link": 8,
"slot_index": 2
}
],
"outputs": [
{
"name": "MESH",
"type": "MESH",
"links": [
3
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "TripoSRSampler"
},
"widgets_values": [
512,
25
]
},
{
"id": 10,
"type": "ImageRemoveBackground+",
"pos": [
129,
519
],
"size": {
"0": 241.79998779296875,
"1": 46
},
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "rembg_session",
"type": "REMBG_SESSION",
"link": 9,
"slot_index": 0
},
{
"name": "image",
"type": "IMAGE",
"link": 6
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
7,
10
],
"shape": 3,
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": [
8
],
"shape": 3
}
],
"properties": {
"Node name for S&R": "ImageRemoveBackground+"
}
},
{
"id": 12,
"type": "PreviewImage",
"pos": [
613,
610
],
"size": {
"0": 210,
"1": 246
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 10
}
],
"properties": {
"Node name for S&R": "PreviewImage"
}
},
{
"id": 2,
"type": "LoadImage",
"pos": [
-217,
530
],
"size": {
"0": 315,
"1": 314
},
"flags": {},
"order": 2,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
6
],
"shape": 3,
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null,
"shape": 3
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"image_readtop_2018_265364_15247057823291378 (1).jpeg",
"image"
]
},
{
"id": 4,
"type": "TripoSRViewer",
"pos": [
1248,
359
],
"size": [
600,
500
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "mesh",
"type": "MESH",
"link": 3
}
],
"properties": {
"Node name for S&R": "TripoSRViewer"
},
"widgets_values": [
null
]
}
],
"links": [
[
1,
1,
0,
3,
0,
"TRIPOSR_MODEL"
],
[
3,
3,
0,
4,
0,
"MESH"
],
[
6,
2,
0,
10,
1,
"IMAGE"
],
[
7,
10,
0,
3,
1,
"IMAGE"
],
[
8,
10,
1,
3,
2,
"MASK"
],
[
9,
11,
0,
10,
0,
"REMBG_SESSION"
],
[
10,
10,
0,
12,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.5644739300537773,
"offset": [
586.2580156758065,
287.71162612790465
]
}
},
"version": 0.4
}

File diff suppressed because it is too large Load Diff