tensorslab-image

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TensorsLab Image Generation

TensorsLab 图片生成

Overview

概述

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.
该Skill通过TensorsLab的API实现基于AI的图片生成,支持文本转图片和图片转图片两种工作流程。Agent在调用API前会为用户的提示词补充详细的视觉描述,确保生成高质量的输出结果。

Authentication Check

身份验证检查

Before any image generation, verify the API key is configured:
bash
undefined
在进行任何图片生成操作前,请先验证是否已配置API密钥:
bash
undefined

Check if API key is set

检查是否已设置API密钥

echo $TENSORSLAB_API_KEY

If not set, display this friendly message:
您好!要生成高质量的内容,您需要先进行简单的配置:
  1. 访问 https://test.tensorai.tensorslab.com/ 登录并订阅。
  2. 在控制台中获取您的专属 API Key。
  3. 将其保存为环境变量:
    • Windows (PowerShell): $env:TENSORSLAB_API_KEY="您的Key"
    • Mac/Linux: export TENSORSLAB_API_KEY="您的Key"
undefined
echo $TENSORSLAB_API_KEY

如果未设置,显示以下友好提示:
您好!要生成高质量的内容,您需要先进行简单的配置:
  1. 访问 https://test.tensorai.tensorslab.com/ 登录并订阅。
  2. 在控制台中获取您的专属 API Key。
  3. 将其保存为环境变量:
    • Windows (PowerShell): $env:TENSORSLAB_API_KEY="您的Key"
    • Mac/Linux: export TENSORSLAB_API_KEY="您的Key"
undefined

Models

模型

ModelDescriptionBest For
seedreamv45Latest enhanced modelGeneral purpose, highest quality
seedreamv4Standard modelFast generation, good quality
zimageAlternative modelSpecific artistic styles
Default:
seedreamv4
模型描述适用场景
seedreamv45最新增强版模型通用场景,最高画质
seedreamv4标准版模型生成速度快,画质优良
zimage替代模型特定艺术风格
默认模型:
seedreamv4

Workflow

工作流程

For additional scenarios beyond basic generation (avatar generation, watermark removal, object erasure, face replacement), see references/scenarios.md.
除基础生成外的其他场景(头像生成、水印去除、物体擦除、人脸替换),请查看references/scenarios.md

1. Text-to-Image Generation

1. 文本转图片生成

User request: "画一个在月球上吃热狗的宇航员"
Agent processing:
  1. Extract the core subject and action
  2. Enhance prompt with details (lighting, composition, style, atmosphere)
  3. Call API with enriched prompt
  4. Monitor progress with heartbeat updates
  5. Download to
    ./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
用户请求:"画一个在月球上吃热狗的宇航员"
Agent处理过程:
  1. 提取核心主体和动作
  2. 为提示词补充细节(光线、构图、风格、氛围)
  3. 使用优化后的提示词调用API
  4. 通过心跳更新跟踪进度
  5. 下载至
    ./tensorslab_output/
优化后提示词示例:
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

2. Image-to-Image Generation

2. 图片转图片生成

User request: "把 cat.png 的背景换成太空" or "参考 sketch.png 渲染成 3D 模型"
Agent processing:
  1. Extract image file paths (absolute or relative to current directory)
  2. Enhance prompt with transformation instructions
  3. Upload source images with prompt
  4. Monitor and download results
Parameters for image-to-image:
  • sourceImage
    : Array of image files (for local upload)
  • imageUrl
    : URL of source image
  • prompt
    : Description of desired transformation
用户请求:"把 cat.png 的背景换成太空" 或 "参考 sketch.png 渲染成 3D 模型"
Agent处理过程:
  1. 提取图片文件路径(绝对路径或相对于当前目录的路径)
  2. 为提示词补充转换说明
  3. 上传源图片并附带提示词
  4. 跟踪进度并下载结果
图片转图片参数:
  • sourceImage
    : 图片文件数组(用于本地上传)
  • imageUrl
    : 源图片的URL
  • prompt
    : 期望转换效果的描述

3. Image Editing (General Purpose)

3. 通用图片编辑

General-purpose editing for any local image modifications.
User request examples:
  • "把这张图的天空改成日落色"
  • "给人物加上墨镜"
  • "把头发颜色染成粉色"
Agent processing:
  1. Extract image file path
  2. Parse the specific editing instruction (what to change, where)
  3. Build enhanced prompt with precise editing guidance
  4. Call API with source image and editing prompt
  5. Save result to
    ./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.
