Generate Stunning Images with the mcai/urpm-v1.3-img2img Cognitive Actions

24 Apr 2025
Generate Stunning Images with the mcai/urpm-v1.3-img2img Cognitive Actions

The mcai/urpm-v1.3-img2img API offers developers a powerful toolset for image generation, leveraging advanced algorithms to create visually compelling images based on user inputs. With this set of Cognitive Actions, you can easily generate new images from existing ones, incorporating text prompts and various customization options such as upscaling, noise levels, and guidance control. In this blog post, we'll explore how to integrate these capabilities into your applications.

Prerequisites

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

  1. API Key: You will need an API key for the Cognitive Actions platform. This key will be used to authenticate your requests.
  2. Setup: Familiarize yourself with making HTTP requests in your preferred programming language.

Authentication typically involves passing the API key in the request headers.

Cognitive Actions Overview

Generate Image with URPM v1.3

The Generate Image with URPM v1.3 action allows you to create new images based on an input image. It features advanced customization options including text prompts, upscaling, noise levels, and guidance controls, making it a versatile tool for developers in the image generation space.

Input

The input for this action is structured as follows:

  • Required:
    • image (string): The URI of the initial image used to generate variations.
  • Optional:
    • seed (integer): Random seed for generating variations (default is random).
    • prompt (string): Descriptive text for the desired output.
    • upscale (number): Upscaling factor for the output image (1 to 4, default is 1).
    • strength (number): Degree of noise (0 to 1, default is 0.5).
    • scheduler (string): Scheduler algorithm for processing (default is "EulerAncestralDiscrete").
    • guidanceScale (number): Control for classifier-free guidance (1 to 20, default is 7.5).
    • negativePrompt (string): Elements to exclude from the output.
    • numberOfOutputs (integer): Number of images to generate (1 to 4, default is 1).
    • numberOfInferenceSteps (integer): Number of denoising steps (1 to 500, default is 30).

Example Input:

{
  "image": "https://replicate.delivery/pbxt/IvyTOjVHHdwaNW60zu8SARghg6mNXkgXEOH0LAn238y53HYp/il_1588xN.620769841_3kw7.webp",
  "prompt": "A painting of a cafe terrace at night in Arles, France. The cafe is brightly lit, with yellow, green, and orange lights. The tables are filled with people, and there are a few musicians playing. The sky is dark blue, and there are stars twinkling in the distance. The painting is done in a post-impressionist style, with thick brushstrokes and vibrant colors.",
  "upscale": 1,
  "strength": 0.3,
  "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 output image URIs.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/9ac02d36-10dd-4685-9cb1-4272568c8a3d/7f73fb8b-0fdb-48d9-a4ca-470e79683cca.png"
]

Conceptual Usage Example (Python)

Here is a conceptual Python code snippet demonstrating how to call this 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 = "1e6a7d8a-3e62-4896-a40f-3871c7ce2dc7"  # Action ID for Generate Image with URPM v1.3

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/IvyTOjVHHdwaNW60zu8SARghg6mNXkgXEOH0LAn238y53HYp/il_1588xN.620769841_3kw7.webp",
    "prompt": "A painting of a cafe terrace at night in Arles, France. The cafe is brightly lit, with yellow, green, and orange lights. The tables are filled with people, and there are a few musicians playing. The sky is dark blue, and there are stars twinkling in the distance. The painting is done in a post-impressionist style, with thick brushstrokes and vibrant colors.",
    "upscale": 1,
    "strength": 0.3,
    "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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id is set for the "Generate Image with URPM v1.3" action, and the payload contains the structured input for the API call.

Conclusion

The mcai/urpm-v1.3-img2img Cognitive Actions provide a robust framework for generating stunning images tailored to your specifications. By leveraging the capabilities of this API, you can enhance your applications with dynamic and artistic image generation. Explore further possibilities like integrating user-generated content or automating creative workflows to maximize the potential of your projects!