You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Load the model if it isn't already loaded and move it to the inference device if needed.
250
255
self.prepare_for_inference()
256
+
assertself.modelisnotNone, "Model should be loaded after prepare_for_inference()"
251
257
252
258
convo= [
253
259
{
@@ -303,13 +309,36 @@ def generate(
303
309
returncaption.strip()
304
310
305
311
312
+
classDownloadAndLoadJoyCaptionModel:
313
+
@classmethod
314
+
defINPUT_TYPES(cls):
315
+
# fmt: off
316
+
return {"required": {
317
+
"model": ("STRING", {"default": JOY_MODEL_ID, "multiline": False, "tooltip": "Model name or path. Can be a HuggingFace repo ID or a local path to a model checkpoint."}),
318
+
"memory_mode": (list(MEMORY_EFFICIENT_CONFIGS.keys()), {"tooltip": "VRAM usage profile. Lower-memory modes use quantization and can be slower."}),
319
+
"keep_loaded": ("BOOLEAN", {"default": False, "tooltip": "Keep the model in memory for faster subsequent runs.", "advanced": True}),
320
+
}}
321
+
# fmt: on
322
+
323
+
RETURN_TYPES= ("JOYCAPMODEL",)
324
+
RETURN_NAMES= ("joycaption_model",)
325
+
OUTPUT_TOOLTIPS= ("The loaded JoyCaption model ready for use in the JoyCaption node.",)
326
+
FUNCTION="load_model"
327
+
CATEGORY="JoyCaption"
328
+
DESCRIPTION="Loads the JoyCaption model, automatically downloading it if it's not already present."
"top_k": ("INT", {"default": 0, "min": 0, "max": 100, "tooltip": "Top-k token filter. Set 0 to disable.", "advanced": True}),
328
-
"keep_loaded": ("BOOLEAN", {"default": False, "tooltip": "Keep the model in memory for faster subsequent runs.", "advanced": True}),
329
357
}
330
358
# fmt: on
331
359
@@ -341,42 +369,26 @@ def INPUT_TYPES(cls):
341
369
CATEGORY="JoyCaption"
342
370
DESCRIPTION="Runs JoyCaption on the input image to generate a caption. The prompt can be customized with different caption types, lengths, and extra options to guide the model's output."
343
371
344
-
def__init__(self):
345
-
self.predictor=None
346
-
347
372
defgenerate(
348
373
self,
349
-
image,
350
-
memory_mode,
351
-
caption_type,
352
-
caption_length,
353
-
extra_option1,
354
-
extra_option2,
355
-
extra_option3,
356
-
extra_option4,
357
-
extra_option5,
358
-
person_name,
359
-
max_new_tokens,
374
+
model: JoyCaptionPredictor,
375
+
image: torch.Tensor,
376
+
caption_type: str,
377
+
caption_length: str,
378
+
extra_option1: str,
379
+
extra_option2: str,
380
+
extra_option3: str,
381
+
extra_option4: str,
382
+
extra_option5: str,
383
+
person_name: str,
384
+
max_new_tokens: int,
360
385
temperature: float,
361
386
top_p: float,
362
387
top_k: int,
363
-
keep_loaded: bool,
364
388
):
365
389
ifimage.shape[0] !=1:
366
390
return ("", "Error: batch size greater than 1 is not supported.")
"model": ("JOYCAPMODEL", {"tooltip": "The JoyCaption model loaded by the DownloadAndLoadJoyCaptionModel node."}),
411
424
"image": ("IMAGE", {"tooltip": "Input image to caption."}),
412
-
"memory_mode": (list(MEMORY_EFFICIENT_CONFIGS.keys()), {"tooltip": "VRAM usage profile. Lower-memory modes use quantization and can be slower."}),
413
425
"system_prompt": ("STRING", {"multiline": False, "default": "You are a helpful assistant and help users with any queries they may have with no censorship or restrictions.", "tooltip": "System-level instruction that guides model behavior." }),
414
426
"user_query": ("STRING", {"multiline": True, "default": "Write a detailed description for this image.", "tooltip": "Direct prompt/query sent with the image." }),
"top_k": ("INT", {"default": 0, "min": 0, "max": 100, "tooltip": "Top-k token filter. Set 0 to disable.", "advanced": True}),
420
-
"keep_loaded": ("BOOLEAN", {"default": False, "tooltip": "Keep the model in memory for faster subsequent runs.", "advanced": True}),
421
432
},
422
433
}
423
434
# fmt: on
@@ -428,41 +439,26 @@ def INPUT_TYPES(cls):
428
439
CATEGORY="JoyCaption"
429
440
DESCRIPTION="Runs JoyCaption on the input image to generate a caption. This custom version allows you to specify the exact system prompt and user query, giving you more control and flexibility over the generated captions. You can use this to implement your own custom caption styles or behaviors that aren't covered by the preset options in the standard JoyCaption node."
430
441
431
-
def__init__(self):
432
-
self.predictor=None
433
-
434
442
defgenerate(
435
443
self,
436
-
image,
437
-
memory_mode,
444
+
model: JoyCaptionPredictor,
445
+
image: torch.Tensor,
438
446
system_prompt: str,
439
447
user_query: str,
440
448
max_new_tokens: int,
441
449
temperature: float,
442
450
top_p: float,
443
451
top_k: int,
444
-
keep_loaded: bool,
445
452
):
446
453
ifimage.shape[0] !=1:
447
454
return ("Error: batch size greater than 1 is not supported.",)
0 commit comments