Ported and curated from the internal fal-flux-nodes package: dropped 3 redundant nodes (Nano Banana v1, AnyVLM, SeedVR v1) that were fully superseded by newer variants already in the set. Every node now takes an explicit api_key STRING input instead of reading from a config file or environment variable, so no key is ever baked into this repo.
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
import logging
|
|
from .base_node import (
|
|
SupersideFalNode,
|
|
ImageProcessingMixin,
|
|
APIClientMixin,
|
|
API_KEY_INPUT_SPEC,
|
|
)
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Florence2CaptionNode(
|
|
SupersideFalNode, ImageProcessingMixin, APIClientMixin
|
|
):
|
|
"""
|
|
Florence-2 Large More Detailed Caption Node: Generate detailed captions
|
|
for images using Florence-2 Large model via fal.ai API.
|
|
"""
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"image": ("IMAGE",),
|
|
"api_key": API_KEY_INPUT_SPEC,
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("STRING",)
|
|
FUNCTION = "caption"
|
|
DISPLAY_NAME = "Florence-2 Detailed Caption"
|
|
DESCRIPTION = "Generate detailed captions for images using Florence-2 Large model"
|
|
|
|
def prepare_arguments(self, client, image, **kwargs):
|
|
"""Prepare arguments for the API call."""
|
|
# Upload image and get URL
|
|
image_url = self.upload_image(client, image)
|
|
|
|
arguments = {
|
|
"image_url": image_url,
|
|
}
|
|
|
|
return arguments
|
|
|
|
def caption(self, image, api_key, **kwargs):
|
|
"""Main captioning function."""
|
|
try:
|
|
client = self.get_client(api_key)
|
|
arguments = self.prepare_arguments(client, image, **kwargs)
|
|
logger.info(f"Calling Florence-2 API with arguments: {arguments}")
|
|
|
|
result = self.call_api(
|
|
client, "fal-ai/florence-2-large/more-detailed-caption", arguments
|
|
)
|
|
|
|
logger.debug(f"API Response: {result}")
|
|
|
|
# Extract the caption from the results
|
|
if "results" not in result:
|
|
raise RuntimeError("No caption was generated by the API.")
|
|
|
|
caption = result["results"]
|
|
logger.info(f"Generated caption: {caption}")
|
|
|
|
# Return as a tuple (required by ComfyUI)
|
|
return (caption,)
|
|
|
|
except Exception as e:
|
|
logger.error(f"Captioning failed: {str(e)}")
|
|
raise
|