gemini-web 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gemini_web-1.0.0/.env.example +17 -0
- gemini_web-1.0.0/.github/workflows/publish.yml +24 -0
- gemini_web-1.0.0/.github/workflows/test.yml +29 -0
- gemini_web-1.0.0/.gitignore +9 -0
- gemini_web-1.0.0/AGENTS.md +101 -0
- gemini_web-1.0.0/CLAUDE.md +21 -0
- gemini_web-1.0.0/GEMINI.md +93 -0
- gemini_web-1.0.0/PKG-INFO +16 -0
- gemini_web-1.0.0/README.md +283 -0
- gemini_web-1.0.0/docs/design.md +243 -0
- gemini_web-1.0.0/docs/plan.md +1245 -0
- gemini_web-1.0.0/pyproject.toml +32 -0
- gemini_web-1.0.0/scripts/install-service.sh +32 -0
- gemini_web-1.0.0/scripts/setup.sh +78 -0
- gemini_web-1.0.0/src/__init__.py +0 -0
- gemini_web-1.0.0/src/assets/bg_48.png +0 -0
- gemini_web-1.0.0/src/assets/bg_96.png +0 -0
- gemini_web-1.0.0/src/browser.py +171 -0
- gemini_web-1.0.0/src/cli.py +260 -0
- gemini_web-1.0.0/src/commands/__init__.py +0 -0
- gemini_web-1.0.0/src/commands/chat.md +38 -0
- gemini_web-1.0.0/src/commands/chat.toml +18 -0
- gemini_web-1.0.0/src/commands/gemini-web.md +37 -0
- gemini_web-1.0.0/src/commands/gemini-web.toml +25 -0
- gemini_web-1.0.0/src/commands/generate.md +36 -0
- gemini_web-1.0.0/src/commands/generate.toml +22 -0
- gemini_web-1.0.0/src/config.py +59 -0
- gemini_web-1.0.0/src/gemini.py +419 -0
- gemini_web-1.0.0/src/main.py +290 -0
- gemini_web-1.0.0/src/queue.py +69 -0
- gemini_web-1.0.0/src/selectors.py +31 -0
- gemini_web-1.0.0/src/watermark.py +121 -0
- gemini_web-1.0.0/tests/__init__.py +0 -0
- gemini_web-1.0.0/tests/test_api.py +65 -0
- gemini_web-1.0.0/tests/test_config.py +35 -0
- gemini_web-1.0.0/tests/test_queue.py +46 -0
- gemini_web-1.0.0/tests/test_watermark.py +109 -0
- gemini_web-1.0.0/uv.lock +930 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 瀏覽器
|
|
2
|
+
HEADLESS=false
|
|
3
|
+
# PROFILE_DIR=~/.gemini-web/profiles # 預設值,通常不需要改
|
|
4
|
+
GEMINI_URL=https://gemini.google.com/app
|
|
5
|
+
|
|
6
|
+
# Stealth
|
|
7
|
+
STEALTH_LANGUAGE=zh-TW,zh,en-US,en
|
|
8
|
+
STEALTH_TIMEZONE=Asia/Taipei
|
|
9
|
+
|
|
10
|
+
# 服務
|
|
11
|
+
HOST=0.0.0.0
|
|
12
|
+
PORT=8070
|
|
13
|
+
QUEUE_MAX_SIZE=10
|
|
14
|
+
DEFAULT_TIMEOUT=180
|
|
15
|
+
|
|
16
|
+
# 心跳
|
|
17
|
+
HEARTBEAT_INTERVAL=300
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
environment: pypi
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Install uv
|
|
18
|
+
uses: astral-sh/setup-uv@v4
|
|
19
|
+
|
|
20
|
+
- name: Build package
|
|
21
|
+
run: uv build
|
|
22
|
+
|
|
23
|
+
- name: Publish to PyPI
|
|
24
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ${{ matrix.os }}
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
15
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
run: uv python install ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: uv sync --extra dev
|
|
27
|
+
|
|
28
|
+
- name: Run tests
|
|
29
|
+
run: uv run pytest tests/ -v
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Gemini Image — AI Agent 使用指引
|
|
2
|
+
|
|
3
|
+
本工具讓 AI Agent 能透過 Gemini 網頁版進行**文字對話**和**圖片生成**(含自動去水印)。
|
|
4
|
+
|
|
5
|
+
## 前置需求
|
|
6
|
+
|
|
7
|
+
確認 `gemini-web` 已安裝且已登入:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
gemini-web health # API 模式:檢查服務是否運行
|
|
11
|
+
# 或
|
|
12
|
+
which gemini-web # CLI 模式:確認指令存在
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用方式
|
|
16
|
+
|
|
17
|
+
### 文字對話
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# CLI
|
|
21
|
+
gemini-web chat "<prompt>"
|
|
22
|
+
|
|
23
|
+
# HTTP API
|
|
24
|
+
curl -X POST http://localhost:8070/api/chat \
|
|
25
|
+
-H "Content-Type: application/json" \
|
|
26
|
+
-d '{"prompt": "<prompt>"}'
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
回傳 JSON:`{"success": true, "text": "..."}`
|
|
30
|
+
|
|
31
|
+
### 圖片生成
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# CLI
|
|
35
|
+
gemini-web generate "<prompt>" -o <output_path> --no-watermark
|
|
36
|
+
|
|
37
|
+
# HTTP API
|
|
38
|
+
curl -X POST http://localhost:8070/api/generate \
|
|
39
|
+
-H "Content-Type: application/json" \
|
|
40
|
+
-d '{"prompt": "<prompt>"}'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
回傳 JSON:`{"success": true, "images": ["data:image/png;base64,..."]}`
|
|
44
|
+
|
|
45
|
+
### 參數說明
|
|
46
|
+
|
|
47
|
+
- `<prompt>`:圖片描述,**建議用英文**效果最好
|
|
48
|
+
- `-o`:輸出檔案路徑(支援 .png / .jpg)
|
|
49
|
+
- `--no-watermark`:移除 Gemini 水印(建議始終加上)
|
|
50
|
+
- 文字對話耗時約 5-30 秒,圖片生成約 30-120 秒
|
|
51
|
+
|
|
52
|
+
## Prompt 撰寫規則
|
|
53
|
+
|
|
54
|
+
**重要:不要原封不動轉發用戶的請求。** 你應該:
|
|
55
|
+
|
|
56
|
+
1. 理解用戶意圖
|
|
57
|
+
2. 擴寫為詳細的英文 prompt
|
|
58
|
+
3. 描述主體、風格、構圖、色彩、氛圍
|
|
59
|
+
4. 如果需要圖片中出現中文文字,用引號標明:`with text "歡迎光臨"`
|
|
60
|
+
|
|
61
|
+
### 範例
|
|
62
|
+
|
|
63
|
+
用戶說「畫一隻貓」→ 你應該送:
|
|
64
|
+
```
|
|
65
|
+
A cute fluffy orange tabby cat sitting on a windowsill, warm afternoon sunlight streaming in, cozy atmosphere, soft watercolor illustration style, gentle expression with bright curious eyes
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
用戶說「做一張開幕海報」→ 你應該送:
|
|
69
|
+
```
|
|
70
|
+
A modern grand opening poster design with bold typography showing text "盛大開幕" at the top, celebratory confetti and ribbons, red and gold color scheme, professional marketing design, clean layout
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 錯誤處理
|
|
74
|
+
|
|
75
|
+
| 錯誤 | 意義 | 建議 |
|
|
76
|
+
|------|------|------|
|
|
77
|
+
| `content_blocked` | Gemini 拒絕生成 | 換一個不涉及敏感內容的 prompt |
|
|
78
|
+
| `no_image` | 沒有生成圖片 | prompt 更具體,確認包含「draw」「generate」等關鍵字 |
|
|
79
|
+
| `no_response` | 文字對話無回應 | 稍後再試 |
|
|
80
|
+
| `timeout` | 生成超時 | 稍後再試 |
|
|
81
|
+
| `browser_error` | 瀏覽器問題 | 檢查 `gemini-web health` |
|
|
82
|
+
|
|
83
|
+
## 安裝(如果尚未安裝)
|
|
84
|
+
|
|
85
|
+
> ⚠️ **不要用 `pip install`** — 必須用 uv 或 pipx,否則 Playwright 安裝會失敗。
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 1. 安裝 uv(如果還沒有)
|
|
89
|
+
# macOS / Linux:
|
|
90
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
91
|
+
# Windows PowerShell:
|
|
92
|
+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
93
|
+
|
|
94
|
+
# 2. 安裝 gemini-web + Chromium
|
|
95
|
+
uv tool install gemini-web && gemini-web install
|
|
96
|
+
|
|
97
|
+
# 3. 登入 Google(⚠️ 此步驟需要人類手動操作,會彈出瀏覽器)
|
|
98
|
+
gemini-web login
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
如果之前用 pip 裝過,先移除:`pip uninstall gemini-web -y`
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
## 發佈流程
|
|
4
|
+
|
|
5
|
+
不要用 `uv publish` 手動發佈。本專案使用 GitHub Release 觸發自動發佈:
|
|
6
|
+
|
|
7
|
+
1. bump `pyproject.toml` 中的 version
|
|
8
|
+
2. commit + push
|
|
9
|
+
3. 在 GitHub 上建立 Release(tag 格式:`v0.4.0`)
|
|
10
|
+
4. GitHub Actions(`.github/workflows/publish.yml`)自動 build + publish 到 PyPI
|
|
11
|
+
|
|
12
|
+
## 開發
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
uv sync --extra dev
|
|
16
|
+
uv run python -m pytest -v
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 安裝方式
|
|
20
|
+
|
|
21
|
+
必須用 `uv tool install` 或 `pipx install`,不要用 `pip install`。
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Gemini Image — AI Agent 使用指引
|
|
2
|
+
|
|
3
|
+
本工具讓 AI Agent 能透過 Gemini 網頁版進行**文字對話**和**圖片生成**(含自動去水印)。
|
|
4
|
+
|
|
5
|
+
## 安裝
|
|
6
|
+
|
|
7
|
+
> **不要用 `pip install`** — 必須用 uv 或 pipx,否則 Playwright 安裝會失敗。
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# 1. 安裝 uv(如果還沒有)
|
|
11
|
+
# macOS / Linux:
|
|
12
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
13
|
+
# Windows PowerShell:
|
|
14
|
+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
15
|
+
|
|
16
|
+
# 2. 安裝 gemini-web + Chromium
|
|
17
|
+
uv tool install gemini-web && gemini-web install
|
|
18
|
+
|
|
19
|
+
# 3. 登入 Google(需要人類手動操作,會彈出瀏覽器)
|
|
20
|
+
gemini-web login
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
如果之前用 pip 裝過,先移除:`pip uninstall gemini-web -y`
|
|
24
|
+
|
|
25
|
+
## 確認安裝成功
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
which gemini-web # 確認指令存在
|
|
29
|
+
gemini-web health # API 模式:檢查服務是否運行
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 使用方式
|
|
33
|
+
|
|
34
|
+
### 文字對話
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# CLI
|
|
38
|
+
gemini-web chat "<prompt>"
|
|
39
|
+
|
|
40
|
+
# HTTP API
|
|
41
|
+
curl -X POST http://localhost:8070/api/chat \
|
|
42
|
+
-H "Content-Type: application/json" \
|
|
43
|
+
-d '{"prompt": "<prompt>"}'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
回傳 JSON:`{"success": true, "text": "..."}`
|
|
47
|
+
|
|
48
|
+
### 圖片生成
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# CLI
|
|
52
|
+
gemini-web generate "<prompt>" -o <output_path> --no-watermark
|
|
53
|
+
|
|
54
|
+
# HTTP API
|
|
55
|
+
curl -X POST http://localhost:8070/api/generate \
|
|
56
|
+
-H "Content-Type: application/json" \
|
|
57
|
+
-d '{"prompt": "<prompt>"}'
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
回傳 JSON:`{"success": true, "images": ["data:image/png;base64,..."]}`
|
|
61
|
+
|
|
62
|
+
- 文字對話耗時約 5-30 秒,圖片生成約 30-120 秒
|
|
63
|
+
|
|
64
|
+
## Prompt 撰寫規則
|
|
65
|
+
|
|
66
|
+
**重要:不要原封不動轉發用戶的請求。** 你應該:
|
|
67
|
+
|
|
68
|
+
1. 理解用戶意圖
|
|
69
|
+
2. 擴寫為詳細的英文 prompt
|
|
70
|
+
3. 描述主體、風格、構圖、色彩、氛圍
|
|
71
|
+
4. 如果需要圖片中出現中文文字,用引號標明:`with text "歡迎光臨"`
|
|
72
|
+
|
|
73
|
+
### 範例
|
|
74
|
+
|
|
75
|
+
用戶說「畫一隻貓」→ 你應該送:
|
|
76
|
+
```
|
|
77
|
+
A cute fluffy orange tabby cat sitting on a windowsill, warm afternoon sunlight streaming in, cozy atmosphere, soft watercolor illustration style, gentle expression with bright curious eyes
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
用戶說「做一張開幕海報」→ 你應該送:
|
|
81
|
+
```
|
|
82
|
+
A modern grand opening poster design with bold typography showing text "盛大開幕" at the top, celebratory confetti and ribbons, red and gold color scheme, professional marketing design, clean layout
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 錯誤處理
|
|
86
|
+
|
|
87
|
+
| 錯誤 | 意義 | 建議 |
|
|
88
|
+
|------|------|------|
|
|
89
|
+
| `content_blocked` | Gemini 拒絕生成 | 換一個不涉及敏感內容的 prompt |
|
|
90
|
+
| `no_image` | 沒有生成圖片 | prompt 更具體,確認包含「draw」「generate」等關鍵字 |
|
|
91
|
+
| `no_response` | 文字對話無回應 | 稍後再試 |
|
|
92
|
+
| `timeout` | 生成超時 | 稍後再試 |
|
|
93
|
+
| `browser_error` | 瀏覽器問題 | 檢查 `gemini-web health` |
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gemini-web
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Gemini 網頁版自動化 — 文字對話、圖片生成、Google GenAI API 相容
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: fastapi>=0.115
|
|
7
|
+
Requires-Dist: httpx>=0.27
|
|
8
|
+
Requires-Dist: numpy>=1.26
|
|
9
|
+
Requires-Dist: pillow>=10.0
|
|
10
|
+
Requires-Dist: playwright>=1.49
|
|
11
|
+
Requires-Dist: python-dotenv>=1.0
|
|
12
|
+
Requires-Dist: uvicorn[standard]>=0.30
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# Gemini Image
|
|
2
|
+
|
|
3
|
+
> **快速安裝:** `uv tool install gemini-web && gemini-web install`
|
|
4
|
+
|
|
5
|
+
使用 Playwright 自動化 Gemini 網頁版,提供**圖片生成**和**文字對話**功能。支援 **CLI 工具**和 **HTTP API** 兩種使用方式。
|
|
6
|
+
|
|
7
|
+
自動移除 Gemini 可見水印(Reverse Alpha Blending,基於 [gemini-watermark-remover](https://github.com/journey-ad/gemini-watermark-remover))。
|
|
8
|
+
|
|
9
|
+
## 安裝
|
|
10
|
+
|
|
11
|
+
> ⚠️ **不要用 `pip install`** — pip 不會建立隔離環境,會導致 Playwright 安裝失敗。請用 uv 或 pipx。
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# 1. 安裝 uv(如果還沒有)
|
|
15
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh # macOS / Linux
|
|
16
|
+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # Windows
|
|
17
|
+
|
|
18
|
+
# 2. 安裝 gemini-web
|
|
19
|
+
uv tool install gemini-web && gemini-web install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
備選方式(效果相同):
|
|
23
|
+
```bash
|
|
24
|
+
pipx install gemini-web && gemini-web install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`gemini-web install` 會安裝 Chromium 瀏覽器(Playwright)。
|
|
28
|
+
|
|
29
|
+
### 已經用 pip 裝過?
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip uninstall gemini-web -y
|
|
33
|
+
uv tool install gemini-web && gemini-web install
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 首次登入 Google
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
gemini-web login
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
在彈出的瀏覽器中登入 Google 帳號,確認進入 Gemini 頁面,按 Enter 關閉。登入狀態存在 `~/.gemini-web/profiles/`,之後不需要重新登入。
|
|
43
|
+
|
|
44
|
+
## 使用方式
|
|
45
|
+
|
|
46
|
+
### CLI 工具
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 文字對話
|
|
50
|
+
gemini-web chat "解釋量子力學"
|
|
51
|
+
|
|
52
|
+
# 生成圖片(自動 headless)
|
|
53
|
+
gemini-web generate "A cute cat sitting on a windowsill" -o cat.png
|
|
54
|
+
|
|
55
|
+
# 生成 + 去水印
|
|
56
|
+
gemini-web generate "A poster with text '歡迎光臨'" -o poster.png --no-watermark
|
|
57
|
+
|
|
58
|
+
# 詳細 log
|
|
59
|
+
gemini-web generate "畫一隻柴犬" -o shiba.png --no-watermark -v
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Prompt 不含「畫」「draw」「generate」等關鍵字時,會自動加上 `Generate an image:` 前綴。
|
|
63
|
+
|
|
64
|
+
### HTTP API
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# 啟動服務
|
|
68
|
+
gemini-web serve
|
|
69
|
+
# 或
|
|
70
|
+
gemini-web serve --host 0.0.0.0 --port 8070
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
API 模式自動去水印、自動下載原尺寸圖片。
|
|
74
|
+
|
|
75
|
+
#### POST /api/chat
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
curl -X POST http://localhost:8070/api/chat \
|
|
79
|
+
-H "Content-Type: application/json" \
|
|
80
|
+
-d '{"prompt": "解釋量子力學"}'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
回傳:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"success": true,
|
|
88
|
+
"text": "量子力學是...",
|
|
89
|
+
"prompt": "...",
|
|
90
|
+
"elapsed_seconds": 8.3
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### POST /api/generate
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
curl -X POST http://localhost:8070/api/generate \
|
|
98
|
+
-H "Content-Type: application/json" \
|
|
99
|
+
-d '{"prompt": "畫一張台北101海報"}'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
回傳:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"success": true,
|
|
107
|
+
"images": ["data:image/png;base64,..."],
|
|
108
|
+
"prompt": "...",
|
|
109
|
+
"elapsed_seconds": 45.2
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
#### POST /v1beta/models/{model}:generateContent(Google GenAI API 相容)
|
|
114
|
+
|
|
115
|
+
完全相容 `google-genai` SDK 格式,可做為 Google Gemini API 的 drop-in replacement。
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# 文字對話
|
|
119
|
+
curl -X POST "http://localhost:8070/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_KEY" \
|
|
120
|
+
-H "Content-Type: application/json" \
|
|
121
|
+
-d '{"contents": [{"parts": [{"text": "什麼是量子力學"}]}]}'
|
|
122
|
+
|
|
123
|
+
# 圖片生成
|
|
124
|
+
curl -X POST "http://localhost:8070/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_KEY" \
|
|
125
|
+
-H "Content-Type: application/json" \
|
|
126
|
+
-d '{"contents": [{"parts": [{"text": "a cute cat"}]}], "generationConfig": {"responseMimeType": "image/png"}}'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
回傳格式與 Google API 完全一致:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"candidates": [{
|
|
134
|
+
"content": {
|
|
135
|
+
"parts": [{"text": "量子力學是..."}],
|
|
136
|
+
"role": "model"
|
|
137
|
+
},
|
|
138
|
+
"finishReason": "STOP"
|
|
139
|
+
}]
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
搭配 `google-genai` SDK 使用:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from google import genai
|
|
147
|
+
client = genai.Client(
|
|
148
|
+
api_key="YOUR_KEY",
|
|
149
|
+
http_options={"api_version": "v1beta", "base_url": "http://localhost:8070"}
|
|
150
|
+
)
|
|
151
|
+
response = client.models.generate_content(model="gemini-2.5-flash", contents="Hello")
|
|
152
|
+
print(response.text)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### GET /api/health
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"status": "ok",
|
|
160
|
+
"browser_alive": true,
|
|
161
|
+
"logged_in": true,
|
|
162
|
+
"queue_size": 0,
|
|
163
|
+
"uptime_seconds": 3600
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### POST /api/new-chat
|
|
168
|
+
|
|
169
|
+
手動重置 Gemini 對話(除錯用)。
|
|
170
|
+
|
|
171
|
+
### systemd 服務部署
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
sudo bash scripts/install-service.sh
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## 去水印
|
|
178
|
+
|
|
179
|
+
使用 **Reverse Alpha Blending** 演算法,數學精確還原被水印覆蓋的像素:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
original = (watermarked - alpha × logo) / (1 - alpha)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
- 純 Python 實作(Pillow + NumPy),跨平台
|
|
186
|
+
- 大圖(寬高 > 1024):96×96 水印,64px 邊距
|
|
187
|
+
- 小圖:48×48 水印,32px 邊距
|
|
188
|
+
- API 模式自動去水印
|
|
189
|
+
- CLI 模式加 `--no-watermark`
|
|
190
|
+
- 不可見的 SynthID 浮水印無法移除
|
|
191
|
+
|
|
192
|
+
基於 [gemini-watermark-remover](https://github.com/journey-ad/gemini-watermark-remover) 和 [Python 版本](https://github.com/VimalMollyn/Gemini-Watermark-Remover-Python)。
|
|
193
|
+
|
|
194
|
+
## AI Agent 整合
|
|
195
|
+
|
|
196
|
+
讓你的 AI Agent 能用 `/gemini-web` 指令生圖。
|
|
197
|
+
|
|
198
|
+
### 安裝(一行搞定)
|
|
199
|
+
|
|
200
|
+
> ⚠️ **不要用 `pip install`**,必須用 uv 或 pipx。
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
uv tool install gemini-web && gemini-web install
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`gemini-web install` 會自動:
|
|
207
|
+
1. 安裝 Chromium 瀏覽器(Playwright)
|
|
208
|
+
2. 偵測 Claude Code(`~/.claude/`)→ 安裝 slash commands
|
|
209
|
+
3. 偵測 Gemini CLI(`~/.gemini/`)→ 安裝 slash commands
|
|
210
|
+
|
|
211
|
+
安裝後可用:`/gemini-web <自然語言描述>`、`/generate <英文 prompt>`、`/chat <提問>`
|
|
212
|
+
|
|
213
|
+
### 登入(需人工操作)
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
gemini-web login
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
會彈出瀏覽器,手動登入 Google 帳號後按 Enter 關閉。登入狀態存在 `~/.gemini-web/profiles/`。
|
|
220
|
+
|
|
221
|
+
### 支援的 AI Agent
|
|
222
|
+
|
|
223
|
+
| Agent | 自動支援 | 說明 |
|
|
224
|
+
|-------|:--------:|------|
|
|
225
|
+
| **Claude Code** | ✓ | install 自動安裝 commands 到 `~/.claude/commands/gemini-web/` |
|
|
226
|
+
| **Gemini CLI** | ✓ | install 自動安裝 commands 到 `~/.gemini/commands/gemini-web/` |
|
|
227
|
+
| **Cursor / Windsurf** | — | 把 `AGENTS.md` 內容加入 rules 設定 |
|
|
228
|
+
| **其他 Agent** | — | 讓 Agent 讀取 `AGENTS.md` 作為系統指引 |
|
|
229
|
+
|
|
230
|
+
### CLI 呼叫
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
gemini-web generate "detailed english prompt" -o /path/to/output.png --no-watermark
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### HTTP API
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
import httpx
|
|
240
|
+
resp = httpx.post("http://localhost:8070/api/generate", json={"prompt": "..."}, timeout=200)
|
|
241
|
+
data = resp.json()
|
|
242
|
+
if data["success"]:
|
|
243
|
+
images = data["images"] # base64 list
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 環境變數
|
|
247
|
+
|
|
248
|
+
| 變數 | 說明 | 預設 |
|
|
249
|
+
|------|------|------|
|
|
250
|
+
| `HEADLESS` | 無頭模式 | `false`(CLI generate 強制 `true`) |
|
|
251
|
+
| `PROFILE_DIR` | 瀏覽器 session 目錄 | `~/.gemini-web/profiles` |
|
|
252
|
+
| `GEMINI_URL` | Gemini 網址 | `https://gemini.google.com/app` |
|
|
253
|
+
| `PORT` | API 服務埠 | `8070` |
|
|
254
|
+
| `DEFAULT_TIMEOUT` | 生圖超時秒數 | `180` |
|
|
255
|
+
| `QUEUE_MAX_SIZE` | 最大排隊數 | `10` |
|
|
256
|
+
| `API_KEYS` | API 金鑰(逗號分隔多組,空 = 不驗證) | 無 |
|
|
257
|
+
|
|
258
|
+
## 從原始碼安裝
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
git clone https://github.com/yazelin/gemini-web.git
|
|
262
|
+
cd gemini-web
|
|
263
|
+
bash scripts/setup.sh
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## 開發
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
uv sync --extra dev
|
|
270
|
+
uv run pytest -v
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 已知限制
|
|
274
|
+
|
|
275
|
+
- 一次只能處理一個請求(生圖或對話,其他排隊等待)
|
|
276
|
+
- Google 登入過期需手動重新登入(`gemini-web login`)
|
|
277
|
+
- Gemini 改版可能導致 DOM selector 失效,需更新 `src/selectors.py`
|
|
278
|
+
- 違反 Google 服務條款,帳號有被封風險
|
|
279
|
+
- 生圖耗時約 30-120 秒,視 Gemini 伺服器負載而定
|
|
280
|
+
|
|
281
|
+
## 授權
|
|
282
|
+
|
|
283
|
+
MIT License
|