Skip to content

Commit

Permalink
Cleanup the repo and add help popup descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
yvann-ba committed Sep 7, 2024
1 parent c5a516f commit 3aacb91
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 761 deletions.
26 changes: 5 additions & 21 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Thanks to RyanOnTheInside, KJNodes, MTB, Fill, Akatz, their works helped me a lot
from .node_configs import CombinedMeta
from collections import OrderedDict

# 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

# Allows for central management and inheritance of class variables for help documentation
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"
footer = "Code: [Yvann GitHub](https://github.com/yvann-ba)\n"
footer += "👁️ Tutorials and Workflows: [Yvann Youtube](https://www.youtube.com/@yvann.mp4)\n\n"

desc = ""

Expand Down Expand Up @@ -39,20 +35,16 @@ def get_description(cls):

desc += footer
return desc

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 @@ -61,8 +53,6 @@ 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 = """
Expand All @@ -71,23 +61,17 @@ def get_description(cls):
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

if hasattr(PromptServer, "instance"):

# NOTE: we add an extra static path to avoid comfy mechanism
# that loads every script in web.

PromptServer.instance.app.add_routes(
[web.static("/yvann_web_async", (Path(__file__).parent.absolute() / "yvann_web_async").as_posix())]
)



for node_name, node_class in NODE_CLASS_MAPPINGS.items():
if hasattr(node_class, 'get_description'):
desc = node_class.get_description()
Expand Down
65 changes: 47 additions & 18 deletions node_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,62 @@ def add_node_config(node_name, config):

add_node_config("Audio_Analysis_Yvann", {
"BASE_DESCRIPTION": """
##Parameters
- `video_frames`: Input video frames to be processed.
- `audio`: Input audio to be processed.
- `frame_rate`: Frame rate of the video.
- `smoothing_factor`: Smoothing factor for the audio analysis
- `global_intensity`: Global intensity for the audio analysis
#### Analyzes video audio to generate audio-reactive weights and masks
#### Parameters:
- `smoothing_factor`: Smooths audio weights (higher values = smoother transitions)
- `global_intensity`: Adjusts overall intensity of audio weights
#### Inputs:
- `video_frames`: Input video
- `audio`: Video audio
#### Outputs:
- `Audio`: Same as input
- `Audio Weights`: Audio-reactive float values for each frame, usable with IPAdapter, CN, etc.
- `Audio Masks`: Audio weights converted to masks usable with any mask input: Latent Noise Mask, CN, IPadapter etc..
- `Weights Graph`: Visual Graph of "Audio Weights", help to adjust smoothing_factor/global_intensity
"""
})

add_node_config("Audio_Drums_Analysis_Yvann", {
"BASE_DESCRIPTION": """
##Parameters
- `video_frames`: Input video frames to be processed.
- `audio`: Input audio to be processed.
- `frame_rate`: Frame rate of the video.
- `smoothing_factor`: Smoothing factor for the audio analysis
- `global_intensity`: Global intensity for the audio analysis
#### Isolates and analyzes drums sounds in video audio to generate drum-reactive weights and masks
#### Parameters:
- `smoothing_factor`: Smooths drums audio weights (higher values = smoother transitions)
- `global_intensity`: Adjusts overall intensity of drums audio weights
#### Inputs:
- `video_frames`: Input video
- `audio`: Video audio
#### Outputs:
- `Drums Audio`: Isolated drums audio from input
- `Drums Weights`: Drums-reactive float values for each frame, usable with IPAdapter, CN, etc.
- `Drums Masks`: Drums weights converted to masks usable with any mask input: Latent Noise Mask, CN, IPadapter etc..
- `Weights Graph`: Visual Graph of "Drums Weights",help to adjust smoothing_factor/global_intensity
"""
})

add_node_config("Audio_Vocals_Analysis_Yvann", {
"BASE_DESCRIPTION": """
##Parameters
- `video_frames`: Input video frames to be processed.
- `audio`: Input audio to be processed.
- `frame_rate`: Frame rate of the video.
- `smoothing_factor`: Smoothing factor for the audio analysis
- `global_intensity`: Global intensity for the audio analysis
#### Isolates and analyzes vocal sounds in video audio to generate vocal-reactive weights and masks
#### Parameters:
- `smoothing_factor`: Smooths vocals audio weights (higher values = smoother transitions)
- `global_intensity`: Adjusts overall intensity of vocals audio weights
#### Inputs:
- `video_frames`: Input video
- `audio`: Video audio
#### Outputs:
- `Vocals Audio`: Isolated vocals audio from input
- `Vocals Weights`: Vocals-reactive float values for each frame, usable with IPAdapter, CN, etc.
- `Vocals Masks`: Vocals weights converted to masks usable with any mask input: Latent Noise Mask, CN, IPadapter etc..
- `Weights Graph`: Visual Graph of "Vocals Weights", help to adjust smoothing_factor/global_intensity
"""
})
7 changes: 1 addition & 6 deletions nodes/audio/Audio_Analysis_Yvann.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tempfile
import numpy as np
from PIL import Image
import pandas as pd
from ... import Yvann
import random

Expand All @@ -22,7 +21,6 @@ def INPUT_TYPES(cls):
"required": {
"video_frames": ("IMAGE",),
"audio": ("AUDIO",),
"frame_rate": ("INT", {"default": 30, "min": 1, "max": 60, "step": 1}),
"smoothing_factor": ("FLOAT", {"default": 0.25, "min": 0.0, "max": 1.0, "step": 0.01}),
"global_intensity": ("FLOAT", {"default": 0.0, "min": -1.0, "max": 1.0, "step": 0.01}),
}
Expand Down Expand Up @@ -64,8 +62,6 @@ def generate_masks(self, input_values, width, height):
# Ensure input_values is a list
if isinstance(input_values, (float, int)):
input_values = [input_values]
elif isinstance(input_values, pd.Series):
input_values = input_values.tolist()
elif isinstance(input_values, list) and all(isinstance(item, list) for item in input_values):
input_values = [item for sublist in input_values for item in sublist]

Expand All @@ -79,7 +75,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, prompt=None, filename_prefix="ComfyUI", extra_pnginfo=None):
def process_audio(self, audio, video_frames, smoothing_factor, global_intensity, prompt=None, filename_prefix="ComfyUI", extra_pnginfo=None):
waveform = audio['waveform']
sample_rate = audio['sample_rate']

Expand All @@ -98,7 +94,6 @@ def process_audio(self, audio, video_frames, frame_rate, smoothing_factor, globa
processed_audio = {
'waveform': waveform.cpu(),
'sample_rate': sample_rate,
'frame_rate': frame_rate
}

audio_weights = self._rms_energy(waveform, num_frames, samples_per_frame)
Expand Down
7 changes: 1 addition & 6 deletions nodes/audio/Audio_Drums_Analysis_Yvann.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import tempfile
import numpy as np
from PIL import Image
import librosa
from nodes import SaveImage
import pandas as pd
from ... import Yvann

class AudioNodeBase(Yvann):
Expand All @@ -20,7 +17,6 @@ def INPUT_TYPES(cls):
"required": {
"video_frames": ("IMAGE",),
"audio": ("AUDIO",),
"frame_rate": ("INT", {"default": 30, "min": 1, "max": 60, "step": 1}),
"smoothing_factor": ("FLOAT", {"default": 0.25, "min": 0.0, "max": 1.0, "step": 0.01}),
"global_intensity": ("FLOAT", {"default": 0.0, "min": -1.0, "max": 1.0, "step": 0.01}),
}
Expand Down Expand Up @@ -97,7 +93,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, smoothing_factor, global_intensity):
model = self.download_and_load_model()

waveform = audio['waveform']
Expand Down Expand Up @@ -126,7 +122,6 @@ def process_audio(self, audio, video_frames, frame_rate, smoothing_factor, globa
drums_audio = {
'waveform': drums_waveform.cpu(), # Move back to CPU
'sample_rate': sample_rate,
'frame_rate': frame_rate
}

drums_weights = self._rms_energy(drums_waveform.squeeze(0), num_frames, samples_per_frame)
Expand Down
9 changes: 1 addition & 8 deletions nodes/audio/Audio_Vocals_Analysis_Yvann.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import tempfile
import numpy as np
from PIL import Image
import librosa
from nodes import SaveImage
import pandas as pd
from ... import Yvann

class AudioNodeBase(Yvann):
Expand All @@ -21,7 +18,6 @@ def INPUT_TYPES(cls):
"required": {
"video_frames": ("IMAGE",),
"audio": ("AUDIO",),
"frame_rate": ("INT", {"default": 30, "min": 1, "max": 60, "step": 1}),
"smoothing_factor": ("FLOAT", {"default": 0.25, "min": 0.0, "max": 1.0, "step": 0.01}),
"global_intensity": ("FLOAT", {"default": 0.0, "min": -1.0, "max": 1.0, "step": 0.01}),
}
Expand Down Expand Up @@ -86,8 +82,6 @@ def generate_masks(self, input_values, width, height):
# Ensure input_values is a list
if isinstance(input_values, (float, int)):
input_values = [input_values]
elif isinstance(input_values, pd.Series):
input_values = input_values.tolist()
elif isinstance(input_values, list) and all(isinstance(item, list) for item in input_values):
input_values = [item for sublist in input_values for item in sublist]

Expand All @@ -100,7 +94,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, smoothing_factor, global_intensity):
model = self.download_and_load_model()

waveform = audio['waveform']
Expand Down Expand Up @@ -129,7 +123,6 @@ def process_audio(self, audio, video_frames, frame_rate, smoothing_factor, globa
vocals_audio = {
'waveform': vocals_waveform.cpu(), # Move back to CPU
'sample_rate': sample_rate,
'frame_rate': frame_rate
}

vocals_weights = self._rms_energy(vocals_waveform.squeeze(0), num_frames, samples_per_frame)
Expand Down
Loading

0 comments on commit 3aacb91

Please sign in to comment.