Skip to content

Commit

Permalink
Merge pull request #33 from TNG/fix/FluxWorkflowMissingGitRef
Browse files Browse the repository at this point in the history
Fix git ref provided by workflows
  • Loading branch information
florianesser-tng authored Dec 19, 2024
2 parents dc20cfe + bf49b78 commit 7e69bff
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion WebUI/external/workflows/FaceSwapHD.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"onnxruntime"
],
"customNodes": [
"Gourieff/comfyui-reactor-node/be1c60bd62d1fb35511153533032c5a6811c8fab"
"Gourieff/comfyui-reactor-node@be1c60bd62d1fb35511153533032c5a6811c8fab"
],
"requiredModels": [
"defaultCheckpoint:RunDiffusion/Juggernaut-XL-v9/unet/diffusion_pytorch_model.fp16.safetensors",
Expand Down
2 changes: 1 addition & 1 deletion WebUI/external/workflows/fluxQ4.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"backend": "comfyui",
"comfyUIRequirements": {
"customNodes": [
"city96/ComfyUI-GGUF/65a7c895bb0ac9547ba2f89d55fbdb609aa2bfe7"
"city96/ComfyUI-GGUF@65a7c895bb0ac9547ba2f89d55fbdb609aa2bfe7"
],
"requiredModels": [
"unet:city96/FLUX.1-schnell-gguf/flux1-schnell-Q4_K_S.gguf",
Expand Down
2 changes: 1 addition & 1 deletion WebUI/external/workflows/fluxQ8.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"backend": "comfyui",
"comfyUIRequirements": {
"customNodes": [
"city96/ComfyUI-GGUF"
"city96/ComfyUI-GGUF@65a7c895bb0ac9547ba2f89d55fbdb609aa2bfe7"
],
"requiredModels": [
"unet:city96/FLUX.1-schnell-gguf/flux1-schnell-Q8_0.gguf",
Expand Down
25 changes: 21 additions & 4 deletions WebUI/src/assets/js/store/comfyUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,30 @@ export const useComfyUi = defineStore("comfyUi", () => {
}
}

function extractCustomNodeInfo(workflowNodeInfoString: string): ComfyUICustomNodesRequestParameters {
const repoInfoWithPotentialGitRefSplitted = workflowNodeInfoString.replace(" ", "").split("@")
if (repoInfoWithPotentialGitRefSplitted.length > 2 || repoInfoWithPotentialGitRefSplitted.length < 1) {
console.error(`Could not extract comfyUI node description from ${workflowNodeInfoString}`)
throw new Error("Could not extract comfyUI node description from ${workflowNodeInfoString}")
}
const [repoInfoString, gitRef] = repoInfoWithPotentialGitRefSplitted
if (!gitRef) {
console.warn(`No gitRef provided in ${workflowNodeInfoString}.`)
}
const repoInfoSplitted = repoInfoString.replace(" ", "").split("/")
if (repoInfoSplitted.length !== 2) {
console.error(`Could not extract comfyUI node description from ${workflowNodeInfoString}`)
throw new Error("Could not extract comfyUI node description from ${workflowNodeInfoString}")
}
const [username, repoName] = repoInfoSplitted
console.info(JSON.stringify({username: username, repoName: repoName, gitRef: gitRef}))
return {username: username, repoName: repoName, gitRef: gitRef}
}

async function installCustomNodesForActiveWorkflow(): Promise<boolean> {
const uniqueCustomNodes = new Set(imageGeneration.workflows.filter(w => w.name === imageGeneration.activeWorkflowName).filter(w => w.backend === 'comfyui').flatMap((item) => item.comfyUIRequirements.customNodes))
const requiredCustomNodes: ComfyUICustomNodesRequestParameters[] =
[...uniqueCustomNodes].map((nodeName) => {
const [username, repoName, gitRef] = nodeName.replace(" ", "").split("/")
return {username: username, repoName: repoName, gitRef: gitRef}
})
[...uniqueCustomNodes].map((nodeName) => extractCustomNodeInfo(nodeName))
const response = await fetch(`${globalSetup.apiHost}/api/comfyUi/loadCustomNodes`, {
method: 'POST',
body: JSON.stringify({data: requiredCustomNodes}),
Expand Down
2 changes: 1 addition & 1 deletion WebUI/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ type DownloadModelParam = CheckModelAlreadyLoadedParameters
type ComfyUICustomNodesRequestParameters = {
username: string,
repoName: string
gitRef: string
gitRef?: string
}


Expand Down
1 change: 1 addition & 0 deletions WebUI/src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const downloadModel = reactive({
const showParams = ref(false);
const infoParams = ref<KVObject>({})
const emits = defineEmits<{
(e: "showDownloadModelConfirm", downloadList: DownloadModelParam[], success?: () => void, fail?: () => void): void,
(e: "postImageToEnhance", url: string): void
Expand Down
8 changes: 4 additions & 4 deletions service/aipg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ def check_defaultbackend_mmodel_exist(type: int, repo_id: str) -> bool:
elif type == 7:
dir = service_config.service_model_paths.get("preview")
return (
os.path.exists(os.path.join(dir, folder_name, "config.json"))
or os.path.exists(os.path.join(dir, f"{repo_id}.safetensors"))
or os.path.exists(os.path.join(dir, f"{repo_id}.bin"))
os.path.exists(os.path.join(dir, folder_name, "config.json"))
or os.path.exists(os.path.join(dir, f"{repo_id}.safetensors"))
or os.path.exists(os.path.join(dir, f"{repo_id}.bin"))
)



def convert_model_type(type: int):
Expand Down
15 changes: 11 additions & 4 deletions service/comfyui_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ def _install_git_repo(git_repo_url: str, target_dir: str):
aipg_utils.remove_existing_filesystem_resource(target_dir)
raise e

def _checkout_git_ref(repo_dir: str, git_ref: str):
def _checkout_git_ref(repo_dir: str, git_ref: Optional[str]):
if git_ref is None or not git_ref.strip():
logging.info(f"No valid git ref provided for {repo_dir}")
logging.warning(f"Repo {repo_dir} remains in ref {get_git_ref(repo_dir)}.")
return
try:
aipg_utils.call_subprocess(f"{service_config.git.get('exePath')} checkout {git_ref}", cwd=repo_dir)
logging.info(f"checked out {git_ref} in {repo_dir}")
except Exception as e:
logging.warning(f"git checkout of {git_ref} failed for rep {repo_dir} due to {e}.")
logging.warning(f"will use repo ref {get_git_ref(repo_dir)} in {repo_dir}.")
logging.warning(f"Repo {repo_dir} remains in ref {get_git_ref(repo_dir)}.")


def get_git_ref(repo_dir: str) -> Optional[str]:
Expand Down Expand Up @@ -159,8 +163,11 @@ def install_comfyUI() -> bool:

def is_custom_node_installed_with_git_ref(node_repo_ref: ComfyUICustomNodesGithubRepoId) -> bool:
expected_custom_node_path = os.path.join(service_config.comfy_ui_root_path, "custom_nodes", node_repo_ref.repoName)
custom_node_dir_exists= os.path.exists(expected_custom_node_path)
return custom_node_dir_exists and (get_git_ref(expected_custom_node_path) == node_repo_ref.gitRef)
custom_node_dir_exists = os.path.exists(expected_custom_node_path)

git_ref_provided = node_repo_ref.gitRef is not None and not node_repo_ref.gitRef.strip() == ""
git_ref_matches = not git_ref_provided and (get_git_ref(expected_custom_node_path) == node_repo_ref.gitRef)
return custom_node_dir_exists and git_ref_matches


def download_custom_node(node_repo_data: ComfyUICustomNodesGithubRepoId) -> bool:
Expand Down
13 changes: 0 additions & 13 deletions service/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,6 @@ def delete_rag_file():
return jsonify({"code": -1, "message": "failed"})


@app.get("/api/comfyUi/isInstalled")
def is_comfyUI_loaded():
return jsonify({"is_comfyUI_installed": comfyui_downloader.is_comfyUI_installed()})

@app.post("/api/comfyUi/install")
def install_comfyUI():
try:
installation_success = comfyui_downloader.install_comfyUI()
return jsonify({"success": installation_success, "error_message": ""})
except Exception as e:
return jsonify({'error_message': f'failed to install comfyUI due to {e}'}), 501


@app.post("/api/comfyUi/areCustomNodesLoaded")
@app.input(ComfyUICustomNodesDownloadRequest.Schema, location='json', arg_name='comfyNodeRequest')
def are_custom_nodes_installed(comfyNodeRequest: ComfyUICustomNodesDownloadRequest):
Expand Down
4 changes: 2 additions & 2 deletions service/web_request_bodies.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

import marshmallow_dataclass
from marshmallow import EXCLUDE
Expand All @@ -20,7 +20,7 @@ class DownloadModelRequestBody:
class ComfyUICustomNodesGithubRepoId:
username: str
repoName: str
gitRef: str
gitRef: Optional[str]

@marshmallow_dataclass.dataclass
class ComfyUICustomNodesDownloadRequest:
Expand Down

0 comments on commit 7e69bff

Please sign in to comment.