tl-image
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTensorsLab 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 environment variable or in 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.)
TENSORSLAB_API_KEY~/.tensorslab/.envRun:
bash
python scripts/tensorslab_auth.pyThis will open a browser for authorization. Wait for "Authorization Successful!" before proceeding.
After authorization, the API key is stored in and you don't need to re-authorize unless the key expires.
~/.tensorslab/.env授权脚本会在执行前自动检查环境变量或文件中是否已存在API密钥。
(注意:验证环境变量时,仅需检查是否存在,绝对不能显示或打印实际的API密钥值。)
TENSORSLAB_API_KEY~/.tensorslab/.env运行:
bash
python scripts/tensorslab_auth.py该命令会打开浏览器进行授权。等待页面显示“Authorization Successful!”后再继续操作。
授权完成后,API密钥会存储在文件中,除非密钥过期,否则无需重复授权。
~/.tensorslab/.env2. 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:
- Direct the user to get their API Key at TensorsLab Console.
- Set the environment variable in the cloud environment.
TENSORSLAB_API_KEY
**当Agent或openclaw在无浏览器的云环境中运行时,URL授权方式也会失效。**这种情况下,必须指导用户手动获取API密钥并在云环境中进行配置:
- 引导用户前往 TensorsLab控制台 获取API密钥。
- 在云环境中设置环境变量。
TENSORSLAB_API_KEY
Models
模型
| Model | Description | Best For |
|---|---|---|
| seedreamv5 | Latest enhanced model | General purpose, highest quality |
| seedreamv4 | Standard model | Fast generation, good quality |
| zimage | Alternative model | Specific artistic styles |
| quickedit | Image instruction editing | Fast color/style/object editing |
Default:
seedreamv4| 模型 | 描述 | 最佳适用场景 |
|---|---|---|
| seedreamv5 | 最新增强版模型 | 通用场景,最高画质 |
| seedreamv4 | 标准模型 | 快速生成,画质优良 |
| zimage | 备选模型 | 特定艺术风格 |
| quickedit | 图片指令编辑模型 | 快速颜色/风格/物体编辑 |
默认模型:
seedreamv4Workflow
工作流
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 or
sourceImagefor text-to-image generation.imageUrl
Agent processing:
- Extract the core subject and action
- Enhance prompt with details (lighting, composition, style, atmosphere)
- Call API with enriched prompt
- Monitor progress with heartbeat updates
- 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处理流程:
- 提取核心主体和动作
- 为提示词添加细节(光线、构图、风格、氛围)进行优化
- 使用优化后的提示词调用API
- 通过心跳更新追踪生成进度
- 将结果下载至目录
./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 angle2. Image-to-Image Generation
2. 图片生成图片
User request: "把 cat.png 的背景换成太空" or "参考 sketch.png 渲染成 3D 模型"
Agent processing:
- Extract image file paths (absolute or relative to current directory)
- Enhance prompt with transformation instructions
- Upload source images with prompt
- Monitor and download results
Parameters for image-to-image:
- : Array of image files (for local upload)
sourceImage - : URL of source image (Must be a standard HTTP/HTTPS URL. Do NOT use local paths like /tmp/xxx.png here)
imageUrl - : Description of desired transformation
prompt
用户请求示例:"把 cat.png 的背景换成太空" 或 "参考 sketch.png 渲染成3D模型"
Agent处理流程:
- 提取图片文件路径(绝对路径或相对于当前目录的路径)
- 为提示词添加转换指令进行优化
- 上传源图片并携带优化后的提示词
- 追踪生成进度并下载结果
图片生成图片参数:
- : 本地图片文件数组(用于本地上传)
sourceImage - : 源图片的URL(必须是标准HTTP/HTTPS链接,请勿使用
imageUrl这类本地路径)/tmp/xxx.png - : 所需转换效果的描述
prompt
3. Image Editing (General Purpose)
3. 通用图片编辑
General-purpose editing for any local image modifications.
User request examples:
- "把这张图的天空改成日落色"
- "给人物加上墨镜"
- "把头发颜色染成粉色"
Agent processing:
- Extract image file path
- Parse the specific editing instruction (what to change, where)
- Build enhanced prompt with precise editing guidance
- Call API with source image and editing prompt
- 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 lineFor avatar generation, watermark removal, object erasure, and face replacement scenarios, see references/scenarios.md.
适用于任何本地图片的修改需求。
用户请求示例:
- "把这张图的天空改成日落色"
- "给人物加上墨镜"
- "把头发颜色染成粉色"
Agent处理流程:
- 提取图片文件路径
- 解析具体的编辑指令(修改内容、修改位置)
- 构建包含精准编辑指引的优化提示词
- 携带源图片和编辑提示词调用API
- 将结果保存至目录
./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:33:2 - Resolution levels: ,
2K4K - Specific dimensions: format (e.g.,
WxH,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:33:2 - 分辨率级别: ,
2K4K - 自定义尺寸: 格式(例如
WxH,2048x2048)1920x1080- 约束:总像素数必须在3,686,400到16,777,216之间
Using the Script
脚本使用方法
依赖:脚本需要和requests库,首次使用前执行:pyyamlbashpip install requests pyyaml
Execute the Python script directly:
bash
undefined依赖:脚本需要和requests库,首次使用前请执行:pyyamlbashpip install requests pyyaml
直接执行Python脚本:
bash
undefinedText-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
undefinedpython scripts/tensorslab_image.py "把主体改为蓝色" --source image.png --model quickedit
undefinedTask Status Flow
任务状态流转
| Status | Code | Meaning |
|---|---|---|
| Queued | 1 | Task waiting in queue |
| Processing | 2 | Currently generating |
| Completed | 3 | Done, images ready |
| Failed | 4 | Error occurred |
| 状态 | 代码 | 含义 |
|---|---|---|
| 排队中 | 1 | 任务等待处理 |
| 处理中 | 2 | 正在生成图片 |
| 已完成 | 3 | 生成完成,图片已就绪 |
| 失败 | 4 | 生成过程中出现错误 |
Error Handling
错误处理
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 |
将API错误转换为用户友好的提示信息:
| 错误码 | 含义 | 用户提示 |
|---|---|---|
| 9000 | 积分不足 | "亲,积分用完啦,请前往 https://tensorai.tensorslab.com/ 充值" |
| 9999 | 通用错误 | 显示具体的错误信息 |
Output
输出
All images are saved to output directory with naming pattern:
- Default: (current working directory)
./tensorslab_output/ - Custom: Use or
--output-dirto specify a different path-o - Naming: - e.g.,
{task_id}_{index}.{ext}abcd_1234567890_0.png
URL mapping: The script also saves file-to-URL mappings in . 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.
./tensorslab_output/urls.yamlyaml
undefined所有图片都会保存到指定的输出目录,命名规则如下:
- 默认目录:(当前工作目录)
./tensorslab_output/ - 自定义目录:使用或
--output-dir参数指定其他路径-o - 命名格式:- 例如
{task_id}_{index}.{ext}abcd_1234567890_0.png
URL映射:脚本还会在文件中保存文件与URL的映射关系。该文件会记录每个下载文件的原始URL,并在多次运行后累积记录。如需查看生成图片的原始URL,请读取此文件。
./tensorslab_output/urls.yamlyaml
undefinedExample urls.yaml content
urls.yaml示例内容
abcd_1234567890_0.png: https://tensorai.tensorslab.com/images/abcd_1234567890_0.png
abcd_1234567890_1.png: https://tensorai.tensorslab.com/images/abcd_1234567890_1.png
After completion, inform user:🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}
undefinedabcd_1234567890_0.png: https://tensorai.tensorslab.com/images/abcd_1234567890_0.png
abcd_1234567890_1.png: https://tensorai.tensorslab.com/images/abcd_1234567890_1.png
任务完成后,向用户提示:🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}
undefinedResources
资源
- 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: 高级使用场景(头像生成、水印移除、物体擦除、人脸替换)