Skip to content

Commit d27f114

Browse files
author
Aryan185
committed
Improved Flux-Kontext nodes
1 parent 3d3f519 commit d27f114

4 files changed

Lines changed: 30 additions & 130 deletions

File tree

__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from .flux_kontext_pro_node import NODE_CLASS_MAPPINGS as PRO_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as PRO_DISPLAY
2-
from .flux_kontext_max_node import NODE_CLASS_MAPPINGS as MAX_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as MAX_DISPLAY
1+
from .flux_kontext import NODE_CLASS_MAPPINGS as PRO_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as PRO_DISPLAY
32
from .gemini_node import NODE_CLASS_MAPPINGS as GEMINI_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as GEMINI_DISPLAY
43
from .gemini_diarisation import NODE_CLASS_MAPPINGS as GEMINI_DIAR_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as GEMINI_DIAR_DISPLAY
54
from .gpt_image1 import NODE_CLASS_MAPPINGS as GPT_IMAGE_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as GPT_IMAGE_DISPLAY
@@ -13,7 +12,7 @@
1312
from .elevenlabs_tts import NODE_CLASS_MAPPINGS as ELEVENLABS_TTS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as ELEVENLABS_TTS_DISPLAY
1413
from .cleanup import NODE_CLASS_MAPPINGS as CLEANUP_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS as CLEANUP_DISPLAY
1514

16-
NODE_CLASS_MAPPINGS = {**PRO_MAPPINGS, **MAX_MAPPINGS, **GEMINI_MAPPINGS, **GEMINI_DIAR_MAPPINGS, **GPT_IMAGE_MAPPINGS, **IMAGEN_IMAGE_MAPPINGS, **IMAGEN_EDIT_MAPPINGS, **VEO_MAPPINGS, **VEO_GEMINI_MAPPINGS, **GEMINI_SEGMENT_MAPPINGS, **NANO_BANANA_MAPPINGS, **GEMINI_TTS_MAPPINGS, **ELEVENLABS_TTS_MAPPINGS, **CLEANUP_MAPPINGS}
17-
NODE_DISPLAY_NAME_MAPPINGS = {**PRO_DISPLAY, **MAX_DISPLAY, **GEMINI_DISPLAY, **GEMINI_DIAR_DISPLAY, **GPT_IMAGE_DISPLAY, **IMAGEN_IMAGE_DISPLAY, **IMAGEN_EDIT_DISPLAY, **VEO_DISPLAY, **VEO_GEMINI_DISPLAY, **GEMINI_SEGMENT_DISPLAY, **NANO_BANANA_DISPLAY, **GEMINI_TTS_DISPLAY, **ELEVENLABS_TTS_DISPLAY, **CLEANUP_DISPLAY}
15+
NODE_CLASS_MAPPINGS = {**PRO_MAPPINGS, **GEMINI_MAPPINGS, **GEMINI_DIAR_MAPPINGS, **GPT_IMAGE_MAPPINGS, **IMAGEN_IMAGE_MAPPINGS, **IMAGEN_EDIT_MAPPINGS, **VEO_MAPPINGS, **VEO_GEMINI_MAPPINGS, **GEMINI_SEGMENT_MAPPINGS, **NANO_BANANA_MAPPINGS, **GEMINI_TTS_MAPPINGS, **ELEVENLABS_TTS_MAPPINGS, **CLEANUP_MAPPINGS}
16+
NODE_DISPLAY_NAME_MAPPINGS = {**PRO_DISPLAY, **GEMINI_DISPLAY, **GEMINI_DIAR_DISPLAY, **GPT_IMAGE_DISPLAY, **IMAGEN_IMAGE_DISPLAY, **IMAGEN_EDIT_DISPLAY, **VEO_DISPLAY, **VEO_GEMINI_DISPLAY, **GEMINI_SEGMENT_DISPLAY, **NANO_BANANA_DISPLAY, **GEMINI_TTS_DISPLAY, **ELEVENLABS_TTS_DISPLAY, **CLEANUP_DISPLAY}
1817

1918
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,20 @@
66
from PIL import Image
77
import io
88

