Generate and edit images using TensorsLab's AI models. Supports text-to-image, image-to-image generation, plus advanced editing: avatar generation, watermark removal, object erasure, face replacement, and general image editing. Features automatic prompt enhancement, progress tracking, and local file saving. Requires TENSORSLAB_API_KEY environment variable.
This skill enables AI-powered image generation through TensorsLab's API, supporting both text-to-image and image-to-image workflows. The agent enhances user prompts with detailed visual descriptions before calling the API, ensuring high-quality outputs.
Before any image generation, verify the API key is configured:
# 仅检查变量是否存在,不输出完整值
[ -n "$TENSORSLAB_API_KEY" ] && echo "✅ API key is set" || echo "❌ TENSORSLAB_API_KEY is not set"
If not set, display this friendly message:
您好!要生成高质量的内容,您需要先进行简单的配置:
1. 访问 https://tensorai.tensorslab.com/ 登录并订阅。
2. 在控制台中获取您的专属 API Key。
3. 将其保存为环境变量:
- Windows (PowerShell): $env:TENSORSLAB_API_KEY="您的Key"
- Mac/Linux: export TENSORSLAB_API_KEY="您的Key"
| Model | Description | Best For |
|---|---|---|
| seedreamv45 | Latest enhanced model | General purpose, highest quality |
| seedreamv4 | Standard model | Fast generation, good quality |
| zimage | Alternative model | Specific artistic styles |
Default: seedreamv4
For additional scenarios beyond basic generation (avatar generation, watermark removal, object erasure, face replacement), see references/scenarios.md.
User request: "画一个在月球上吃热狗的宇航员"
Agent processing:
./tensorslab_output/Example enhanced prompt:
An astronaut sitting on the lunar surface, eating a hot dog with mustard,
cinematic lighting, Earth visible in the background, highly detailed,
photorealistic, 8k quality, dramatic shadows from the low sun angle
User request: "把 cat.png 的背景换成太空" or "参考 sketch.png 渲染成 3D 模型"
Agent processing:
Parameters for image-to-image:
sourceImage: Array of image files (for local upload)imageUrl: URL of source imageprompt: Description of desired transformationGeneral-purpose editing for any local image modifications.
User request examples:
Agent processing:
./tensorslab_output/Example enhanced prompt:
Change the sky to sunset colors with warm orange and pink gradients,
matching the existing lighting conditions and atmospheric perspective,
seamless blend at the horizon line
For avatar generation, watermark removal, object erasure, and face replacement scenarios, see references/scenarios.md.
Supported formats:
9:16, 16:9, 3:4, 4:3, 1:1, 2:3, 3:22K, 4KWxH format (e.g., 2048x2048, 1920x1080)
依赖:脚本需要
requests库,首次使用前执行:pip install requests
Execute the Python script directly:
# Text-to-image
python scripts/tensorslab_image.py "a cat on the moon"
# With specific resolution
python scripts/tensorslab_image.py "sunset over mountains" --resolution 16:9
# Image-to-image
python scripts/tensorslab_image.py "watercolor style" --source cat.png
# Specify model
python scripts/tensorslab_image.py "cyberpunk city" --model seedreamv45
# Custom output directory
python scripts/tensorslab_image.py "a beautiful landscape" --output-dir ./my_images
| Status | Code | Meaning |
|---|---|---|
| Queued | 1 | Task waiting in queue |
| Processing | 2 | Currently generating |
| Completed | 3 | Done, images ready |
| Failed | 4 | Error occurred |
Translate API errors to user-friendly messages:
| Error Code | Meaning | User Message |
|---|---|---|
| 9000 | Insufficient credits | "亲,积分用完啦,请前往 https://tensorai.tensorslab.com"/ 充值" |
| 9999 | General error | Show the specific error message |
All images are saved to output directory with naming pattern:
./tensorslab_output/ (current working directory)--output-dir or -o to specify a different path{task_id}_{index}.{ext} - e.g., abcd_1234567890_0.pngAfter completion, inform user:
🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}