Create Stunning Images from Text Prompts with Ranveersingh

25 Apr 2025
Create Stunning Images from Text Prompts with Ranveersingh

In today's digital landscape, the ability to generate high-quality images from textual prompts is transforming creative workflows across various industries. The Ranveersingh API offers a powerful Cognitive Action that allows developers to create stunning visuals based on user-defined descriptions. By leveraging advanced image generation models, this service simplifies the process of visual content creation, enabling quick and efficient production of images tailored to specific needs.

Imagine a scenario where a marketing team needs unique visuals for a campaign. Instead of relying on stock images or hiring a designer, they can input a descriptive prompt into the Ranveersingh API and receive custom images that align perfectly with their vision. This capability not only saves time but also enhances the creativity and personalization of content.

Prerequisites

To get started with the Ranveersingh API, you will need a Cognitive Actions API key and a basic understanding of making API calls.

Generate Image from Prompt

The Generate Image from Prompt action is designed to produce high-quality images based on textual prompts provided by the user. This action addresses the challenge of creating tailored visual content quickly and efficiently.

Purpose

This action allows users to generate images using either the 'dev' model for detailed outputs that take approximately 28 steps or the 'schnell' model for quick results in just 4 steps. Developers can customize the image output by adjusting various parameters such as width, height, aspect ratio, and image quality.

Input Requirements

The input for this action requires a JSON object that includes the following fields:

  • prompt (required): A textual description for the image generation.
  • Optional parameters such as width, height, imageFormat, and others to customize the output.

Example input:

{
  "goFast": false,
  "prompt": "a photo of RS wearing a black jacket with long black hair with a burning motorcycle in the background",
  "loraScale": 1,
  "numOutputs": 1,
  "imageFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageResolution": "1",
  "imageAspectRatio": "1:1",
  "numInferenceSteps": 28
}

Expected Output

The output will be a URL link to the generated image, which can be accessed and utilized in various applications.

Example output:

[
  "https://assets.cognitiveactions.com/invocations/e82b0392-603a-4351-94d3-67f0c301872d/8be41937-d62a-4b23-9b36-d07839a02806.webp"
]

Use Cases for this Specific Action

  • Marketing and Advertising: Create bespoke visuals for campaigns directly from descriptive text, streamlining the creative process.
  • Content Creation: Bloggers and social media managers can generate unique images that resonate with their audience without needing design skills.
  • Gaming and Entertainment: Game developers can quickly produce concept art or assets based on narrative descriptions, enhancing their creative iterations.
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 = "1f08cd7d-da22-4da6-9897-dad291b382b6" # 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 = {
  "goFast": false,
  "prompt": "a photo of RS wearing a black jacket with long black hair with a burning motorcycle in the backgrounf",
  "loraScale": 1,
  "numOutputs": 1,
  "imageFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageResolution": "1",
  "imageAspectRatio": "1:1",
  "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

The Ranveersingh API's ability to generate images from text prompts is a game-changer for developers looking to enhance their applications with custom visuals. By simplifying the image creation process, this API opens up a world of possibilities for various industries, including marketing, content creation, and entertainment.

To leverage this powerful tool, developers should explore the different parameters available and consider how they can integrate these capabilities into their projects to provide users with a seamless and innovative experience.