Harnessing Image Generation with the `jonathan-hubjam/jonathan-flux` Cognitive Actions

24 Apr 2025
Harnessing Image Generation with the `jonathan-hubjam/jonathan-flux` Cognitive Actions

In today's digital landscape, the ability to create stunning images programmatically can significantly enhance applications across various domains. The jonathan-hubjam/jonathan-flux API offers a powerful Cognitive Action named Generate Image with Inpainting that allows developers to generate images using advanced inpainting and image-to-image conversion techniques. With options for customizable resolution, aspect ratio, and output quality, this action provides the flexibility needed for creative projects.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Familiarity with making HTTP requests in your preferred programming language.
  • Understanding of JSON structure for input and output data.

Authentication typically involves passing your API key in the headers of your requests, which allows you to securely access the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Inpainting

Description:
The Generate Image with Inpainting action enables users to create images by either generating new visuals from textual prompts or modifying existing images using inpainting techniques. This action supports customizable settings for resolution, aspect ratio, and output quality, making it ideal for various creative applications.

Category: Image Generation

Input:

The input schema for this action requires the following fields:

  • prompt: (required) A textual description of the image you want to generate.
  • model: (optional) Select the inference model to use. Options include dev (default) or schnell.
  • aspectRatio: (optional) Set the aspect ratio of the generated image. Default is 1:1.
  • outputFormat: (optional) Choose the format for output images (e.g., webp, jpg, png). Default is webp.
  • guidanceScale: (optional) A scale for the diffusion process, affecting the realism of generated images.
  • loraIntensity: (optional) Controls the intensity of LoRA application.
  • numberOfOutputs: (optional) Specify how many output images to generate (default is 1).

Example Input:

{
  "model": "dev",
  "prompt": "JONSHUBJAM a bald man sailing on a yacht – in a chic outfit, enjoying a calm day at sea, with seagulls flying overhead.",
  "aspectRatio": "1:1",
  "outputFormat": "png",
  "guidanceScale": 1.99,
  "loraIntensity": 1,
  "outputQuality": 90,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 30
}

Output:

The action typically returns an array of URLs pointing to the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/b8dbdcc5-e916-4608-87f5-21a09e39a6b8/65051584-5937-4ea9-b206-cdbe755d68b5.png"
]

Conceptual Usage Example (Python):

Here’s how you might call this action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "24c7b56c-f37d-48c4-af2e-353be0754c95" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "JONSHUBJAM a bald man sailing on a yacht – in a chic outfit, enjoying a calm day at sea, with seagulls flying overhead.",
    "aspectRatio": "1:1",
    "outputFormat": "png",
    "guidanceScale": 1.99,
    "loraIntensity": 1,
    "outputQuality": 90,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "additionalLoraScale": 1,
    "numberOfInferenceSteps": 30
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this example, we replace the action ID and the input payload with appropriate values. The endpoint URL and request structure are illustrative and should be adapted to your actual API specifications.

Conclusion

The jonathan-hubjam/jonathan-flux Cognitive Actions, specifically the Generate Image with Inpainting, provide a robust tool for developers looking to integrate image generation capabilities into their applications. By leveraging customizable settings and advanced generation techniques, you can create visually stunning content tailored to your specific needs. Consider exploring other potential use cases and experimenting with the various options available to unlock the full potential of this action in your projects. Happy coding!