Create Stunning Images with Predictive Technology Using Jan

25 Apr 2025
Create Stunning Images with Predictive Technology Using Jan

Jan provides developers with a powerful API for generating images through advanced predictive techniques. By leveraging image inpainting, custom aspect ratios, and a range of output formats, Jan simplifies the process of creating high-quality, realistic images. Whether you're looking to enhance your applications with unique visuals or automate image generation for creative projects, Jan offers the tools you need to bring your ideas to life quickly and efficiently.

Use Cases

  • Marketing & Advertising: Generate custom images tailored to specific campaigns, allowing for rapid iteration and testing of visual content.
  • Game Development: Create unique character designs or environments through image generation, reducing the need for manual artwork.
  • E-commerce: Produce product images with custom backgrounds or settings to enhance online listings and attract customers.
  • Creative Projects: Enable artists and designers to visualize concepts quickly, using AI-generated images as a foundation for further development.

Prerequisites

To use Jan's Cognitive Actions, you will need an API key and a basic understanding of making API calls.

Generate Image with Prediction

The "Generate Image with Prediction" action allows for the creation of images by employing sophisticated prediction techniques. This action is particularly useful for tasks that require image inpainting, where parts of an image are filled in based on contextual understanding. The action supports various features, including mask-based inpainting, LoRA adjustments, and guidance scale tuning, ensuring flexibility and high-quality results.

  • Input Requirements:
    • Prompt: A descriptive text that guides the image generation.
    • Mask: An optional image mask for inpainting.
    • Image: An optional input image for image-to-image generation.
    • Model: Choose between "dev" or "schnell" models based on your needs.
    • Width & Height: Set custom dimensions if using a custom aspect ratio.
    • Output Count: Specify the number of images to generate (1 to 4).
    • Output Format: Choose from "webp", "jpg", or "png".
    • Additional parameters: Include settings for guidance scale, output quality, and LoRA scales.
  • Expected Output: The output will be a high-quality image generated based on the provided prompt and specifications. The result will be returned in the chosen format.

Use Cases for this Action

  • Art Generation: Use this action to create original artwork based on textual descriptions, perfect for artists looking to explore new styles.
  • Content Creation: Automatically generate images for blog posts or social media, saving time and effort in sourcing visuals.
  • Prototyping: Quickly visualize ideas and concepts in various styles, helping teams iterate faster during the design process.

```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 = "046c79ba-4f28-458b-95ae-b45152a0390d" # Action ID for: Generate Image with Prediction

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "model": "dev",
  "prompt": "Janice  is not wearing glasses, she is sitting on a white box in the studio wearing a white blouse & black pants talking to customers with one leg hanging down and one leg tucked under her & she is holding a camera on her lap",
  "loraScale": 1,
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "enableFastMode": false,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "imageAspectRatio": "1:1",
  "inferenceStepCount": 28
}

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
Jan's image generation capabilities empower developers to create stunning and unique visuals with ease. By integrating this action into your applications, you can enhance user experiences, streamline creative processes, and bring innovative ideas to fruition. Start exploring Jan today to unlock new possibilities in image creation and design!