66from PIL import Image
77import 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
8781NODE_CLASS_MAPPINGS = {
88- "FluxKontextMaxNode " : FluxKontextMaxNode
82+ "FluxKontextNode " : FluxKontextNode
8983}
9084
9185NODE_DISPLAY_NAME_MAPPINGS = {
92- "FluxKontextMaxNode " : "Flux Kontext Max "
86+ "FluxKontextNode " : "Flux Kontext"
9387}
0 commit comments