Create Stunning Images from Chinese Text Prompts with Taiyi Stable Diffusion

26 Apr 2025
Create Stunning Images from Chinese Text Prompts with Taiyi Stable Diffusion

In today's digital landscape, the ability to generate high-quality images from text prompts can revolutionize content creation, marketing, and artistic expression. The Taiyi Stable Diffusion 1b Chinese V0.1 model offers developers a powerful tool to create visually compelling images based on Chinese text inputs. This open-source image generation model has been trained on a vast dataset of 20 million filtered Chinese image-text pairs, making it uniquely capable of producing images that accurately reflect Chinese concepts and cultural nuances.

By leveraging this model, developers can automate image creation, enhance user engagement, and streamline workflows across various applications. Whether you're building a digital art platform, enhancing e-commerce product listings, or creating educational content, Taiyi Stable Diffusion provides a versatile solution for generating images that resonate with Chinese-speaking audiences.

Prerequisites

To get started with the Taiyi Stable Diffusion API, you'll need an API key for Cognitive Actions and a basic understanding of how to make API calls.

Generate Chinese Image using Taiyi-Stable-Diffusion

The primary action within the Taiyi Stable Diffusion suite is the capability to generate images based on Chinese text prompts. This action serves a crucial role in transforming textual descriptions into vivid visuals, thus bridging the gap between language and imagery.

Purpose

The "Generate Chinese Image using Taiyi-Stable-Diffusion" action allows developers to create high-quality images that are aligned with Chinese text prompts. This is particularly beneficial for applications targeting Chinese-speaking markets or those that wish to incorporate Chinese cultural elements into their visual content.

Input Requirements

To utilize this action, the following parameters are required:

  • Prompt: The text prompt that guides the image generation (e.g., "飞流直下三千尺,油画").
  • Width: The desired width of the output image (options include 128, 256, 512, 640, 768, 896, 1024).
  • Height: The desired height of the output image (same options as width).
  • Number of Outputs: Specify how many images to generate (1 or 4).
  • Number of Inference Steps: The number of denoising steps during inference (ranging from 1 to 500).
  • Guidance Scale: A value that influences the image generation process (default is 7.5, range from 1 to 20).
  • Scheduler: The algorithm used during image generation (e.g., "DPMSolverMultistep").
  • Seed: An optional parameter for random seed generation.
  • Negative Prompt: Optional text specifying unwanted features in the image.

Expected Output

The expected output is a high-quality image represented by a URL where the generated image can be accessed. For instance, after providing a prompt and other parameters, the output might be a link similar to:

https://assets.cognitiveactions.com/invocations/d31df825-9a76-46e3-8e9a-dd0d4e5c6ef9/ff6f525f-dc47-41e2-bf80-07a8aa328beb.png

Use Cases for this Action

  • Digital Art Creation: Artists can use this action to quickly visualize their ideas based on textual descriptions, enabling rapid prototyping of art pieces.
  • E-commerce: Businesses can generate product images from descriptions, allowing for quick catalog updates and enhancing visual storytelling.
  • Education: Educators can create illustrations for educational materials that align with Chinese language content, making learning more engaging.
  • Social Media Content: Marketers can generate eye-catching visuals for campaigns, tailored specifically for Chinese-speaking audiences.
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 = "6df714f1-f06a-43dd-a5ba-7936b993bcc5" # Action ID for: Generate Chinese Image using Taiyi-Stable-Diffusion

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 512,
  "height": 512,
  "prompt": "飞流直下三千尺,油画",
  "scheduler": "DPMSolverMultistep",
  "guidanceScale": 7.5,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 50
}

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 Taiyi Stable Diffusion 1b Chinese V0.1 model offers developers an innovative way to generate stunning images from Chinese text prompts. By simplifying the image creation process, this model opens up new possibilities for various applications, from digital art to e-commerce. As you explore this tool, consider how it can enhance your projects and engage your audience in meaningful ways. Start integrating this powerful image generation capability into your applications today!