Create Stunning Images of Old Books with the razvanmtn/old-books-model Cognitive Actions

24 Apr 2025
Create Stunning Images of Old Books with the razvanmtn/old-books-model Cognitive Actions

In the rapidly evolving world of AI, the ability to generate realistic images can greatly enhance applications across various domains, from publishing to e-commerce. The razvanmtn/old-books-model provides a powerful Cognitive Action that allows developers to create detailed images of old books. This action not only produces high-quality results but also offers customization options for various image attributes, making it an invaluable tool for developers aiming to enrich their applications with visually appealing content.

Prerequisites

To access and utilize the Cognitive Actions, you'll need an API key from the Cognitive Actions platform. This key will be used for authentication when making requests. Typically, you will pass this key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Old Book Images

The Generate Old Book Images action creates detailed images of old books based on a textual prompt. This action is particularly beneficial for applications that require realistic depictions of vintage literature, enhancing the visual storytelling aspect of the content.

  • Category: Image Generation

Input

The action requires a JSON object with the following properties:

  • prompt (required): A textual description of the image you want to generate. For example: "OLDBOOK book with warned covers, dark, wooden table top, earthy colors".
  • mask (optional): A URI for an image mask used in inpainting mode.
  • seed (optional): An integer for random number generation.
  • image (optional): A URI for an input image used in image-to-image or inpainting modes.
  • width (optional): Width of the generated image (256 to 1440 pixels).
  • height (optional): Height of the generated image (256 to 1440 pixels).
  • goFast (optional): A boolean to enable faster predictions.
  • aspectRatio (optional): Controls the aspect ratio of the generated image, with options like "1:1" or "16:9".
  • numOutputs (optional): The number of images to generate (1 to 4).
  • outputFormat (optional): Format of the output images, such as "webp" or "jpg".
  • guidanceScale (optional): A scale parameter for image realism (0 to 10).
  • outputQuality (optional): Compression quality for the images (0 to 100).
  • inferenceModel (optional): Specifies the inference model to use.

Example Input:

{
  "prompt": "OLDBOOK book with warned covers, dark, wooden table top, earthy colors",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Output

Upon successful execution, the action returns a list containing URLs of the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/5ecc67fe-a47a-4783-b86d-4f68f4265511/088d2462-06c1-49fb-bbf5-cc2ff9634df9.webp"
]

Conceptual Usage Example (Python)

Here’s how you could implement the Generate Old Book Images action in your application using Python:

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 = "0978812a-5e9b-4055-9f53-67945379dc4d"  # Action ID for Generate Old Book Images

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "OLDBOOK book with warned covers, dark, wooden table top, earthy colors",
    "loraScale": 1,
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "numInferenceSteps": 28
}

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, remember to replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is constructed to meet the action's requirements, and the response is handled to fetch the generated image URLs.

Conclusion

The razvanmtn/old-books-model Cognitive Actions provide an excellent opportunity for developers to create captivating images of old books, enhancing applications with visually rich content. With its customizable features, developers can fine-tune the image generation to match their specific needs. Start exploring these capabilities today and elevate your application’s visual storytelling!