Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +4 -1
- README.md +9 -15
- docs/README.md +5 -5
- docs/SPEC_WEB_UI.md +44 -85
- docs/WEB_DEV_GUIDE.md +83 -76
Dockerfile
CHANGED
|
@@ -30,4 +30,7 @@ COPY --from=frontend-build /app/web/backend/static /app/web/backend/static
|
|
| 30 |
|
| 31 |
EXPOSE 7860
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
EXPOSE 7860
|
| 32 |
|
| 33 |
+
# Trust reverse-proxy headers (X-Forwarded-Proto). Default allow-list is 127.0.0.1 only;
|
| 34 |
+
# HF Spaces sits behind a proxy — without this, the app thinks the request is HTTP and
|
| 35 |
+
# session cookies often fail, so login loops.
|
| 36 |
+
CMD ["sh", "-c", "exec uvicorn web.backend.main:app --host 0.0.0.0 --port ${PORT:-7860} --forwarded-allow-ips='*'"]
|
README.md
CHANGED
|
@@ -9,27 +9,21 @@ pinned: false
|
|
| 9 |
|
| 10 |
# Gemini Studio Web
|
| 11 |
|
| 12 |
-
Gemini 图片 / 视频
|
| 13 |
|
| 14 |
## Documentation
|
| 15 |
|
| 16 |
-
| Document |
|
| 17 |
-
|----------|----------|
|
| 18 |
-
| [**docs/SPEC_WEB_UI.md**](docs/SPEC_WEB_UI.md) |
|
| 19 |
-
| [**docs/WEB_DEV_GUIDE.md**](docs/WEB_DEV_GUIDE.md) |
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
-
## Hugging Face
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|------|------|
|
| 31 |
-
| `GEMINI_API_KEY` | Google AI Studio / Gemini API 密钥(仅服务端使用) |
|
| 32 |
-
| `WEB_UI_PASSWORD` | 登录本站时输入的密码 |
|
| 33 |
-
| `SESSION_SECRET` | 会话签名用随机串,例如本地执行 `openssl rand -hex 32` 生成 |
|
| 34 |
-
|
| 35 |
-
更完整的步骤与 `docker run` 自测见 **[docs/WEB_DEV_GUIDE.md §10](docs/WEB_DEV_GUIDE.md#10-hugging-face-spaces-docker)**。可选变量 `GENERATION_OPTIONS_PATH` 等见该文档 **§3–4**。
|
|
|
|
| 9 |
|
| 10 |
# Gemini Studio Web
|
| 11 |
|
| 12 |
+
Gemini 图片 / 视频 Web 应用(FastAPI + React)。根目录 `README.md` 含 Hugging Face Spaces 的 YAML 头;详细说明见 `docs/`。
|
| 13 |
|
| 14 |
## Documentation
|
| 15 |
|
| 16 |
+
| Document | Contents |
|
| 17 |
+
|----------|----------|
|
| 18 |
+
| [**docs/SPEC_WEB_UI.md**](docs/SPEC_WEB_UI.md) | 功能与界面规格(原 PLAN) |
|
| 19 |
+
| [**docs/WEB_DEV_GUIDE.md**](docs/WEB_DEV_GUIDE.md) | 环境、部署、Hugging Face |
|
| 20 |
|
| 21 |
+
索引:[docs/README.md](docs/README.md)。
|
| 22 |
|
| 23 |
---
|
| 24 |
|
| 25 |
+
## Hugging Face(摘要)
|
| 26 |
|
| 27 |
+
上传、`README` 元数据、Secrets、本地 Docker:见 **[docs/WEB_DEV_GUIDE.md §10](docs/WEB_DEV_GUIDE.md#10-hugging-face-spaces-docker)**。
|
| 28 |
|
| 29 |
+
Space **Settings → Variables and secrets** 至少配置:`GEMINI_API_KEY`、`WEB_UI_PASSWORD`、`SESSION_SECRET`(大小写一致,含义见 §10.4 与 §3)。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
# Documentation
|
| 2 |
|
| 3 |
-
| File |
|
| 4 |
-
|------|------|
|
| 5 |
-
| [SPEC_WEB_UI.md](./SPEC_WEB_UI.md) | Product
|
| 6 |
-
| [WEB_DEV_GUIDE.md](./WEB_DEV_GUIDE.md) |
|
| 7 |
|
| 8 |
-
|
|
|
|
| 1 |
# Documentation
|
| 2 |
|
| 3 |
+
| File | Contents |
|
| 4 |
+
|------|----------|
|
| 5 |
+
| [SPEC_WEB_UI.md](./SPEC_WEB_UI.md) | Product spec |
|
| 6 |
+
| [WEB_DEV_GUIDE.md](./WEB_DEV_GUIDE.md) | Runbook (local, env, Docker, HF §10) |
|
| 7 |
|
| 8 |
+
Overview: [README.md](../README.md).
|
docs/SPEC_WEB_UI.md
CHANGED
|
@@ -1,113 +1,72 @@
|
|
| 1 |
# Web UI — product specification
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
---
|
| 6 |
|
| 7 |
-
This is the initial plan for how to change this pure code-based repo to a web ui.
|
| 8 |
-
|
| 9 |
# Overview
|
| 10 |
-
The final version of this repo should be launched as a web ui, which supports image and video generation.
|
| 11 |
-
The user might upload prompts and images (optional) as condition.
|
| 12 |
-
There will be several main features:
|
| 13 |
-
|
| 14 |
-
## 第一板块:AI创作台
|
| 15 |
-
- A. 图片生成或编辑:提供0-3张参考图片和提示词,生成一张图
|
| 16 |
-
- 思考强度:界面**并列三项**(模型 + 强度合一)——Flash(快速,默认 minimal)、Flash(快速)(长思考,high)、Pro(标准)(长思考,high);对应 `gemini-3.1-flash-image-preview` / `gemini-3-pro-image-preview` + `thinking_level`
|
| 17 |
-
- 宽高比:"1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9"
|
| 18 |
-
- 分辨率:"1K", "2K", "4K"
|
| 19 |
-
- B. 视频生成:提供0-3张参考图片和提示词,生成一个短视频
|
| 20 |
-
- 模型(可配置,见 `generation_options.json`):`veo-3.1-generate-preview`、`veo-3.1-lite-generate-preview`、`veo-3.1-fast-generate-preview`;界面标注为 **(标准)/(轻量)/(快速)**;其中 **Lite 不支持参考图**(由 `supports_reference_images` 标注)
|
| 21 |
-
- 宽高比:16:9 或 9:16
|
| 22 |
-
- 分辨率:720p、1080p 或 4k
|
| 23 |
-
- 时长:纯文案时可 4/6/8 秒(与分辨率组合以 API 为准);**有参考图时固定 8 秒**(Veo 接口要求)
|
| 24 |
-
- C. 视频生成(首尾过渡)(起始/可选结尾帧):至少 1 张起始帧 + 提示词,生成一个短视频;结尾帧可选,或勾选「结尾与起始相同」
|
| 25 |
-
- 模型:与 B 相同,同上三项 Veo 预览模型,可配置
|
| 26 |
-
- 宽高比:16:9 或 9:16
|
| 27 |
-
- 分辨率:720p、1080p 或 4k
|
| 28 |
-
- 时长:固定 **8 秒**(首/尾帧条件时 Veo 不接受 4/6 秒,与纯文案视频不同)
|
| 29 |
|
|
|
|
| 30 |
|
| 31 |
-
## 第
|
| 32 |
|
| 33 |
-
|
| 34 |
-
- 内在调用与「图片编辑或生成」相同,使用 1 张参考图生成更高清图片
|
| 35 |
-
- 提示词**默认**为「保持内容完全不变,提高图片的分辨率」,**可修改**
|
| 36 |
-
- **先上传原图(必填)**;根据原图**宽高比**在配置列表中**自动择近匹配**;**宽高比选项放在表单最下**,可手动改
|
| 37 |
-
- **分辨率**默认 4K,**不**根据原图自动推断,用户自选 1K/2K/4K
|
| 38 |
-
- 若原图宽高比与列表中**任一项都不接近**,界面**警告**:生成图可能与原图不完全一致,仍可点击生成
|
| 39 |
-
- 模型**默认「快速」**,可改为「标准」
|
| 40 |
-
|
| 41 |
-
- 提取视频的特定帧:
|
| 42 |
-
- 用户上传一个视频
|
| 43 |
-
- 视频将出现一个胶片一样可以拉动的进度条,用户随便停在一个位置,展示具体的时间和对应图像的preview
|
| 44 |
-
- 一旦点击“下载”,在下方讲出现这一帧作为一张单独的图片,可供用户下载。
|
| 45 |
-
|
| 46 |
-
- 图像裁剪(**前端 Canvas**,`/tools/crop`,不上传服务器)
|
| 47 |
-
- 上传图片,**交互式裁剪框**(框内平移、四角缩放;「自由」下四边为**可见白条**可拖,命中区与光标反馈按画布像素计算)
|
| 48 |
-
- 可选固定比例:与 `generation_options.json` 中**图片宽高比**列表一致(另加「自由」);切换比例时重置为居中最大适配框
|
| 49 |
-
- 裁剪交互区即原图;裁剪结果随框**实时**更新,下载 PNG
|
| 50 |
-
|
| 51 |
-
- 替换纯色背景(**前端 Canvas**,`/tools/replace-bg`,不上传服务器)
|
| 52 |
-
- 用户上传一个图片(提示:仅适合**纯色或大块相近色**背景)
|
| 53 |
-
- **原始色 / 目标色**的设定方式一致:**系统调色板**(原生取色器,通常含放大镜/吸管)、**手动** R/G/B 或 Hex(可「应用 Hex」);可选在预览图上点击取像素色
|
| 54 |
-
- **不透明度** 0–100%(默认 100%,仅作用于替换结果)
|
| 55 |
-
- 与原始色在 RGB 距离 ≤ **容差** 的像素改为目标 RGBA(容差可调)
|
| 56 |
-
- 下方预览,可下载 PNG
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
1.
|
| 65 |
-
-
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
- 展示提示词、一张input和output
|
| 69 |
|
| 70 |
-
|
| 71 |
-
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
只展示output,说此功能敬请期待(保持神秘)
|
| 78 |
|
|
|
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
-
|
|
|
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn
|
| 90 |
-
https://ai.google.dev/gemini-api/docs/video?hl=zh-cn
|
| 91 |
|
| 92 |
# 界面要求
|
| 93 |
-
- 初始有一个输入密码界面,这个密码是launch网站之前由用户设置的环境变量
|
| 94 |
-
- 密码正确后,侧栏有上述多重feature选项,点开其中任意一个,包含:
|
| 95 |
-
1. 功能简介和指示
|
| 96 |
-
2. 输入提示词的窗口(不可以为空)
|
| 97 |
-
3. 留给用户上传图片的空位(feature A/B 有三个参考图空位,均可空;feature C 有起始帧必填、结尾帧可选,并可勾选与起始相同)
|
| 98 |
-
4. 选择模型、宽高比、分辨率(视频类还有时长,受 API/参考图约束)
|
| 99 |
-
5. 输出图片/视频的空位
|
| 100 |
-
- 在生成过程中,可以有某种计时器显示运行时间,不要让用户感觉卡住了
|
| 101 |
|
| 102 |
-
|
| 103 |
-
-
|
| 104 |
-
-
|
| 105 |
-
- 网站页面风格:请用比较美观的模板和风格,不用太花哨,但是要有艺术气息
|
| 106 |
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
-
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
|
| 113 |
-
|
|
|
|
|
|
| 1 |
# Web UI — product specification
|
| 2 |
|
| 3 |
+
**Scope:** what to build and UX expectations (implementers / AI). **How to run / deploy:** [WEB_DEV_GUIDE.md](./WEB_DEV_GUIDE.md).
|
| 4 |
|
| 5 |
---
|
| 6 |
|
|
|
|
|
|
|
| 7 |
# Overview
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
Web UI for image and video generation: prompts plus optional reference images.
|
| 10 |
|
| 11 |
+
## 第一板块:AI 创作台
|
| 12 |
|
| 13 |
+
**A. 图片生成或编辑** — 0–3 张参考图 + 提示词 → 一张图。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
- 思考强度:三项并列(模型 + 强���)— Flash(快速,默认 minimal)、Flash(长思考,high)、Pro(长思考,high);对应 `gemini-3.1-flash-image-preview` / `gemini-3-pro-image-preview` + `thinking_level`。
|
| 16 |
+
- 宽高比:`1:1` … `21:9`(见 `generation_options.json`)。
|
| 17 |
+
- 分辨率:`1K` / `2K` / `4K`。
|
| 18 |
|
| 19 |
+
**B. 视频生成** — 0–3 张参考图 + 提示词 → 短视频。
|
| 20 |
|
| 21 |
+
- 模型(可配置):`veo-3.1-generate-preview`、`veo-3.1-lite-generate-preview`、`veo-3.1-fast-generate-preview`;界面:**(标准)/(轻量)/(快速)**。Lite **不支持参考图**(`supports_reference_images`)。
|
| 22 |
+
- 宽高比:16:9 或 9:16;分辨率:720p / 1080p / 4k。
|
| 23 |
+
- 时长:纯文案 4/6/8 秒(与分辨率以 API 为准);**有参考图时固定 8 秒**。
|
| 24 |
|
| 25 |
+
**C. 视频生成(首尾过渡)** — 至少 1 张起始帧 + 提示词;结尾帧可选或「与起始相同」。
|
|
|
|
| 26 |
|
| 27 |
+
- 模型:同 B;宽高比、分辨率:同 B。
|
| 28 |
+
- 时长:**固定 8 秒**(首/尾帧条件不接受 4/6 秒)。
|
| 29 |
|
| 30 |
+
## 第二板块:辅助工具
|
| 31 |
+
|
| 32 |
+
- **超分辨率:** 与图片编辑同一路径,1 张参考图 → 更高清;默认提示词可改。先上传原图(必填);按原图宽高比在列表中自动择近匹配,**宽高比控件放在表单最下**、可手改。分辨率默认 4K(不随原图自动推断),自选 1K/2K/4K。原图比例与列表都不接近时 **警告**,仍可生成。模型默认「快速」,可改「标准」。
|
| 33 |
+
- **提取视频帧:** 上传视频 → 可拖动时间轴 → 预览时间与画面 → 「下载」导出该帧 PNG。
|
| 34 |
+
- **图像裁剪**(前端 Canvas,`/tools/crop`,不上传服务器):裁剪框可平移、四角缩放;「自由」比例下四边白条可拖;固定比例选项与图片宽高比列表一致(另加「自由」);裁剪区即原图、结果实时更新;下载 PNG。
|
| 35 |
+
- **替换纯色背景**(前端 Canvas,`/tools/replace-bg`):适合纯色或大块相近背景;原色/目标色(系统调色板、手动 R/G/B 或 Hex、预览图点击取色);不透明度 0–100%;RGB 距离 ≤ 容差的像素替换为目标色;预览与 PNG 下载。
|
| 36 |
+
|
| 37 |
+
## 第三板块:示例
|
| 38 |
|
| 39 |
+
创作台的静态示例:预置提示词与 `assets/` 素材,展示输出;不调用模型。
|
|
|
|
| 40 |
|
| 41 |
+
简介:Wake-UP 人声乐团(北大 2025–2026 十佳歌手冠军)比赛彩幕相关能力展示。
|
| 42 |
|
| 43 |
+
1. 手写字体:两张 output。
|
| 44 |
+
2. 图上加字:提示词 + input + output。
|
| 45 |
+
3. 循环视频:提示词 + input + output 视频。
|
| 46 |
+
4. 超分辨率:input + output。
|
| 47 |
+
5. 视频延伸(长视频):仅 output +「敬请期待」。
|
| 48 |
|
| 49 |
+
## 示例脚本(仓库内)
|
| 50 |
|
| 51 |
+
- A:`run_gen_image_image_cond.sh`、`run_gen_image_prompt_only.sh`
|
| 52 |
+
- B:`run_gen_video_prompt_only.sh`
|
| 53 |
+
- C:`run_gen_video_image_start_end_diff.sh`
|
| 54 |
|
| 55 |
+
脚本可能只覆盖单图等简化场景。完整 API 说明:[图片](https://ai.google.dev/gemini-api/docs/image-generation?hl=zh-cn)、[视频](https://ai.google.dev/gemini-api/docs/video?hl=zh-cn)。
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# 界面要求
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
- 启动页:密码登录(密码来自环境变量)。
|
| 60 |
+
- 登录后侧栏进入各功能,每项含:简介、**必填**提示词、上传区(A/B 最多三张参考图,均可空;C 起始帧必填、结尾可选、可勾选与起始相同)、模型/宽高比/分辨率(视频含时长,受 API/参考图约束)、结果展示区。
|
| 61 |
+
- 生成中显示耗时,避免「卡住」感。
|
|
|
|
| 62 |
|
| 63 |
+
# 其他
|
| 64 |
|
| 65 |
+
- `GEMINI_API_KEY` 仅环境变量,禁止写入代码仓库。
|
| 66 |
+
- 代码英文;界面文案与提示词可用中文。
|
| 67 |
+
- 视觉:简洁、有一定设计感。
|
| 68 |
|
| 69 |
+
# 稳定 URL 与可配置选项
|
| 70 |
|
| 71 |
+
- 稳定访问域名:用自有域名 + DNS、静态 IP、反代或隧道等(见 WEB_DEV_GUIDE §8)。
|
| 72 |
+
- 模型名、分辨率、宽高比等:**不要写死在代码里**;集中在 **`web/config/generation_options.json`**,可用 **`GENERATION_OPTIONS_PATH`** 指向其他文件。改 JSON 通常不必重编前端;改 React/样式需 `cd web/frontend && npm run build`。
|
docs/WEB_DEV_GUIDE.md
CHANGED
|
@@ -1,20 +1,18 @@
|
|
| 1 |
# Web UI — developer guide
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
**Layout:** Application code lives under **`VideoGeneration-release/web/`**. All `from web.backend...` imports assume **`PYTHONPATH`** includes **`VideoGeneration-release`** (the parent of the `web/` directory). Do not set `PYTHONPATH` to `web/` itself—that will break imports.
|
| 8 |
|
| 9 |
## 1. Prerequisites
|
| 10 |
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
- **ffmpeg** on
|
| 14 |
|
| 15 |
-
## 2. Python
|
| 16 |
|
| 17 |
-
From **`VideoGeneration-release`**
|
| 18 |
|
| 19 |
```bash
|
| 20 |
cd /path/to/VideoGeneration-release
|
|
@@ -25,16 +23,14 @@ pip install -r web/requirements.txt
|
|
| 25 |
|
| 26 |
## 3. Environment variables
|
| 27 |
|
| 28 |
-
|
| 29 |
|
| 30 |
| Variable | Purpose |
|
| 31 |
|----------|---------|
|
| 32 |
-
| `GEMINI_API_KEY` |
|
| 33 |
-
| `WEB_UI_PASSWORD` | Login password
|
| 34 |
-
| `SESSION_SECRET` |
|
| 35 |
-
| `GENERATION_OPTIONS_PATH` | Optional.
|
| 36 |
-
|
| 37 |
-
Example for local debugging:
|
| 38 |
|
| 39 |
```bash
|
| 40 |
export GEMINI_API_KEY="your_key"
|
|
@@ -42,16 +38,14 @@ export WEB_UI_PASSWORD="password"
|
|
| 42 |
export SESSION_SECRET="$(openssl rand -hex 32)"
|
| 43 |
```
|
| 44 |
|
| 45 |
-
## 4.
|
| 46 |
|
| 47 |
-
Edit **`web/config/generation_options.json`** (or the file
|
| 48 |
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
- **`video`** / **`video_frames`**: `models` (`value` + `label`, Veo IDs), `aspect_ratios`, `resolutions`, `durations_seconds`. On **`video`**, each model may set **`supports_reference_images`** (boolean); e.g. Veo 3.1 Lite is **`false`**. With reference images, the backend also forces **8s** duration per API rules. The **首尾帧** API route always uses **8s** (frame-conditioned video does not accept 4/6s like prompt-only 720p).
|
| 53 |
-
|
| 54 |
-
## 5. Build the frontend once
|
| 55 |
|
| 56 |
```bash
|
| 57 |
cd web/frontend
|
|
@@ -59,96 +53,109 @@ npm install
|
|
| 59 |
npm run build
|
| 60 |
```
|
| 61 |
|
| 62 |
-
Output
|
| 63 |
-
|
| 64 |
-
## 6. Launch the server
|
| 65 |
|
| 66 |
-
|
| 67 |
|
| 68 |
```bash
|
| 69 |
cd /path/to/VideoGeneration-release
|
| 70 |
PYTHONPATH=. uvicorn web.backend.main:app --host 127.0.0.1 --port 8000
|
| 71 |
```
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
```bash
|
| 76 |
-
|
| 77 |
-
PYTHONPATH=. uvicorn web.backend.main:app --host 0.0.0.0 --port 8000
|
| 78 |
```
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
##
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
-
cd /path/to/VideoGeneration-release
|
| 88 |
-
PYTHONPATH=. uvicorn web.backend.main:app --reload --host 127.0.0.1 --port 8000
|
| 89 |
-
```
|
| 90 |
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
cd /path/to/VideoGeneration-release/web/frontend && npm run dev
|
| 95 |
-
```
|
| 96 |
|
| 97 |
-
|
| 98 |
|
| 99 |
-
##
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
| 104 |
-
Register a domain (e.g. `studio.example.com`). Create an **A** (or **AAAA**) record pointing to the **current** server’s public IP. When you move to a new machine, update the DNS record to the new IP. Users keep the same hostname.
|
| 105 |
|
| 106 |
-
|
| 107 |
-
If your cloud provider offers a static/elastic IP, attach it to whichever instance runs the app; point your DNS name to that IP.
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
|
| 112 |
-
|
| 113 |
-
**Cloudflare Tunnel**, **Tailscale Funnel**, or similar gives you a stable hostname without opening ports on your home router; the tunnel endpoint can be repointed when the backend machine changes (depending on the product).
|
| 114 |
|
| 115 |
-
|
| 116 |
-
Hard-coding `localhost` or a raw IP in the app will not give a stable branded URL. The fix is always: **one DNS name you control** → **current server location**.
|
| 117 |
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|------|---------|
|
| 135 |
-
| `GEMINI_API_KEY` | Same as local; never commit it. |
|
| 136 |
-
| `WEB_UI_PASSWORD` | Password users type on the login page. |
|
| 137 |
-
| `SESSION_SECRET` | Same as local, e.g. `openssl rand -hex 32`. |
|
| 138 |
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
|
| 148 |
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
```bash
|
|
|
|
| 152 |
docker build -t gemini-studio-web .
|
| 153 |
docker run --rm -p 7860:7860 \
|
| 154 |
-e GEMINI_API_KEY="your_key" \
|
|
@@ -157,4 +164,4 @@ docker run --rm -p 7860:7860 \
|
|
| 157 |
gemini-studio-web
|
| 158 |
```
|
| 159 |
|
| 160 |
-
|
|
|
|
| 1 |
# Web UI — developer guide
|
| 2 |
|
| 3 |
+
Set up, run, and deploy the Gemini Studio Web stack (FastAPI + React). Product scope: **[SPEC_WEB_UI.md](./SPEC_WEB_UI.md)**.
|
| 4 |
|
| 5 |
+
**Imports:** Code lives under `VideoGeneration-release/web/`. Use **`PYTHONPATH=.`** with cwd = **`VideoGeneration-release`** (parent of `web/`). Do not set `PYTHONPATH` to `web/` alone.
|
|
|
|
|
|
|
| 6 |
|
| 7 |
## 1. Prerequisites
|
| 8 |
|
| 9 |
+
- Python 3.10+
|
| 10 |
+
- Node.js 18+ and npm (frontend build)
|
| 11 |
+
- **ffmpeg** on `PATH` (strip audio from MP4s)
|
| 12 |
|
| 13 |
+
## 2. Python venv
|
| 14 |
|
| 15 |
+
From **`VideoGeneration-release`**:
|
| 16 |
|
| 17 |
```bash
|
| 18 |
cd /path/to/VideoGeneration-release
|
|
|
|
| 23 |
|
| 24 |
## 3. Environment variables
|
| 25 |
|
| 26 |
+
Do not commit secrets; use a `.env` with your process manager if you like.
|
| 27 |
|
| 28 |
| Variable | Purpose |
|
| 29 |
|----------|---------|
|
| 30 |
+
| `GEMINI_API_KEY` | Server-side only. |
|
| 31 |
+
| `WEB_UI_PASSWORD` | Login password. |
|
| 32 |
+
| `SESSION_SECRET` | Session signing, e.g. `openssl rand -hex 32`. |
|
| 33 |
+
| `GENERATION_OPTIONS_PATH` | Optional. Overrides default `web/config/generation_options.json`. |
|
|
|
|
|
|
|
| 34 |
|
| 35 |
```bash
|
| 36 |
export GEMINI_API_KEY="your_key"
|
|
|
|
| 38 |
export SESSION_SECRET="$(openssl rand -hex 32)"
|
| 39 |
```
|
| 40 |
|
| 41 |
+
## 4. `generation_options.json`
|
| 42 |
|
| 43 |
+
Edit **`web/config/generation_options.json`** (or the file from `GENERATION_OPTIONS_PATH`). The UI loads **`GET /api/config/generation-options`** after login. JSON-only changes need no frontend rebuild; React/TS/CSS changes do.
|
| 44 |
|
| 45 |
+
- **`image`**: `models` (`value` + `label`), `aspect_ratios`, `resolutions`, `thinking_levels`.
|
| 46 |
+
- **`video`** / **`video_frames`**: `models`, `aspect_ratios`, `resolutions`, `durations_seconds`. On **`video`**, **`supports_reference_images`** (e.g. Veo Lite = `false`). With reference images, duration is forced to **8s**. **首尾帧** route always **8s** (no 4/6s like prompt-only 720p).
|
| 47 |
|
| 48 |
+
## 5. Build frontend
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
```bash
|
| 51 |
cd web/frontend
|
|
|
|
| 53 |
npm run build
|
| 54 |
```
|
| 55 |
|
| 56 |
+
Output: **`web/backend/static/`**. Missing build → root URL returns 503.
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
## 6. Run server
|
| 59 |
|
| 60 |
```bash
|
| 61 |
cd /path/to/VideoGeneration-release
|
| 62 |
PYTHONPATH=. uvicorn web.backend.main:app --host 127.0.0.1 --port 8000
|
| 63 |
```
|
| 64 |
|
| 65 |
+
LAN: `--host 0.0.0.0`. Dev: add `--reload`.
|
| 66 |
+
|
| 67 |
+
## 7. Dev mode (hot reload)
|
| 68 |
+
|
| 69 |
+
**A** — API, cwd **`VideoGeneration-release`**:
|
| 70 |
|
| 71 |
```bash
|
| 72 |
+
PYTHONPATH=. uvicorn web.backend.main:app --reload --host 127.0.0.1 --port 8000
|
|
|
|
| 73 |
```
|
| 74 |
|
| 75 |
+
**B** — Vite (`web/frontend`): `npm run dev` (proxies `/api` to 8000). Open the printed URL (e.g. `http://127.0.0.1:5173`).
|
| 76 |
|
| 77 |
+
## 8. Stable URL
|
| 78 |
|
| 79 |
+
The app does not provide a hostname. Use DNS to a domain you control, static/elastic IP, reverse proxy (nginx/Caddy), or a tunnel (Cloudflare Tunnel, Tailscale Funnel, etc.). **One DNS name → current server** when you move machines.
|
| 80 |
|
| 81 |
+
## 9. Checklist
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
- [ ] `ffmpeg -version`
|
| 84 |
+
- [ ] `pip install -r web/requirements.txt`
|
| 85 |
+
- [ ] `npm run build` in `web/frontend` at least once
|
| 86 |
+
- [ ] `GEMINI_API_KEY`, `WEB_UI_PASSWORD`, `SESSION_SECRET` set
|
| 87 |
+
- [ ] Uvicorn from **`VideoGeneration-release`** with `PYTHONPATH=.`
|
| 88 |
|
| 89 |
+
## 10. Hugging Face Spaces (Docker)
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
Use **Docker** (`sdk: docker`), not Streamlit/Gradio. **`Dockerfile`** at repo root next to `web/` and `assets/`.
|
| 92 |
|
| 93 |
+
### 10.1 Create Space
|
| 94 |
|
| 95 |
+
[Hugging Face](https://huggingface.co/) → New Space → **SDK: Docker**. Space id: **`YOUR_USERNAME/YOUR_SPACE_NAME`**.
|
| 96 |
|
| 97 |
+
### 10.2 Root `README.md`
|
|
|
|
| 98 |
|
| 99 |
+
YAML frontmatter must validate. This repo’s README is preconfigured.
|
|
|
|
| 100 |
|
| 101 |
+
- **`sdk: docker`**
|
| 102 |
+
- **`colorFrom`** / **`colorTo`**: each must be one of **`red`**, **`yellow`**, **`green`**, **`blue`**, **`indigo`**, **`purple`**, **`pink`**, **`gray`** (other names → upload error).
|
| 103 |
|
| 104 |
+
### 10.3 Upload
|
|
|
|
| 105 |
|
| 106 |
+
**Cwd:** **`VideoGeneration-release`** (contains `Dockerfile`, `web/`, `assets/`).
|
|
|
|
| 107 |
|
| 108 |
+
**CLI** ([write token](https://huggingface.co/settings/tokens)):
|
| 109 |
|
| 110 |
+
```bash
|
| 111 |
+
pip install -U huggingface_hub
|
| 112 |
+
huggingface-cli login
|
| 113 |
+
cd /path/to/VideoGeneration-release
|
| 114 |
+
hf upload YOUR_USERNAME/YOUR_SPACE_NAME . . --repo-type space
|
| 115 |
+
```
|
| 116 |
|
| 117 |
+
Example:
|
| 118 |
+
|
| 119 |
+
```bash
|
| 120 |
+
hf upload LehongWu/VideoGeneration-release . . --repo-type space
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
Then check **Space → Logs** for the Docker build.
|
| 124 |
|
| 125 |
+
**Git:**
|
| 126 |
|
| 127 |
+
```bash
|
| 128 |
+
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
|
| 129 |
+
git push -u hf main
|
| 130 |
+
```
|
| 131 |
|
| 132 |
+
Or connect GitHub in Space settings and push there.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
### 10.4 Secrets
|
| 135 |
|
| 136 |
+
**Settings → Variables and secrets** — names must match exactly (case-sensitive). Same as [§3](#3-environment-variables).
|
| 137 |
|
| 138 |
+
| Name | Purpose |
|
| 139 |
+
|------|---------|
|
| 140 |
+
| `GEMINI_API_KEY` | Gemini key; never commit. |
|
| 141 |
+
| `WEB_UI_PASSWORD` | Login password. |
|
| 142 |
+
| `SESSION_SECRET` | e.g. `openssl rand -hex 32`. |
|
| 143 |
|
| 144 |
+
Optional: `GENERATION_OPTIONS_PATH` (custom JSON path inside the container).
|
| 145 |
|
| 146 |
+
Saving restarts the Space. Never put secrets in Git or `README.md`.
|
| 147 |
|
| 148 |
+
### 10.5 Runtime
|
| 149 |
+
|
| 150 |
+
- Listens on **`PORT`** or **`7860`** (`Dockerfile`: `uvicorn ... --port ${PORT:-7860}`).
|
| 151 |
+
- **`--forwarded-allow-ips='*'`** — required behind HF’s reverse proxy so `X-Forwarded-Proto: https` is trusted. Without it, Uvicorn often sees `http`, session cookies misbehave, and the UI **keeps asking you to log in**.
|
| 152 |
+
- **ffmpeg** in image.
|
| 153 |
+
- First build / cold start can take minutes.
|
| 154 |
+
|
| 155 |
+
### 10.6 Local Docker
|
| 156 |
|
| 157 |
```bash
|
| 158 |
+
cd /path/to/VideoGeneration-release
|
| 159 |
docker build -t gemini-studio-web .
|
| 160 |
docker run --rm -p 7860:7860 \
|
| 161 |
-e GEMINI_API_KEY="your_key" \
|
|
|
|
| 164 |
gemini-studio-web
|
| 165 |
```
|
| 166 |
|
| 167 |
+
Open `http://127.0.0.1:7860`.
|