Skip to content

Commit

Permalink
backup before clean
Browse files Browse the repository at this point in the history
  • Loading branch information
yvann-ba committed Sep 7, 2024
1 parent 173ae74 commit c5a516f
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 36 deletions.
33 changes: 24 additions & 9 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
from .node_configs import CombinedMeta
from collections import OrderedDict

# credit to RyanOnTheInside, KJNodes, MTB, Akatz, their works helped me a lot
# credit to RyanOnTheInside, KJNodes, MTB, Fill, Akatz, their works helped me a lot


#allows for central management and inheritance of class variables for help documentation
from collections import OrderedDict

class Yvann(metaclass=CombinedMeta):
@classmethod
def get_description(cls):
footer = "Code : [Yvann GitHub](https://github.com/yvann-ba)\n"
footer += "Tutorials and Workflows: [Yvann Youtube](https://www.youtube.com/@yvann.mp4)\n\n"

display_name = NODE_DISPLAY_NAME_MAPPINGS.get(cls.__name__, cls.__name__)
footer = "For more information, visit [RyanOnTheInside GitHub](https://github.com/ryanontheinside).\n\n"
footer += "For tutorials and example workflows visit [RyanOnTheInside Civitai](https://civitai.com/user/ryanontheinside).\n\n"
display_name = display_name.replace(" | Yvann", "")

desc = f"# {display_name}\n\n"
desc = ""

if hasattr(cls, 'DESCRIPTION'):
desc += f"{cls.DESCRIPTION}\n\n{footer}"
return desc

if hasattr(cls, 'TOP_DESCRIPTION'):
desc += f"### {cls.TOP_DESCRIPTION}\n\n"
desc += f"{cls.TOP_DESCRIPTION}\n\n"

if hasattr(cls, "BASE_DESCRIPTION"):
desc += cls.BASE_DESCRIPTION + "\n\n"
Expand All @@ -30,7 +29,6 @@ def get_description(cls):
for c in cls.mro()[::-1]:
if hasattr(c, 'ADDITIONAL_INFO'):
info = c.ADDITIONAL_INFO.strip()

additional_info[c.__name__] = info

if additional_info:
Expand All @@ -45,11 +43,16 @@ def get_description(cls):
from .nodes.audio.Audio_Drums_Analysis_Yvann import Audio_Drums_Analysis_Yvann
from .nodes.audio.Audio_Vocals_Analysis_Yvann import Audio_Vocals_Analysis_Yvann
from .nodes.audio.Audio_Analysis_Yvann import Audio_Analysis_Yvann
from .nodes.audio.previewaudio2 import PreviewAudio2
from .nodes.audio.imagemask import ImageAndMaskPreview2


NODE_CLASS_MAPPINGS = {
"Audio Drums Analysis | Yvann": Audio_Drums_Analysis_Yvann,
"Audio Vocals Analysis | Yvann": Audio_Vocals_Analysis_Yvann,
"Audio Analysis | Yvann": Audio_Analysis_Yvann,
"Preview Audio | Yvann": PreviewAudio2,
"Image And Mask Preview | Yvann": ImageAndMaskPreview2,
}

WEB_DIRECTORY = "./web/js"
Expand All @@ -58,8 +61,18 @@ def get_description(cls):
"Audio Drums Analysis | Yvann": "Audio Drums Analysis | Yvann",
"Audio Vocals Analysis | Yvann": "Audio Vocals Analysis | Yvann",
"Audio Analysis | Yvann": "Audio Analysis | Yvann",
"Preview Audio | Yvann": "Preview Audio | Yvann",
"Image And Mask Preview | Yvann": "Image And Mask Preview | Yvann",
}

Yvann_Print = """
🔊 Yvann Audio Reactive Nodes"""

print("\033[38;5;195m" + Yvann_Print + "\033[38;5;222m" + " : Loaded\n" + "\033[0m")




from aiohttp import web
from server import PromptServer
from pathlib import Path
Expand All @@ -79,3 +92,5 @@ def get_description(cls):
if hasattr(node_class, 'get_description'):
desc = node_class.get_description()
node_class.DESCRIPTION = desc

__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
18 changes: 10 additions & 8 deletions nodes/audio/Audio_Analysis_Yvann.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import torch
import os
import folder_paths
import matplotlib.pyplot as plt
import tempfile
import numpy as np
from PIL import Image
import librosa
from nodes import SaveImage
import pandas as pd
from ... import Yvann
import random

class AudioNodeBase(Yvann):
CATEGORY= "👁️ Yvann Nodes/Audio"

