Transform Photos into Van Gogh Art with Cognitive Actions

23 Apr 2025
Transform Photos into Van Gogh Art with Cognitive Actions

In the world of digital art, the ability to transform ordinary photos into stunning masterpieces is made easier with the power of Cognitive Actions. The "abhishek7kalra/vangogh" spec provides a unique action to apply Vincent van Gogh's iconic style to your images using advanced style transfer techniques. This action allows developers to integrate artistic transformations into their applications seamlessly, opening up new possibilities in creative projects.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with making HTTP requests and handling JSON data in your preferred programming language.

Authentication typically involves passing your API key in the headers of your requests, which secures your access to the Cognitive Actions capabilities.

Cognitive Actions Overview

Apply Van Gogh Style Transfer

Description:
This action transforms your photos into artwork reminiscent of Vincent van Gogh's style using the Stable Diffusion method. It allows customization through a text prompt, enabling users to specify the artistic theme they want to apply.

Category: Style Transfer

Input

The action requires the following input parameters:

  • inputPhoto (required): A URI link to the input image file that serves as the base for processing.
  • prompt (optional): The artistic style or theme to apply to the input photo, with a default value of "Van Gogh style".

Example Input:

{
  "prompt": "Van Gogh style",
  "inputPhoto": "https://replicate.delivery/pbxt/JGREiNaS7u9rKJmmkwtDv1YTAjuqo912Vykp7aeIYB0B0UTb/testimg.jpeg"
}

Output

Upon successful execution, this action returns a URI link to the transformed image. The output typically appears as follows:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/d009d6ba-18ec-459d-869f-7ab9f4b59c00/64c80348-3465-4001-960f-5d695361a230.png"
]

Conceptual Usage Example (Python)

Here is a conceptual Python snippet to demonstrate how to call the Cognitive Actions execution endpoint for the "Apply Van Gogh Style Transfer" 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 = "1ca9de19-7db4-4ff0-89b0-74691ebd6ad8"  # Action ID for "Apply Van Gogh Style Transfer"

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Van Gogh style",
    "inputPhoto": "https://replicate.delivery/pbxt/JGREiNaS7u9rKJmmkwtDv1YTAjuqo912Vykp7aeIYB0B0UTb/testimg.jpeg"
}

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 snippet, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The action ID corresponds to the "Apply Van Gogh Style Transfer" action, and the input payload is structured to match the required fields. The endpoint URL and request structure provided are illustrative and may vary based on the actual implementation.

Conclusion

The "Apply Van Gogh Style Transfer" action empowers developers to infuse their applications with creativity by transforming ordinary images into stunning pieces of art. With just a few lines of code, you can leverage the capabilities of Cognitive Actions to enhance user experiences through artistic expression. Explore the possibilities and let your creativity flow!