tl-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前会自动优化用户的提示词,添加详细的视觉描述,确保生成高质量的输出。

Authorization

授权

BEFORE any image generation, you must ensure you are authorized with TensorsLab.
在进行任何图片生成操作前,必须确保已完成TensorsLab的授权。

1. Automatic Authorization

1. 自动授权

The authorization script will automatically check if an API key already exists in the
TENSORSLAB_API_KEY
environment variable or in
~/.tensorslab/.env
before proceeding. (Note: When you need to verify the environment variable, ONLY check if it exists. NEVER display or print the actual API key value.)
Run:
bash
python scripts/tensorslab_auth.py
This will open a browser for authorization. Wait for "Authorization Successful!" before proceeding.
After authorization, the API key is stored in
~/.tensorslab/.env
and you don't need to re-authorize unless the key expires.
授权脚本会在执行前自动检查
TENSORSLAB_API_KEY
环境变量或
~/.tensorslab/.env
文件中是否已存在API密钥。 (注意:验证环境变量时,仅需检查是否存在,绝对不能显示或打印实际的API密钥值。)
运行:
bash
python scripts/tensorslab_auth.py
该命令会打开浏览器进行授权。等待页面显示“Authorization Successful!”后再继续操作。
授权完成后,API密钥会存储在
~/.tensorslab/.env
文件中,除非密钥过期,否则无需重复授权。

2. Manual Configuration (For Cloud/Headless Environments)

2. 手动配置(适用于云环境/无界面环境)

When the agent or openclaw operates in a cloud environment without a browser, the URL authorization method will also fail. In this scenario, you must instruct the user to manually acquire their API key and configure it in the cloud environment:
  1. Direct the user to get their API Key at TensorsLab Console.
  2. Set the
    TENSORSLAB_API_KEY
    environment variable in the cloud environment.
**当Agent或openclaw在无浏览器的云环境中运行时,URL授权方式也会失效。**这种情况下,必须指导用户手动获取API密钥并在云环境中进行配置:
  1. 引导用户前往 TensorsLab控制台 获取API密钥。
  2. 在云环境中设置
    TENSORSLAB_API_KEY
    环境变量。

Models

模型

ModelDescriptionBest For
seedreamv5Latest enhanced modelGeneral purpose, highest quality
seedreamv4Standard modelFast generation, good quality
zimageAlternative modelSpecific artistic styles
quickeditImage instruction editingFast color/style/object editing
Default:
seedreamv4
模型描述最佳适用场景
seedreamv5最新增强版模型通用场景,最高画质
seedreamv4标准模型快速生成,画质优良
zimage备选模型特定艺术风格
quickedit图片指令编辑模型快速颜色/风格/物体编辑
默认模型:
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: "画一个在月球上吃热狗的宇航员"
Constraints:
  • Do NOT pass
    sourceImage
    or
    imageUrl
    for text-to-image generation.
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
用户请求示例:"画一个在月球上吃热狗的宇航员"
约束:
  • 文本生成图片时,请勿传入
    sourceImage
    imageUrl
    参数。
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 (Must be a standard HTTP/HTTPS URL. Do NOT use local paths like /tmp/xxx.png here)
  • prompt
    : Description of desired transformation
用户请求示例:"把 cat.png 的背景换成太空" 或 "参考 sketch.png 渲染成3D模型"
Agent处理流程:
  1. 提取图片文件路径(绝对路径或相对于当前目录的路径)
  2. 为提示词添加转换指令进行优化
  3. 上传源图片并携带优化后的提示词
  4. 追踪生成进度并下载结果
图片生成图片参数:
  • sourceImage
    : 本地图片文件数组(用于本地上传)
  • imageUrl
    : 源图片的URL(必须是标准HTTP/HTTPS链接,请勿使用
    /tmp/xxx.png
    这类本地路径)
  • 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

脚本使用方法

依赖:脚本需要
requests
pyyaml
库,首次使用前执行:
bash
pip install requests pyyaml
Execute the Python script directly:
bash
undefined
依赖:脚本需要
requests
pyyaml
库,首次使用前请执行:
bash
pip install requests pyyaml
直接执行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 with local file

本地图片生成图片

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

Image-to-image with URL

在线图片生成图片

python scripts/tensorslab_image.py "watercolor style" --image-url https://example.com/cat.jpg
python scripts/tensorslab_image.py "watercolor style" --image-url https://example.com/cat.jpg

Specify model

指定模型

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

Custom output directory

自定义输出目录

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

Quick editing (Fast instructions)

快速编辑(快速指令)

python scripts/tensorslab_image.py "把主体改为蓝色" --source image.png --model quickedit
undefined
python scripts/tensorslab_image.py "把主体改为蓝色" --source image.png --model quickedit
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://tensorai.tensorslab.com"/ 充值"
9999General errorShow the specific error message
将API错误转换为用户友好的提示信息:
错误码含义用户提示
9000积分不足"亲,积分用完啦,请前往 https://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
URL mapping: The script also saves file-to-URL mappings in
./tensorslab_output/urls.yaml
. This file tracks the original URLs for each downloaded file and accumulates entries across multiple runs. When you need the original URL of a generated image, read this file.
yaml
undefined
所有图片都会保存到指定的输出目录,命名规则如下:
  • 默认目录:
    ./tensorslab_output/
    (当前工作目录)
  • 自定义目录:使用
    --output-dir
    -o
    参数指定其他路径
  • 命名格式:
    {task_id}_{index}.{ext}
    - 例如
    abcd_1234567890_0.png
URL映射:脚本还会在
./tensorslab_output/urls.yaml
文件中保存文件与URL的映射关系。该文件会记录每个下载文件的原始URL,并在多次运行后累积记录。如需查看生成图片的原始URL,请读取此文件。
yaml
undefined

Example urls.yaml content

urls.yaml示例内容


After completion, inform user:
🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}
undefined

任务完成后,向用户提示:
🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}
undefined

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: 高级使用场景(头像生成、水印移除、物体擦除、人脸替换)