CATEGORY= "👁️ Yvann Nodes/🔊 Audio"
class Audio_Analysis_Yvann(AudioNodeBase):
def __init__(self):
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5))
@classmethod
def INPUT_TYPES(cls):
return {
Expand Down Expand Up @@ -77,7 +79,7 @@ def generate_masks(self, input_values, width, height):

return masks_out

def process_audio(self, audio, video_frames, frame_rate, smoothing_factor, global_intensity):
def process_audio(self, audio, video_frames, frame_rate, smoothing_factor, global_intensity, prompt=None, filename_prefix="ComfyUI", extra_pnginfo=None):
waveform = audio['waveform']
sample_rate = audio['sample_rate']

Expand All @@ -94,7 +96,7 @@ def process_audio(self, audio, video_frames, frame_rate, smoothing_factor, globa
samples_per_frame = total_samples // num_frames

processed_audio = {
'waveform': waveform,
'waveform': waveform.cpu(),
'sample_rate': sample_rate,
'frame_rate': frame_rate
}
Expand Down Expand Up @@ -133,5 +135,5 @@ def process_audio(self, audio, video_frames, frame_rate, smoothing_factor, globa
processed_audio,
audio_weights.tolist(),
audio_masks,
weights_graph
weights_graph,
)
2 changes: 1 addition & 1 deletion nodes/audio/Audio_Drums_Analysis_Yvann.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ... import Yvann

class AudioNodeBase(Yvann):
CATEGORY= "👁️ Yvann Nodes/Audio"
CATEGORY= "👁️ Yvann Nodes/🔊 Audio"

class Audio_Drums_Analysis_Yvann(AudioNodeBase):
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion nodes/audio/Audio_Vocals_Analysis_Yvann.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ... import Yvann

class AudioNodeBase(Yvann):
CATEGORY= "👁️ Yvann Nodes/Audio"
CATEGORY= "👁️ Yvann Nodes/🔊 Audio"

class Audio_Vocals_Analysis_Yvann(AudioNodeBase):

Expand Down
63 changes: 63 additions & 0 deletions nodes/bin/imagemask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import random
import folder_paths
from nodes import SaveImage
from comfy_extras.nodes_mask import ImageCompositeMasked
import numpy as np


class ImageAndMaskPreview2(SaveImage):
def __init__(self):
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5))
self.compress_level = 4

@classmethod
def INPUT_TYPES(s):
return {
"required": {
"mask_opacity": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
"mask_color": ("STRING", {"default": "255, 255, 255"}),
"pass_through": ("BOOLEAN", {"default": False}),
},
"optional": {
"image": ("IMAGE",),
"mask": ("MASK",),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("composite",)
FUNCTION = "execute"
CATEGORY = "KJNodes"
DESCRIPTION = """
Preview an image or a mask, when both inputs are used
composites the mask on top of the image.
with pass_through on the preview is disabled and the
composite is returned from the composite slot instead,
this allows for the preview to be passed for video combine
nodes for example.
"""

def execute(self, mask_opacity, mask_color, pass_through, filename_prefix="ComfyUI", image=None, mask=None, prompt=None, extra_pnginfo=None):
if mask is not None and image is None:
preview = mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])).movedim(1, -1).expand(-1, -1, -1, 3)
elif mask is None and image is not None:
preview = image
elif mask is not None and image is not None:
mask_adjusted = mask * mask_opacity
mask_image = mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])).movedim(1, -1).expand(-1, -1, -1, 3).clone()

if ',' in mask_color:
color_list = np.clip([int(channel) for channel in mask_color.split(',')], 0, 255) # RGB format
else:
mask_color = mask_color.lstrip('#')
color_list = [int(mask_color[i:i+2], 16) for i in (0, 2, 4)] # Hex format
mask_image[:, :, :, 0] = color_list[0] / 255 # Red channel
mask_image[:, :, :, 1] = color_list[1] / 255 # Green channel
mask_image[:, :, :, 2] = color_list[2] / 255 # Blue channel

preview, = ImageCompositeMasked.composite(self, image, mask_image, 0, 0, True, mask_adjusted)
if pass_through:
return (preview, )
return(self.save_images(preview, filename_prefix, prompt, extra_pnginfo))
25 changes: 25 additions & 0 deletions nodes/bin/previewaudio2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import torchaudio
import torch
import comfy.model_management
import folder_paths
import os
import io
import json
import struct
import random
import hashlib
from comfy.cli_args import args
from comfy_extras.nodes_audio import SaveAudio

class PreviewAudio2(SaveAudio):
def __init__(self):
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prefix_append = "_temp_" + ''.join(random.choice("abcdefghijklmnopqrstupvxyz") for x in range(5))

@classmethod
def INPUT_TYPES(s):
return {"required":
{"audio": ("AUDIO", ), },
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
15 changes: 0 additions & 15 deletions web/appearance.js

This file was deleted.

16 changes: 16 additions & 0 deletions web/js/appearance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { app } from "../../../scripts/app.js";

app.registerExtension({
name: "Yvann.appearance", // Extension name
async nodeCreated(node) {
if (node.comfyClass.endsWith("Yvann")) {
// Apply styling
node.color = "#153a61";
node.bgcolor = "#1A4870";


}
}
});

//#51829B bleu fonce
4 changes: 2 additions & 2 deletions web/js/help_popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ loadScript('/yvann_web_async/purify.min.js').catch((e) => {
console.log(e)
})

const categories = [""];
const categories = ["👁️ Yvann Nodes"];
app.registerExtension({
name: "Yvann.HelpPopup",
async beforeRegisterNodeDef(nodeType, nodeData) {
Expand Down Expand Up @@ -275,7 +275,7 @@ const create_documentation_stylesheet = () => {
ctx.lineJoin = 'round'
ctx.lineWidth = 2.4
ctx.font = 'bold 36px monospace'
ctx.fillStyle = 'orange';
ctx.fillStyle = '#EADFB4';
ctx.fillText('?', 0, 24)
ctx.restore()
return r
Expand Down

0 comments on commit c5a516f

Please sign in to comment.