适用于任何本地图片的修改需求。
用户请求示例:
  • "把这张图的天空改成日落色"
  • "给人物加上墨镜"
  • "把头发颜色染成粉色"
Agent处理过程:
  1. 提取图片文件路径
  2. 解析具体的编辑指令(修改内容、位置)
  3. 构建包含精准编辑指引的优化提示词
  4. 携带源图片和编辑提示词调用API
  5. 将结果保存至
    ./tensorslab_output/
优化后提示词示例:
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
头像生成、水印去除、物体擦除、人脸替换等场景,请查看references/scenarios.md

4. Resolution Options

4. 分辨率选项

Supported formats:
  • Aspect ratios:
    9:16
    ,
    16:9
    ,
    3:4
    ,
    4:3
    ,
    1:1
    ,
    2:3
    ,
    3:2
  • Resolution levels:
    2K
    ,
    4K
  • Specific dimensions:
    WxH
    format (e.g.,
    2048x2048
    ,
    1920x1080
    )
    • Constraint: Total pixels must be between 3,686,400 and 16,777,216
支持的格式:
  • 宽高比:
    9:16
    ,
    16:9
    ,
    3:4
    ,
    4:3
    ,
    1:1
    ,
    2:3
    ,
    3:2
  • 分辨率级别:
    2K
    ,
    4K
  • 自定义尺寸:
    WxH
    格式(例如:
    2048x2048
    ,
    1920x1080
    • 限制条件:总像素数必须在3,686,400到16,777,216之间

Using the Script

脚本使用方法

Execute the Python script directly:
bash
undefined
直接执行Python脚本:
bash
undefined

Text-to-image

文本转图片

python scripts/tensorslab_image.py "a cat on the moon"
python scripts/tensorslab_image.py "a cat on the moon"

With specific resolution

指定分辨率

python scripts/tensorslab_image.py "sunset over mountains" --resolution 16:9
python scripts/tensorslab_image.py "sunset over mountains" --resolution 16:9

Image-to-image

图片转图片

python scripts/tensorslab_image.py "watercolor style" --source cat.png
python scripts/tensorslab_image.py "watercolor style" --source cat.png

Specify model

指定模型

python scripts/tensorslab_image.py "cyberpunk city" --model seedreamv45
python scripts/tensorslab_image.py "cyberpunk city" --model seedreamv45

Custom output directory

自定义输出目录

python scripts/tensorslab_image.py "a beautiful landscape" --output-dir ./my_images
undefined
python scripts/tensorslab_image.py "a beautiful landscape" --output-dir ./my_images
undefined

Task Status Flow

任务状态流程

StatusCodeMeaning
Queued1Task waiting in queue
Processing2Currently generating
Completed3Done, images ready
Failed4Error occurred
状态代码含义
排队中1任务等待处理
处理中2正在生成
已完成3生成完成,图片就绪
失败4发生错误

Error Handling

错误处理

Translate API errors to user-friendly messages:
Error CodeMeaningUser Message
9000Insufficient credits"亲,积分用完啦,请前往 https://test.tensorai.tensorslab.com"/ 充值"
9999General errorShow the specific error message
将API错误转换为用户友好的提示信息:
错误代码含义用户提示
9000积分不足"亲,积分用完啦,请前往 https://test.tensorai.tensorslab.com/ 充值"
9999通用错误显示具体错误信息

Output

输出

All images are saved to output directory with naming pattern:
  • Default:
    ./tensorslab_output/
    (current working directory)
  • Custom: Use
    --output-dir
    or
    -o
    to specify a different path
  • Naming:
    {task_id}_{index}.{ext}
    - e.g.,
    abcd_1234567890_0.png
After completion, inform user:
🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}
所有图片将保存至输出目录,命名规则如下:
  • 默认路径:
    ./tensorslab_output/
    (当前工作目录)
  • 自定义路径:使用
    --output-dir
    -o
    指定其他路径
  • 命名格式:
    {task_id}_{index}.{ext}
    - 例如:
    abcd_1234567890_0.png
生成完成后,将向用户提示:
🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}

Resources

资源

  • scripts/tensorslab_image.py: Main API client with full CLI support
  • references/api_reference.md: Detailed API documentation
  • references/scenarios.md: Advanced usage scenarios (avatar generation, watermark removal, object erasure, face replacement)
  • scripts/tensorslab_image.py: 完整支持CLI的主API客户端
  • references/api_reference.md: 详细的API文档
  • references/scenarios.md: 高级使用场景(头像生成、水印去除、物体擦除、人脸替换)