Create Stunning Images from Prompts with Miya Captioned

25 Apr 2025
Create Stunning Images from Prompts with Miya Captioned

In the world of digital creativity, the ability to generate images from simple text prompts has revolutionized how developers and artists approach design. The Miya Captioned service offers a powerful Cognitive Action called "Generate Image from Prompt," enabling users to create stunning visuals tailored to specific narratives. This service not only simplifies the image creation process but also enhances productivity by allowing for rapid prototyping and iteration.

Imagine being able to input a detailed description and receive a unique image that embodies that vision. Whether you’re developing content for marketing, creating assets for games, or designing artwork, this action provides an efficient way to bring your ideas to life. With options for customization and optimization, it caters to a wide range of creative needs.

Prerequisites

Before getting started with Miya Captioned, ensure you have an API key for Cognitive Actions and a basic understanding of making API calls.

Generate Image from Prompt

The "Generate Image from Prompt" action is designed to create images based on user-defined text prompts. This operation supports advanced features like image inpainting and customization of image properties such as aspect ratio, width, height, and format. It solves the problem of needing unique, tailored visuals without requiring extensive graphic design skills.

Input Requirements

To use this action, you must provide a prompt that guides the image generation, along with optional parameters that can refine the output. Here are the key inputs:

  • prompt: A descriptive text that guides the image creation (required).
  • mask: A URI for an image mask used in inpainting mode.
  • seed: An integer for random number generation to ensure consistent outputs.
  • image: A URI of an input image for modifications.
  • width and height: Dimensions for the generated image (applicable for custom aspect ratios).
  • aspectRatio: Choose from predefined ratios or specify a custom size.
  • outputFormat: Format of the generated image (e.g., webp, jpg).
  • Additional parameters for customization and optimization, including guidance scale, output quality, and more.

Expected Output

The action will return a set of image URLs based on the prompt and specified parameters. For example, you might receive multiple images that reflect different interpretations of the same prompt.

Example Output:

  • https://assets.cognitiveactions.com/.../image1.webp
  • https://assets.cognitiveactions.com/.../image2.webp
  • https://assets.cognitiveactions.com/.../image3.webp
  • https://assets.cognitiveactions.com/.../image4.webp

Use Cases for this Specific Action

This action is particularly useful in various scenarios, including:

  • Marketing and Advertising: Create unique visuals for campaigns based on specific themes or products.
  • Game Development: Generate concept art or assets that align with game narratives.
  • Content Creation: Produce illustrations for blog posts, articles, or social media content without needing graphic design expertise.
  • Art Projects: Experiment with different artistic styles and concepts quickly.

The flexibility of adjusting parameters such as guidance scale and output quality allows developers to fine-tune the results to fit their specific needs.

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 = "031b0726-8ce6-4239-b6ec-275e04b4eb49" # Action ID for: Generate Image from Prompt

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "In the style of MIYAC, a young girl and young boy skip across stones in a gurgling creek surrounded by a thick, lush green forest with tall trees. They are walking from the left to right across the creek, facing towards the right of the shot. The girl is in front of the boy.",
  "loraScale": 1,
  "numOutputs": 4,
  "aspectRatio": "16:9",
  "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",
    # 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

Miya Captioned's "Generate Image from Prompt" action empowers developers and creatives to produce high-quality images effortlessly. By leveraging this service, you can accelerate your creative processes, explore different visual styles, and generate tailored content that resonates with your audience. Whether for professional projects or personal experimentation, this tool opens up new horizons in digital creativity.

Take the next step in your development journey by integrating Miya Captioned and unlock the full potential of AI-driven image creation!