9-
class FluxKontextMaxNode:
9+
class FluxKontextNode:
1010
@classmethod
1111
def INPUT_TYPES(cls):
1212
return {
1313
"required": {
1414
"image": ("IMAGE",),
15-
"prompt": ("STRING", {
16-
"multiline": True,
17-
"default": "Make this a 90s cartoon"
18-
}),
19-
"api_key": ("STRING", {
20-
"default": ""
21-
}),
22-
"aspect_ratio": (["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "5:4", "4:5", "21:9", "9:21", "2:1", "1:2", "match_input_image"], {
23-
"default": "match_input_image"
24-
}),
25-
"output_format": (["jpg", "png"], {
26-
"default": "jpg"
27-
}),
28-
"safety_tolerance": ("INT", {
29-
"default": 2,
30-
"min": 0,
31-
"max": 6,
32-
"step": 1
33-
}),
15+
"prompt": ("STRING", {"multiline": True, "default": "Make this a 90s cartoon"}),
16+
"api_key": ("STRING", {"default": ""}),
17+
"model": (["flux-kontext-dev", "flux-kontext-max", "flux-kontext-pro"], {"default": "flux-kontext-dev"}),
18+
"aspect_ratio": (["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "5:4", "4:5", "21:9", "9:21", "2:1", "1:2", "match_input_image"], {"default": "match_input_image"}),
19+
"output_format": (["jpg", "png"], {"default": "jpg"}),
20+
"safety_tolerance": ("INT", {"default": 2, "min": 0, "max": 6, "step": 1}),
21+
"seed": ("INT", {"default": 69, "min": 1, "max": 2147483646, "step": 1}),
22+
"prompt_upsampling": ("BOOLEAN", {"default": False})
3423
}
3524
}
3625

@@ -39,7 +28,7 @@ def INPUT_TYPES(cls):
3928
FUNCTION = "generate_image"
4029
CATEGORY = "image/edit"
4130

42-
def generate_image(self, image, prompt, api_key, aspect_ratio, output_format, safety_tolerance):
31+
def generate_image(self, image, prompt, api_key, model, aspect_ratio, output_format, safety_tolerance, seed, prompt_upsampling):
4332
try:
4433
os.environ["REPLICATE_API_TOKEN"] = api_key
4534

@@ -53,16 +42,21 @@ def generate_image(self, image, prompt, api_key, aspect_ratio, output_format, sa
5342
pil_image.save(img_buffer, format='PNG')
5443
img_buffer.seek(0)
5544

56-
# Run Replicate model
45+
# Build input dict with all parameters for both models
46+
replicate_input = {
47+
"prompt": prompt,
48+
"input_image": img_buffer,
49+
"aspect_ratio": aspect_ratio,
50+
"output_format": output_format,
51+
"safety_tolerance": safety_tolerance,
52+
"seed": seed,
53+
"prompt_upsampling": prompt_upsampling
54+
}
55+
56+
# Run Replicate model with selected model
5757
output = replicate.run(
58-
"black-forest-labs/flux-kontext-max",
59-
input={
60-
"prompt": prompt,
61-
"input_image": img_buffer,
62-
"aspect_ratio": aspect_ratio,
63-
"output_format": output_format,
64-
"safety_tolerance": safety_tolerance
65-
}
58+
f"black-forest-labs/{model}",
59+
input=replicate_input
6660
)
6761

6862
# Get URL from output
@@ -85,9 +79,9 @@ def generate_image(self, image, prompt, api_key, aspect_ratio, output_format, sa
8579
return (torch.zeros((1, 512, 512, 3)),)
8680

8781
NODE_CLASS_MAPPINGS = {
88-
"FluxKontextMaxNode": FluxKontextMaxNode
82+
"FluxKontextNode": FluxKontextNode
8983
}
9084

9185
NODE_DISPLAY_NAME_MAPPINGS = {
92-
"FluxKontextMaxNode": "Flux Kontext Max"
86+
"FluxKontextNode": "Flux Kontext"
9387
}

flux_kontext_pro_node.py

Lines changed: 0 additions & 93 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "externalapi-helpers"
33
description = "Various ComfyUI nodes for Gemini, Replicate and OpenAI"
4-
version = "1.0.3"
4+
version = "1.0.4"
55
license = {file = "LICENSE"}
66
# classifiers = [
77
# # For OS-independent nodes (works on all operating systems)

0 commit comments

Comments
 (0)