jacky3102 commited on
Commit
e37b904
·
verified ·
1 Parent(s): a575d28

Deploy Blender Headless API

Browse files
Files changed (1) hide show
  1. README.md +91 -15
README.md CHANGED
@@ -1,28 +1,104 @@
1
  ---
2
- title: Chinese To Malay Video Dubber CPU
3
- emoji: 🎬
4
  colorFrom: blue
5
- colorTo: green
6
  sdk: docker
7
- app_file: app.py
8
  pinned: false
9
  ---
10
 
11
- # Chinese → Bahasa Melayu Video Dubber — CPU Basic
12
 
13
- Designed for Hugging Face Spaces CPU Basic (2 vCPU / 16 GB RAM).
 
 
 
14
 
15
- Pipeline:
16
 
17
- Chinese MP4 → Whisper Small → Chinese → Malay translation → Meta MMS Malay TTS → FFmpeg → Malay MP4
 
 
 
 
 
 
 
18
 
19
- Models:
20
- - `openai/whisper-large-v3-turbo`
21
- - `Helsinki-NLP/opus-mt-zh-ms`
22
- - `facebook/mms-tts-zlm`
23
 
24
- This version does not clone the original speaker's voice. It is intentionally lightweight for CPU Basic.
 
25
 
26
- Recommended test: 1–3 minute videos. Longer videos can take a long time on CPU.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- FFmpeg/ffprobe are required by the Space runtime.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Blender Headless API
3
+ emoji: 🦖
4
  colorFrom: blue
5
+ colorTo: purple
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
  ---
10
 
11
+ # Blender Headless API
12
 
13
+ 在 Hugging Face Space(CPU basic)上跑一个常驻的 FastAPI 服务,
14
+ 每次请求用 `blender --background --python worker.py` 无头执行一组
15
+ 白名单 3D 操作(建模 / 材质 / 灯光 / 相机 / 动画 / 渲染 / 导出),
16
+ 供 OpenClaw Agent 通过 HTTP 调用。
17
 
18
+ ## 目录结构
19
 
20
+ ```
21
+ .
22
+ ├── Dockerfile # 安装 Blender + 启动 FastAPI
23
+ ├── requirements.txt
24
+ ├── app.py # FastAPI 服务,接收请求,拉起 blender 子进程
25
+ ├── worker.py # 运行在 Blender 内部(bpy)的操作分发器
26
+ └── example_request.json
27
+ ```
28
 
29
+ ## API
 
 
 
30
 
31
+ ### `GET /health`
32
+ 检查服务和 Blender 二进制是否就绪。
33
 
34
+ ### `POST /execute`
35
+ ```json
36
+ {
37
+ "scene_b64": null,
38
+ "ops": [
39
+ {"op": "create_object", "type": "sphere", "name": "Ball", "location": [0,0,1]},
40
+ {"op": "add_material", "target": "Ball", "color": [0.8, 0.1, 0.1, 1.0], "roughness": 0.3},
41
+ {"op": "add_light", "type": "SUN", "location": [4,-4,6], "energy": 3},
42
+ {"op": "set_camera", "location": [6,-6,4], "look_at": [0,0,1]},
43
+ {"op": "set_render_settings", "resolution": [960, 540], "samples": 32},
44
+ {"op": "render_image", "filename": "ball.png"},
45
+ {"op": "export_glb", "filename": "ball.glb"}
46
+ ]
47
+ }
48
+ ```
49
 
50
+ 返回:
51
+ ```json
52
+ {
53
+ "job_id": "a1b2c3d4e5f6",
54
+ "ops_result": {"ok": true, "results": [...], "errors": []},
55
+ "files": ["ball.png", "ball.glb"],
56
+ "download_base": "/files/a1b2c3d4e5f6/"
57
+ }
58
+ ```
59
+
60
+ ### `GET /files/{job_id}/{filename}`
61
+ 下载生成的文件(渲染图 / glb / fbx / blend)。
62
+
63
+ ### `DELETE /jobs/{job_id}`
64
+ 清理某次任务的临时文件。
65
+
66
+ ## 支持的 op(在 `worker.py` 里维护白名单)
67
+
68
+ | op | 说明 |
69
+ |---|---|
70
+ | `create_object` | 创建基础几何体(sphere/cube/cylinder/cone/plane/monkey/torus/empty) |
71
+ | `move_object` | 绝对位置或相对位移 |
72
+ | `set_transform` | 设置位置/旋转(度)/缩放 |
73
+ | `add_material` | 创建/应用材质(颜色、金属度、粗糙度) |
74
+ | `set_camera` | 创建相机,支持 look_at 自动朝向 |
75
+ | `add_light` | 创建灯光(POINT/SUN/AREA/SPOT) |
76
+ | `add_animation` | 按关键帧设置位置/旋转/缩放 |
77
+ | `set_render_settings` | 分辨率/引擎/采样数/帧率/起止帧 |
78
+ | `render_image` | 渲染单帧 PNG |
79
+ | `render_animation` | 渲染动画序列帧 |
80
+ | `import_model` | 导入 glb/gltf/fbx/obj |
81
+ | `export_glb` / `export_fbx` | 导出模型 |
82
+ | `delete_object` | 删除物体 |
83
+ | `save_blend` | 保存 .blend 文件 |
84
+
85
+ 不支持任意 Python 执行——Agent 只能组合调用这些 op,避免生成失控脚本
86
+ (死循环、超大渲染、越权文件访问)。
87
+
88
+ ## 部署前需要改的地方
89
+
90
+ 1. `Dockerfile` 里的 `BLENDER_VERSION`,默认是 `4.2.9`(4.2 LTS 最新补丁版)。
91
+ 如需其他版本,去 https://download.blender.org/release/ 确认对应文件名。
92
+ 2. `JOB_TIMEOUT_SECONDS`(Dockerfile 里的环境变量),默认 180 秒,
93
+ 渲染复杂场景时按需调大——但 HF Space CPU basic 的算力有限,
94
+ 建议先用低分辨率/低采样数验证流程。
95
+ 3. 认证:这个 MVP 没有做鉴权,Space 一旦公开任何人都能调用你的 `/execute`。
96
+ 建议在 `app.py` 加一个简单的 API Key header 校验(`X-API-Key`),
97
+ OpenClaw 那边配置对应的 key。
98
+
99
+ ## OpenClaw 集成建议
100
+
101
+ 按你之前的设计,把它包成一个 skill:
102
+ `blender_execute` = bash wrapper 拼装 ops.json → POST 到这个 Space 的
103
+ `/execute` → 轮询/直接拿到 `files` 列表 → 用 `GET /files/...` 下载渲染结果
104
+ 或 glb,交给你现有的 video-gen / 3d-video pipeline 继续处理。