Remove redundant SD3 API Node

This commit is contained in:
kijai 2025-06-03 20:45:28 +03:00
parent ea5482a6ee
commit 76d67a963e
3 changed files with 1 additions and 156 deletions

View File

@ -155,7 +155,6 @@ NODE_CONFIG = {
"InterpolateCoords": {"class": InterpolateCoords, "name": "Interpolate Coords"}, "InterpolateCoords": {"class": InterpolateCoords, "name": "Interpolate Coords"},
"PointsEditor": {"class": PointsEditor, "name": "Points Editor"}, "PointsEditor": {"class": PointsEditor, "name": "Points Editor"},
#experimental #experimental
"StabilityAPI_SD3": {"class": StabilityAPI_SD3, "name": "Stability API SD3"},
"SoundReactive": {"class": SoundReactive, "name": "Sound Reactive"}, "SoundReactive": {"class": SoundReactive, "name": "Sound Reactive"},
"StableZero123_BatchSchedule": {"class": StableZero123_BatchSchedule, "name": "Stable Zero123 Batch Schedule"}, "StableZero123_BatchSchedule": {"class": StableZero123_BatchSchedule, "name": "Stable Zero123 Batch Schedule"},
"SV3D_BatchSchedule": {"class": SV3D_BatchSchedule, "name": "SV3D Batch Schedule"}, "SV3D_BatchSchedule": {"class": SV3D_BatchSchedule, "name": "SV3D Batch Schedule"},

View File

@ -1,3 +0,0 @@
{
"sai_api_key": "your_api_key_here"
}

View File

@ -1693,158 +1693,7 @@ or a .txt file with RealEstate camera intrinsics and coordinates, in a 3D plot.
ret_poses = [transform_matrix @ x for x in ret_poses] ret_poses = [transform_matrix @ x for x in ret_poses]
return np.array(ret_poses, dtype=np.float32) return np.array(ret_poses, dtype=np.float32)
class StabilityAPI_SD3:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True}),
"n_prompt": ("STRING", {"multiline": True}),
"seed": ("INT", {"default": 123,"min": 0, "max": 4294967294, "step": 1}),
"model": (
[
'sd3',
'sd3-turbo',
],
{
"default": 'sd3'
}),
"aspect_ratio": (
[
'1:1',
'16:9',
'21:9',
'2:3',
'3:2',
'4:5',
'5:4',
'9:16',
'9:21',
],
{
"default": '1:1'
}),
"output_format": (
[
'png',
'jpeg',
],
{
"default": 'jpeg'
}),
},
"optional": {
"api_key": ("STRING", {"multiline": True}),
"image": ("IMAGE",),
"img2img_strength": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.01}),
"disable_metadata": ("BOOLEAN", {"default": True}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "apicall"
CATEGORY = "KJNodes/experimental"
DESCRIPTION = """
## Calls StabilityAI API
Although you may have multiple keys in your account,
you should use the same key for all requests to this API.
Get your API key here: https://platform.stability.ai/account/keys
Recommended to set the key in the config.json -file under this
node packs folder.
# WARNING:
Otherwise the API key may get saved in the image metadata even
with "disable_metadata" on if the workflow includes save nodes
separate from this node.
sd3 requires 6.5 credits per generation
sd3-turbo requires 4 credits per generation
If no image is provided, mode is set to text-to-image
"""
def apicall(self, prompt, n_prompt, model, seed, aspect_ratio, output_format,
img2img_strength=0.5, image=None, disable_metadata=True, api_key=""):
from comfy.cli_args import args
if disable_metadata:
args.disable_metadata = True
else:
args.disable_metadata = False
import requests
from torchvision import transforms
data = {
"mode": "text-to-image",
"prompt": prompt,
"model": model,
"seed": seed,
"output_format": output_format
}
if image is not None:
image = image.permute(0, 3, 1, 2).squeeze(0)
to_pil = transforms.ToPILImage()
pil_image = to_pil(image)
# Save the PIL Image to a BytesIO object
buffer = io.BytesIO()
pil_image.save(buffer, format='PNG')
buffer.seek(0)
files = {"image": ("image.png", buffer, "image/png")}
data["mode"] = "image-to-image"
data["image"] = pil_image
data["strength"] = img2img_strength
else:
data["aspect_ratio"] = aspect_ratio,
files = {"none": ''}
if model != "sd3-turbo":
data["negative_prompt"] = n_prompt
headers={
"accept": "image/*"
}
if api_key != "":
headers["authorization"] = api_key
else:
config_file_path = os.path.join(script_directory,"config.json")
with open(config_file_path, 'r') as file:
config = json.load(file)
api_key_from_config = config.get("sai_api_key")
headers["authorization"] = api_key_from_config
response = requests.post(
f"https://api.stability.ai/v2beta/stable-image/generate/sd3",
headers=headers,
files = files,
data = data,
)
if response.status_code == 200:
# Convert the response content to a PIL Image
image = Image.open(io.BytesIO(response.content))
# Convert the PIL Image to a PyTorch tensor
transform = transforms.ToTensor()
tensor_image = transform(image)
tensor_image = tensor_image.unsqueeze(0)
tensor_image = tensor_image.permute(0, 2, 3, 1).cpu().float()
return (tensor_image,)
else:
try:
# Attempt to parse the response as JSON
error_data = response.json()
raise Exception(f"Server error: {error_data}")
except json.JSONDecodeError:
# If the response is not valid JSON, raise a different exception
raise Exception(f"Server error: {response.text}")
class CheckpointPerturbWeights: class CheckpointPerturbWeights: