-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
72 changed files
with
3,592 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
import json | ||
|
||
def get_workflows_directory(): | ||
# Change this to the desired location within your ComfyUI directory | ||
return os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "FL_WorkflowManager") | ||
|
||
def get_workflow_path(name): | ||
workflows_dir = get_workflows_directory() | ||
return os.path.abspath(os.path.join(workflows_dir, f"{name}.json")) | ||
|
||
def save_workflow(name, workflow_data): | ||
file_path = get_workflow_path(name) | ||
os.makedirs(os.path.dirname(file_path), exist_ok=True) | ||
with open(file_path, "w") as f: | ||
json.dump(workflow_data, f, indent=2) | ||
|
||
def load_workflow(name): | ||
file_path = get_workflow_path(name) | ||
if not os.path.exists(file_path): | ||
return None | ||
with open(file_path, "r") as f: | ||
return json.load(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import csv | ||
import io | ||
|
||
|
||
class FL_CaptionToCSV: | ||
@classmethod | ||
def INPUT_TYPES(cls): | ||
return { | ||
"required": { | ||
"image_directory": ("STRING", {"default": ""}), | ||
}, | ||
} | ||
|
||
RETURN_TYPES = ("CSV",) | ||
FUNCTION = "create_csv" | ||
CATEGORY = "🏵️Fill Nodes/Captioning" | ||
OUTPUT_NODE = True | ||
|
||
def create_csv(self, image_directory): | ||
# Get all image files and their corresponding caption files | ||
image_files = [f for f in os.listdir(image_directory) if f.lower().endswith(('.png', '.jpg', '.jpeg'))] | ||
image_files.sort() # Sort files to ensure consistent order | ||
|
||
# Prepare CSV data | ||
csv_data = [] | ||
for image_file in image_files: | ||
caption_file = os.path.splitext(image_file)[0] + '.txt' | ||
caption_path = os.path.join(image_directory, caption_file) | ||
try: | ||
with open(caption_path, 'r', encoding='utf-8') as f: | ||
caption = f.read().strip() | ||
except FileNotFoundError: | ||
caption = "No caption found" | ||
|
||
csv_data.append([image_file, caption]) | ||
|
||
# Create CSV in memory | ||
output = io.StringIO() | ||
writer = csv.writer(output) | ||
writer.writerow(['image_file', 'caption']) # Header | ||
writer.writerows(csv_data) | ||
|
||
# Get the CSV content as a string | ||
csv_content = output.getvalue() | ||
|
||
# Convert to bytes for compatibility with other nodes | ||
csv_bytes = csv_content.encode('utf-8') | ||
|
||
return (csv_bytes,) | ||
|
||
@classmethod | ||
def IS_CHANGED(cls, image_directory): | ||
return float("NaN") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class FL_ColorPicker: | ||
@classmethod | ||
def INPUT_TYPES(s): | ||
return { | ||
"required": { | ||
"selected_color": ("STRING", {"default": "#FF0000"}) | ||
} | ||
} | ||
|
||
RETURN_TYPES = ("STRING",) | ||
FUNCTION = "get_color" | ||
CATEGORY = "ui" | ||
|
||
def get_color(self, selected_color): | ||
return (selected_color,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os | ||
import numpy as np | ||
import requests | ||
from PIL import Image | ||
from moviepy.editor import ImageSequenceClip | ||
import torch | ||
import tempfile | ||
import json | ||
|
||
|
||
class FL_SendToDiscordWebhook: | ||
@classmethod | ||
def INPUT_TYPES(cls): | ||
return { | ||
"required": { | ||
"images": ("IMAGE",), | ||
"webhook_url": ("STRING", {"default": "https://discord.com/api/webhooks/YOUR_WEBHOOK_HASH"}), | ||
"frame_rate": ("INT", {"default": 12, "min": 1, "max": 60, "step": 1}), | ||
"save_locally": ("BOOLEAN", {"default": True}), | ||
"bot_username": ("STRING", {"default": "ComfyUI Bot"}), | ||
"message": ("STRING", {"default": "Here's your image/video:", "multiline": True}), | ||
} | ||
} | ||
|
||
RETURN_TYPES = ("STRING",) | ||
FUNCTION = "generate_and_upload" | ||
CATEGORY = "🏵️Fill Nodes/Discord" | ||
OUTPUT_NODE = True | ||
|
||
def generate_and_upload(self, images, webhook_url: str, frame_rate: int, save_locally: bool, bot_username: str, | ||
message: str): | ||
if save_locally: | ||
output_dir = os.path.join(os.path.dirname(__file__), "outputs") | ||
os.makedirs(output_dir, exist_ok=True) | ||
else: | ||
output_dir = tempfile.gettempdir() | ||
|
||
filename = f"discord_upload_{int(torch.rand(1).item() * 10000)}" | ||
|
||
# Prepare the webhook data | ||
webhook_data = { | ||
"username": bot_username, | ||
"content": message, | ||
} | ||
|
||
if len(images) == 1: | ||
file_path = os.path.join(output_dir, f"{filename}.png") | ||
single_image = 255.0 * images[0].cpu().numpy() | ||
single_image_pil = Image.fromarray(single_image.astype(np.uint8)) | ||
single_image_pil.save(file_path) | ||
|
||
with open(file_path, "rb") as file_data: | ||
files = { | ||
"payload_json": (None, json.dumps(webhook_data)), | ||
"file": (f"{filename}.png", file_data) | ||
} | ||
response = requests.post(webhook_url, files=files) | ||
else: | ||
frames = [255.0 * image.cpu().numpy() for image in images] | ||
file_path = os.path.join(output_dir, f"{filename}.mp4") | ||
|
||
clip = ImageSequenceClip(frames, fps=frame_rate) | ||
clip.write_videofile(file_path, codec="libx264", fps=frame_rate) | ||
|
||
with open(file_path, 'rb') as file_data: | ||
files = { | ||
"payload_json": (None, json.dumps(webhook_data)), | ||
"file": (f"{filename}.mp4", file_data) | ||
} | ||
response = requests.post(webhook_url, files=files) | ||
|
||
if response.status_code == 204: | ||
message = "Successfully uploaded to Discord." | ||
else: | ||
message = f"Failed to upload. Status code: {response.status_code} - {response.text}" | ||
|
||
if not save_locally: | ||
os.remove(file_path) | ||
|
||
return (message,) |
Oops, something went wrong.