Generate Stunning Images with the mcai/rpg-v4-img2img Cognitive Actions

22 Apr 2025
Generate Stunning Images with the mcai/rpg-v4-img2img Cognitive Actions

The mcai/rpg-v4-img2img API offers developers a powerful tool for image generation by allowing them to create new images based on existing ones. Utilizing the RPG V4 model, this API provides a range of customizable parameters for generating variations of input images, making it an ideal solution for applications in art, design, and more. The pre-built cognitive actions simplify the integration process, letting developers focus on enhancing their applications without deep dives into complex image processing algorithms.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of making HTTP requests and handling JSON data in your programming language of choice.

Authentication usually involves passing the API key in the request headers, allowing you to securely access the cognitive actions.

Cognitive Actions Overview

Generate Image with RPG V4

The Generate Image with RPG V4 action allows you to create an image from an input image using the RPG V4 model. It offers customizable parameters such as noise strength, upscaling, and prompt guidance to help tailor the generated output to your needs.

  • Category: Image Generation

Input

The input for this action must conform to the following schema:

{
  "image": "https://replicate.delivery/pbxt/IvyFhgXEUwLNcD0HbhZnoqfAH0tht5subUIIscFgyMROb1MH/d7c66c29e54be6e0efe29389aa042773.jpg",
  "prompt": "The Great Wave (Hokusai) with a tiny Mount Fuji in the background.",
  "upscale": 2,
  "strength": 0.5,
  "scheduler": "EulerAncestralDiscrete",
  "guidanceScale": 7.5,
  "negativePrompt": "disfigured, kitsch, ugly, oversaturated, greain, low-res, deformed, blurry, bad anatomy, poorly drawn face, mutation, mutated, extra limb, poorly drawn hands, missing limb, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, disgusting, poorly drawn, childish, mutilated, mangled, old, surreal, calligraphy, sign, writing, watermark, text, body out of frame, extra legs, extra arms, extra feet, out of frame, poorly drawn feet, cross-eye",
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 30
}
  • Required Fields:
    • image: A valid URI of the initial image.
  • Optional Fields:
    • seed: Random seed for variations (integer).
    • prompt: Text prompt guiding the generation (string).
    • upscale: Factor for upscaling (integer between 1 and 4).
    • strength: Noise strength (number between 0 and 1).
    • scheduler: Scheduling algorithm (string).
    • guidanceScale: Guidance scale (number between 1 and 20).
    • negativePrompt: Undesired elements to avoid (string).
    • numberOfOutputs: Number of images to generate (integer between 1 and 4).
    • numberOfInferenceSteps: Steps for denoising (integer between 1 and 500).

Example Input

{
  "image": "https://replicate.delivery/pbxt/IvyFhgXEUwLNcD0HbhZnoqfAH0tht5subUIIscFgyMROb1MH/d7c66c29e54be6e0efe29389aa042773.jpg",
  "prompt": "The Great Wave (Hokusai) with a tiny Mount Fuji in the background.",
  "upscale": 2,
  "strength": 0.5,
  "scheduler": "EulerAncestralDiscrete",
  "guidanceScale": 7.5,
  "negativePrompt": "disfigured, kitsch, ugly, oversaturated, greain, low-res, deformed, blurry, bad anatomy, poorly drawn face, mutation, mutated, extra limb, poorly drawn hands, missing limb, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, disgusting, poorly drawn, childish, mutilated, mangled, old, surreal, calligraphy, sign, writing, watermark, text, body out of frame, extra legs, extra arms, extra feet, out of frame, poorly drawn feet, cross-eye",
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 30
}

Output

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

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/88e22319-30f0-4fa3-8e73-afb46e7b0e7b/36d659cc-bf14-43a7-b0b6-9bb098563040.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python snippet to demonstrate how you can call the Generate Image with RPG V4 action:

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 = "1801e230-acef-47ac-9685-2635ebce3f4d"  # Action ID for Generate Image with RPG V4

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/IvyFhgXEUwLNcD0HbhZnoqfAH0tht5subUIIscFgyMROb1MH/d7c66c29e54be6e0efe29389aa042773.jpg",
    "prompt": "The Great Wave (Hokusai) with a tiny Mount Fuji in the background.",
    "upscale": 2,
    "strength": 0.5,
    "scheduler": "EulerAncestralDiscrete",
    "guidanceScale": 7.5,
    "negativePrompt": "disfigured, kitsch, ugly, oversaturated, greain, low-res, deformed, blurry, bad anatomy, poorly drawn face, mutation, mutated, extra limb, poorly drawn hands, missing limb, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, disgusting, poorly drawn, childish, mutilated, mangled, old, surreal, calligraphy, sign, writing, watermark, text, body out of frame, extra legs, extra arms, extra feet, out of frame, poorly drawn feet, cross-eye",
    "numberOfOutputs": 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 code snippet, you'll see how to structure the input payload based on the example input provided. The action ID and the endpoint URL are illustrative and should be replaced with actual values when implementing.

Conclusion

The mcai/rpg-v4-img2img Cognitive Actions provide an easy and effective way to integrate advanced image generation capabilities into your applications. With customizable parameters, developers can create unique visual content tailored to their specific needs. To get started, try experimenting with different input images and prompts to see the range of outputs you can achieve!