Create Stunning Custom Images with Scraft1's Image Generation Action

26 Apr 2025
Create Stunning Custom Images with Scraft1's Image Generation Action

In the world of digital content creation, visually striking images play a crucial role in capturing audience attention. Scraft1 offers an innovative set of Cognitive Actions that allow developers to generate customized images effortlessly. With the ability to create detailed images using either the 'dev' model for high fidelity or the 'schnell' model for rapid results, Scraft1 simplifies the image generation process, making it accessible for various applications.

Whether you are building a creative project, designing marketing materials, or enhancing user experiences in applications, Scraft1’s image generation capabilities can save you time and improve the quality of your visuals. The flexibility to control aspects such as image size, quality, and prompt specificity enables developers to create exactly what they envision.

Prerequisites

To get started, ensure you have a Cognitive Actions API key and a basic understanding of making API calls.

Generate Image with Model

The "Generate Image with Model" action empowers developers to create custom images tailored to specific prompts. This action serves as a solution for those needing unique visuals, whether for artistic expression, product design, or content creation.

Purpose

The action allows for image generation and inpainting, supporting operations like image-to-image transformation. By choosing between the 'dev' model for high detail or the 'schnell' model for faster output, developers can optimize for quality or speed based on project needs.

Input Requirements

The input for this action is structured as a JSON object, requiring the following key properties:

  • prompt: A detailed textual description that guides the image generation.
  • modelName: Choose between 'dev' for detailed images or 'schnell' for faster generation.
  • goFast: A boolean that enables quick processing if set to true.
  • Additional optional parameters include image dimensions, aspect ratio, output format, and more.

Example Input:

{
  "goFast": false,
  "prompt": "scraft1 is a thinner bald white man with beard and is seated in a well-lit, contemporary workspace...",
  "modelName": "dev",
  "guidanceScale": 3,
  "loraIntensity": 1,
  "numMegapixels": "1",
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "png",
  "numInferenceSteps": 28,
  "imageOutputQuality": 90,
  "additionalLoraIntensity": 1
}

Expected Output

Upon successful execution, the action returns an array of image URLs, each corresponding to the generated images based on the input prompt.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/3074e4af-a90c-4a45-8840-dacec946be34/a68119a6-7645-4b73-9a17-c687c3e9f24b.png",
  "https://assets.cognitiveactions.com/invocations/3074e4af-a90c-4a45-8840-dacec946be34/6904f130-dce5-483d-b74b-b9848a62813f.png",
  "https://assets.cognitiveactions.com/invocations/3074e4af-a90c-4a45-8840-dacec946be34/a57eab9e-f022-4ae1-bce9-b4879c097b28.png",
  "https://assets.cognitiveactions.com/invocations/3074e4af-a90c-4a45-8840-dacec946be34/a9dde1b8-ffdc-4b9b-8688-78166c4c2649.png"
]

Use Cases for this Action

  • Creative Projects: Artists and designers can leverage this action to create unique artwork or illustrations based on specific themes or concepts.
  • Marketing Materials: Businesses can generate tailored images for advertisements, social media posts, or promotional content, ensuring their visuals stand out.
  • Game Development: Developers can create custom characters or environments, enhancing the gaming experience with unique visual elements.
  • Content Creation: Bloggers and content creators can generate images that align with their written content, improving engagement and aesthetic appeal.

```python
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "8372fb04-775a-4bad-be0b-ec11d51014ed" # Action ID for: Generate Image with Model

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "goFast": false,
  "prompt": "scraft1 is a thinner bald white man with beard and is seated in a well-lit, contemporary workspace that blends comfort with professionalism. He faces the camera directly, with a poised and composed demeanor. His expression is calm. His neatly groomed beard and clean-shaven scalp emphasize his polished appearance.\n\nHe is dressed in a fitted long sleeved black top, simple yet elegant, which contrasts sharply with the warm tones of the environment. Around his neck, a gold chain adds a touch of sophistication, catching the light subtly and drawing attention to his overall styling. wearing modern elegant black sunglasses\n\nThe camera captures scraft1 in a medium shot at eye level, with blue eyes, focusing on his upper body while leaning against the wall and allowing for a clear view of both his expression and the surrounding environment. The background features a dark black brick wall adorned with minimalistic decor, including small potted plants and wall-mounted lights that cast warm, soft glows. A set of furniture, including modern armchairs and tables, creates a cozy yet professional ambiance.\n\nThe lighting is warm and evenly diffused, blending natural daylight with artificial light sources. This balance enhances the texture of the wall and the metallic sheen of scraft1's chain, while subtly illuminating his facial features.\n\nThe mood of the image is thoughtful and inviting, striking a balance between professionalism and approachability. The minimalist design of the setting, paired with scraft1's calm demeanor and sleek outfit, creates a harmonious and engaging visual composition that conveys focus and modern sophistication.",
  "modelName": "dev",
  "guidanceScale": 3,
  "loraIntensity": 1,
  "numMegapixels": "1",
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "png",
  "numInferenceSteps": 28,
  "imageOutputQuality": 90,
  "additionalLoraIntensity": 1
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Conclusion
Scraft1's image generation action provides a powerful tool for developers seeking to create customized visuals quickly and efficiently. With options to adjust quality, speed, and specific parameters, this action is versatile enough to meet various creative needs. Start integrating Scraft1 into your projects today and unlock the potential of automated image generation!