fix: 🐛 improve startup times
This commit is contained in:
+1
-1
@@ -75,7 +75,7 @@ def extract_nodes_from_source(filename: Path):
|
||||
)
|
||||
break
|
||||
except SyntaxError:
|
||||
log.error("Failed to parse")
|
||||
log.error(f"Failed to parse ast from: {filename}")
|
||||
return nodes
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ from .utils import (
|
||||
backup_file,
|
||||
build_glob_patterns,
|
||||
glob_multiple,
|
||||
import_install,
|
||||
reqs_map,
|
||||
run_command,
|
||||
styles_dir,
|
||||
@@ -24,7 +23,6 @@ from .utils import (
|
||||
endlog = mklog("mtb endpoint")
|
||||
|
||||
# - ACTIONS
|
||||
import_install("requirements")
|
||||
|
||||
|
||||
def ACTIONS_installDependency(dependency_names: list[str] | None = None):
|
||||
|
||||
@@ -43,7 +43,6 @@ pip_map = {
|
||||
"tb-nightly": "tensorboard",
|
||||
"protobuf": "google.protobuf",
|
||||
"qrcode[pil]": "qrcode",
|
||||
"requirements-parser": "requirements",
|
||||
# Add more mappings as needed
|
||||
}
|
||||
|
||||
|
||||
+14
-13
@@ -1,20 +1,16 @@
|
||||
from typing import Any, TypedDict
|
||||
from typing import TYPE_CHECKING, Any, TypedDict
|
||||
|
||||
import torch
|
||||
import torchaudio
|
||||
from comfy.model_management import get_torch_device
|
||||
from huggingface_hub import snapshot_download
|
||||
from transformers import (
|
||||
WhisperForConditionalGeneration,
|
||||
WhisperProcessor,
|
||||
)
|
||||
|
||||
# from transformers import (
|
||||
# AutoFeatureExtractor,
|
||||
# WhisperForConditionalGeneration,
|
||||
# WhisperModel,
|
||||
# WhisperProcessor,
|
||||
# )
|
||||
if TYPE_CHECKING:
|
||||
from transformers import (
|
||||
WhisperForConditionalGeneration,
|
||||
WhisperProcessor,
|
||||
)
|
||||
|
||||
from ..log import log
|
||||
from ..utils import get_model_path
|
||||
|
||||
@@ -101,8 +97,8 @@ class MtbAudio:
|
||||
class WhisperPipeline(TypedDict):
|
||||
"""Whisper model pipeline."""
|
||||
|
||||
processor: WhisperProcessor
|
||||
model: WhisperForConditionalGeneration
|
||||
processor: "WhisperProcessor"
|
||||
model: "WhisperForConditionalGeneration"
|
||||
|
||||
|
||||
class MTB_LoadWhisper:
|
||||
@@ -148,6 +144,11 @@ class MTB_LoadWhisper:
|
||||
|
||||
def load(self, model_size="tiny", download_missing=False):
|
||||
"""Load Whisper model and processor."""
|
||||
from transformers import (
|
||||
WhisperForConditionalGeneration,
|
||||
WhisperProcessor,
|
||||
)
|
||||
|
||||
whisper_dir = get_model_path("whisper")
|
||||
tag = f"whisper-{model_size}"
|
||||
model_dir = whisper_dir / tag
|
||||
|
||||
+7
-4
@@ -4,12 +4,8 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
import comfy.model_management as model_management
|
||||
import cv2
|
||||
import insightface
|
||||
import numpy as np
|
||||
import onnxruntime
|
||||
import torch
|
||||
from insightface.model_zoo.inswapper import INSwapper
|
||||
from PIL import Image
|
||||
|
||||
from ..errors import ModelNotFound
|
||||
@@ -43,6 +39,8 @@ class MTB_LoadFaceAnalysisModel:
|
||||
DEPRECATED = True
|
||||
|
||||
def load_model(self, faceswap_model: str):
|
||||
import insightface
|
||||
|
||||
if faceswap_model == "antelopev2":
|
||||
download_antelopev2()
|
||||
|
||||
@@ -81,6 +79,9 @@ class MTB_LoadFaceSwapModel:
|
||||
DEPRECATED = True
|
||||
|
||||
def load_model(self, faceswap_model: str):
|
||||
import onnxruntime
|
||||
from insightface.model_zoo.inswapper import INSwapper
|
||||
|
||||
model_path = get_model_path("insightface", faceswap_model)
|
||||
if not model_path or not model_path.exists():
|
||||
raise ModelNotFound(f"{faceswap_model} ({model_path})")
|
||||
@@ -212,6 +213,8 @@ def swap_face(
|
||||
face_swapper_model,
|
||||
faces_index: set[int] | None = None,
|
||||
) -> Image.Image:
|
||||
import cv2
|
||||
|
||||
if faces_index is None:
|
||||
faces_index = {0}
|
||||
log.debug(f"Swapping faces: {faces_index}")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import contextlib
|
||||
import functools
|
||||
import importlib
|
||||
import math
|
||||
import operator
|
||||
import os
|
||||
@@ -462,23 +461,6 @@ def _run_command(shell_cmd, ignored_lines_start):
|
||||
print("Command executed successfully!")
|
||||
|
||||
|
||||
def import_install(package_name):
|
||||
package_spec = reqs_map.get(package_name, package_name)
|
||||
|
||||
try:
|
||||
importlib.import_module(package_name)
|
||||
|
||||
except Exception: # (ImportError, ModuleNotFoundError):
|
||||
run_command(
|
||||
[
|
||||
Path(sys.executable).as_posix(),
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
package_spec,
|
||||
]
|
||||
)
|
||||
importlib.import_module(package_name)
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
@@ -195,6 +195,7 @@ export function hideWidgetForGood(node, widget, suffix = '') {
|
||||
widget.origComputeSize = widget.computeSize
|
||||
widget.origSerializeValue = widget.serializeValue
|
||||
widget.computeSize = () => [0, -4] // -4 is due to the gap litegraph adds between widgets automatically
|
||||
widget.hidden = true
|
||||
widget.type = CONVERTED_TYPE + suffix
|
||||
// widget.serializeValue = () => {
|
||||
// // Prevent serializing the widget if we have no input linked
|
||||
|
||||
+25
-10
@@ -257,13 +257,28 @@ class NotePlus extends LiteGraph.LGraphNode {
|
||||
}
|
||||
}
|
||||
get iconRect() {
|
||||
const iconSize = 32
|
||||
const iconMargin = 16
|
||||
let icon = {
|
||||
size: 24,
|
||||
margin: 5,
|
||||
yoffset: -25,
|
||||
}
|
||||
|
||||
if (window.inspector) {
|
||||
if (window.inspector.get('note_icon') !== null) {
|
||||
icon = window.inspector.get('note_icon')
|
||||
} else {
|
||||
window.inspector.set('note_icon', icon)
|
||||
window.inspector.subscribe('note_icon', (k, v) => {
|
||||
console.log(v)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
x: this.size[0] - iconSize - iconMargin,
|
||||
y: iconMargin * 1.5,
|
||||
width: iconSize,
|
||||
height: iconSize,
|
||||
x: this.size[0] - icon.size - icon.margin,
|
||||
y: icon.yoffset, //iconMargin * 1.5,
|
||||
width: icon.size,
|
||||
height: icon.size,
|
||||
}
|
||||
}
|
||||
onMouseDown(_e, localPos, _graphcanvas) {
|
||||
@@ -797,8 +812,8 @@ class NotePlus extends LiteGraph.LGraphNode {
|
||||
|
||||
app.registerExtension({
|
||||
name: 'mtb.noteplus',
|
||||
setup: () => {
|
||||
app.ui.settings.addSetting({
|
||||
settings: [
|
||||
{
|
||||
id: 'mtb.noteplus.use-shiki',
|
||||
category: ['mtb', 'Note+', 'use-shiki'],
|
||||
name: 'Use shiki to highlight code',
|
||||
@@ -816,8 +831,8 @@ app.registerExtension({
|
||||
storage.set('np-use-shiki', value)
|
||||
useShiki = value
|
||||
},
|
||||
})
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
registerCustomNodes() {
|
||||
LiteGraph.registerNodeType('Note Plus (mtb)', NotePlus)
|
||||
|
||||
Reference in New Issue
Block a user