Elevate Your App's Visuals with the andreaslevin/porsche2 Cognitive Action

22 Apr 2025
Elevate Your App's Visuals with the andreaslevin/porsche2 Cognitive Action

In the realm of image generation, the andreaslevin/porsche2 Cognitive Actions offer a powerful solution for developers looking to create stunning visuals efficiently. With advanced prediction models, customizable features, and inpainting capabilities, these actions allow you to generate high-quality images tailored to your specific needs. This blog post will guide you through the process of integrating the Cognitive Action for image generation, enabling you to harness its full potential for your applications.

Prerequisites

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

  • API Key: You will need an API key from the Cognitive Actions platform to authenticate your requests.
  • Setup: Familiarity with making HTTP requests in your preferred programming language, such as Python.

Authentication typically involves passing your API key in the request headers to validate your access to the Cognitive Actions service.

Cognitive Actions Overview

Generate Image with Inpainting and Image-to-Image Capabilities

This action allows you to generate images using an advanced prediction model optimized for detail and speed, featuring inpainting and image-to-image capabilities. It supports customizable aspect ratios, image quality, and various output formats, all while utilizing detailed inference settings to enhance quality and specificity.

Input

The input for this action is structured as follows:

  • Required:
    • prompt: A text prompt that describes the image to be generated.
  • Optional:
    • mask: URI of the image mask for inpainting.
    • seed: Fixed random seed for reproducibility.
    • image: URI of the input image for image-to-image conversion.
    • width: Specifies the width of the generated image (when aspect_ratio is set to custom).
    • height: Specifies the height of the generated image (when aspect_ratio is set to custom).
    • goFast: Enables faster predictions.
    • imageFormat: Selects the format for saving the generated images (e.g., webp, jpg, png).
    • outputCount: Specifies the number of image outputs to generate.
    • guidanceScale: Adjusts the scale of guidance in the diffusion process.
    • outputQuality: Defines the quality of the saved images.
    • inferenceModel: Specifies the model for inference.
    • promptStrength: Determines the influence of the prompt in transformations.
    • imageResolution: Denotes the approximate megapixels of the output image.
    • imageAspectRatio: Specifies the aspect ratio for the output image.
    • numInferenceSteps: Sets the number of denoising steps.
    • loraScale, additionalLoraScale: Intensity settings for LoRA applications.
    • disableSafetyChecker: Option to disable safety checks for generated images.

Example Input:

{
  "goFast": false,
  "prompt": "A photo of the yellow car PRSCH on mountain side road, italy, beautiful lighting, premium Porsche car photography, side view, fast speed on road",
  "loraScale": 1,
  "imageFormat": "webp",
  "outputCount": 1,
  "guidanceScale": 3,
  "outputQuality": 80,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageResolution": "1",
  "imageAspectRatio": "1:1",
  "numInferenceSteps": 28,
  "additionalLoraScale": 1
}

Output

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

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/ec5ac185-4c83-4f66-a4a7-09708bcde843/3b78519b-0bfe-4bb2-8660-0560ae8ea710.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet to illustrate how you might 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 = "28caeaca-f921-4133-8c6c-3787340eaf8c"  # Action ID for Generate Image with Inpainting and Image-to-Image Capabilities

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "A photo of the yellow car PRSCH on mountain side road, italy, beautiful lighting, premium Porsche car photography, side view, fast speed on road",
    "loraScale": 1,
    "imageFormat": "webp",
    "outputCount": 1,
    "guidanceScale": 3,
    "outputQuality": 80,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageResolution": "1",
    "imageAspectRatio": "1:1",
    "numInferenceSteps": 28,
    "additionalLoraScale": 1
}

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

    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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id corresponds to the Generate Image action, and the input payload is structured according to the outlined requirements. Note that the endpoint URL and request structure shown here are illustrative and may vary based on your setup.

Conclusion

Integrating the andreaslevin/porsche2 Cognitive Action for image generation significantly enhances your application’s ability to produce high-quality visuals tailored to your specifications. By leveraging the robust features of this action, you can create stunning images that elevate user engagement and experience. Explore the various parameters and experiment with different prompts to unlock the full potential of image generation in your projects. Happy coding!