gpt-image-playground deploy commited on
Commit
e344055
·
1 Parent(s): 96bdf6c

Deploy 444b7ab to Docker Space

Browse files
README.md CHANGED
@@ -12,7 +12,7 @@ app_port: 4783
12
  本地 AI 图片创作工作台,面向中文内容运营、设计草图和自动化生图流程。支持 `gpt-image-2`、OpenAI 兼容图片接口、文生图、图生图、遮罩编辑、批量任务、历史复用、费用追踪和 Agent API。
13
 
14
  <p align="center">
15
- <img src="./readme-images/interface.jpg?v=20260608-07b596b" alt="GPT Image Playground 界面" width="900"/>
16
  </p>
17
 
18
  ## 快速开始
@@ -78,13 +78,13 @@ start-windows.bat
78
  遮罩编辑示例:
79
 
80
  <p align="center">
81
- <img src="./readme-images/mask-creation.jpg?v=20260608-07b596b" alt="遮罩创建" width="900"/>
82
  </p>
83
 
84
  历史与费用示例:
85
 
86
  <p align="center">
87
- <img src="./readme-images/history.jpg?v=20260608-07b596b" alt="历史面板" width="900"/>
88
  </p>
89
 
90
  ## 配置
 
12
  本地 AI 图片创作工作台,面向中文内容运营、设计草图和自动化生图流程。支持 `gpt-image-2`、OpenAI 兼容图片接口、文生图、图生图、遮罩编辑、批量任务、历史复用、费用追踪和 Agent API。
13
 
14
  <p align="center">
15
+ <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/444b7abc99f5bfa03760ceefb2beb0d790f0aba9/readme-images/interface.jpg?v=20260608-07b596b" alt="GPT Image Playground 界面" width="900"/>
16
  </p>
17
 
18
  ## 快速开始
 
78
  遮罩编辑示例:
79
 
80
  <p align="center">
81
+ <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/444b7abc99f5bfa03760ceefb2beb0d790f0aba9/readme-images/mask-creation.jpg?v=20260608-07b596b" alt="遮罩创建" width="900"/>
82
  </p>
83
 
84
  历史与费用示例:
85
 
86
  <p align="center">
87
+ <img src="https://raw.githubusercontent.com/MisonL/gpt-image-playground-customer/444b7abc99f5bfa03760ceefb2beb0d790f0aba9/readme-images/history.jpg?v=20260608-07b596b" alt="历史面板" width="900"/>
88
  </p>
89
 
90
  ## 配置
docs/deployment/huggingface-space-free.md CHANGED
@@ -96,6 +96,7 @@ npm run deploy:space
96
 
97
  - 使用 `git status --porcelain` 拒绝脏工作区。
98
  - 使用 `git archive HEAD` 生成临时源码目录,只上传已跟踪源码。
 
99
  - 优先使用 `hf upload` 上传到 `misonL/gpt-image-playground-customer`。
100
  - 仅当 `hf upload` 因既有 Docker Space 的创建政策 `402` 失败时,克隆该固定 Space、同步已跟踪源码并使用认证 Git 推送;其他错误不会自动回退。
101
  - 等待新 Space commit 进入 `RUNNING`。
 
96
 
97
  - 使用 `git status --porcelain` 拒绝脏工作区。
98
  - 使用 `git archive HEAD` 生成临时源码目录,只上传已跟踪源码。
99
+ - Space 发布包会排除根目录 `readme-images/` 中的 README 文档截图,以兼容 Hugging Face Git 的二进制文件门禁;Space README 会改用对应 GitHub 提交的不可变图片地址。
100
  - 优先使用 `hf upload` 上传到 `misonL/gpt-image-playground-customer`。
101
  - 仅当 `hf upload` 因既有 Docker Space 的创建政策 `402` 失败时,克隆该固定 Space、同步已跟踪源码并使用认证 Git 推送;其他错误不会自动回退。
102
  - 等待新 Space commit 进入 `RUNNING`。
package.json CHANGED
@@ -3,6 +3,13 @@
3
  "version": "2.1.0",
4
  "license": "MIT",
5
  "private": true,
 
 
 
 
 
 
 
6
  "scripts": {
7
  "dev": "next dev --turbopack -p 4783",
8
  "prebuild": "node scripts/clean-standalone.mjs",
 
3
  "version": "2.1.0",
4
  "license": "MIT",
5
  "private": true,
6
+ "allowScripts": {
7
+ "better-sqlite3@12.9.0": true,
8
+ "esbuild@0.28.1": true,
9
+ "fsevents@2.3.3": true,
10
+ "sharp@0.34.5": true,
11
+ "unrs-resolver@1.6.4": true
12
+ },
13
  "scripts": {
14
  "dev": "next dev --turbopack -p 4783",
15
  "prebuild": "node scripts/clean-standalone.mjs",
public/hf-space-deploy-marker.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "schema_version": 1,
3
- "local_sha": "17eadccc647ef019723113dc6cc21af600da3dcd",
4
- "created_at": "2026-07-20T07:05:18.467Z",
5
- "deploy_id": "8d1b7635-85e0-4e04-af0c-e1a37b53c0a4"
6
  }
 
1
  {
2
  "schema_version": 1,
3
+ "local_sha": "444b7abc99f5bfa03760ceefb2beb0d790f0aba9",
4
+ "created_at": "2026-07-20T08:14:53.507Z",
5
+ "deploy_id": "a25ce1ac-a4d0-4982-bc6d-796a92ff195f"
6
  }
readme-images/cost-breakdown.jpg DELETED

Git LFS Details

  • SHA256: f68f63fccbbaed840a4eec70fbbceec2c802a407a4bbda90014b5c450ce3329e
  • Pointer size: 131 Bytes
  • Size of remote file: 166 kB
readme-images/history.jpg DELETED

Git LFS Details

  • SHA256: 2be7b00a10920ccc8e8ba721fc8ff0ba4206f84cce109527d44fce8a0fbd386d
  • Pointer size: 131 Bytes
  • Size of remote file: 184 kB
readme-images/interface.jpg DELETED

Git LFS Details

  • SHA256: 23c67640b44e6d3ef004a8648f61a75af4566acca942cef2738a71fd3f292312
  • Pointer size: 131 Bytes
  • Size of remote file: 174 kB
readme-images/mask-creation.jpg DELETED

Git LFS Details

  • SHA256: 3ae1280b6be5db4bfeae9d977de251cbca06b2c4a492ad5dc60534f2b46068a0
  • Pointer size: 131 Bytes
  • Size of remote file: 207 kB
readme-images/password-dialog.jpg DELETED
Binary file (14.8 kB)
 
scripts/deploy-hf-space.mjs CHANGED
@@ -2,7 +2,7 @@
2
 
3
  import { spawnSync } from 'node:child_process';
4
  import { randomUUID } from 'node:crypto';
5
- import { cpSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
6
  import { tmpdir } from 'node:os';
7
  import { join } from 'node:path';
8
  import { setTimeout as delay } from 'node:timers/promises';
@@ -21,6 +21,7 @@ const HF_SPACE_GIT_REMOTE_URL = `https://huggingface.co/spaces/${HF_SPACE_ID}`;
21
  const GIT_DEPLOY_AUTHOR_NAME = 'gpt-image-playground deploy';
22
  const GIT_DEPLOY_AUTHOR_EMAIL = 'deploy@localhost';
23
  export const GIT_ARCHIVE_MAX_BUFFER_BYTES = 256 * 1024 * 1024;
 
24
 
25
  function parseArgs(argv) {
26
  assertKnownOptions(argv, ['--help', '-h']);
@@ -88,10 +89,30 @@ function assertCleanGitWorktree() {
88
  }
89
  }
90
 
91
- function prepareSourceTree() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  const sourceDir = mkdtempSync(join(tmpdir(), 'gpt-image-hf-space-'));
93
  const archive = runBinary('git', ['archive', '--format=tar', 'HEAD']);
94
  runText('tar', ['-x', '-C', sourceDir], { input: archive });
 
 
 
95
  return sourceDir;
96
  }
97
 
@@ -142,7 +163,7 @@ export function buildUploadArgs({ sourceDir, localSha, repoSlug, deletePaths = [
142
 
143
  function readLocalGitFiles() {
144
  const output = runText('git', ['-c', 'core.quotePath=false', 'ls-tree', '-r', '-z', '--name-only', 'HEAD']);
145
- return new Set(output.split('\0').filter(Boolean));
146
  }
147
 
148
  function readRemoteFilePaths() {
@@ -216,13 +237,13 @@ function readLocalGitFilesWithDeployMarker() {
216
  return files;
217
  }
218
 
219
- function uploadSourceTree(sourceDir, deployMarker) {
220
  writeDeployMarker(sourceDir, deployMarker);
221
  const deletePaths = findRemoteDeletePaths(readLocalGitFilesWithDeployMarker(), readRemoteFilePaths());
222
  try {
223
  const output = runText(
224
  'hf',
225
- buildUploadArgs({ sourceDir, localSha: deployMarker.local_sha, repoSlug: readRepositorySlug(), deletePaths })
226
  );
227
  return { spaceCommitSha: extractUploadCommitSha(output), transport: 'hf_upload' };
228
  } catch (error) {
@@ -351,10 +372,11 @@ async function deploy() {
351
  assertCleanGitWorktree();
352
  runText('hf', ['auth', 'whoami']);
353
  const localSha = runText('git', ['rev-parse', 'HEAD']);
 
354
  const deployMarker = buildDeployMarker(localSha);
355
- const sourceDir = prepareSourceTree();
356
  try {
357
- const { spaceCommitSha, transport } = uploadSourceTree(sourceDir, deployMarker);
358
  const runtime = await waitForRunning(spaceCommitSha, deployMarker);
359
  const verification = await verifyPublicEndpoints();
360
  console.log(
 
2
 
3
  import { spawnSync } from 'node:child_process';
4
  import { randomUUID } from 'node:crypto';
5
+ import { cpSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
6
  import { tmpdir } from 'node:os';
7
  import { join } from 'node:path';
8
  import { setTimeout as delay } from 'node:timers/promises';
 
21
  const GIT_DEPLOY_AUTHOR_NAME = 'gpt-image-playground deploy';
22
  const GIT_DEPLOY_AUTHOR_EMAIL = 'deploy@localhost';
23
  export const GIT_ARCHIVE_MAX_BUFFER_BYTES = 256 * 1024 * 1024;
24
+ const SPACE_DEPLOY_EXCLUDED_PATH_PREFIXES = ['readme-images/'];
25
 
26
  function parseArgs(argv) {
27
  assertKnownOptions(argv, ['--help', '-h']);
 
89
  }
90
  }
91
 
92
+ export function isSpaceDeployPath(filePath) {
93
+ const normalized = String(filePath || '')
94
+ .replaceAll('\\', '/')
95
+ .replace(/^\.\//, '');
96
+ return normalized.length > 0 && !SPACE_DEPLOY_EXCLUDED_PATH_PREFIXES.some((prefix) => normalized.startsWith(prefix));
97
+ }
98
+
99
+ export function rewriteSpaceReadmeImageSources(readme, repoSlug, localSha) {
100
+ if (!repoSlug?.trim()) throw new Error('repoSlug is required when rewriting Space README image sources.');
101
+ if (!/^[0-9a-f]{40}$/.test(String(localSha || ''))) {
102
+ throw new Error('localSha must be a full git commit SHA when rewriting Space README image sources.');
103
+ }
104
+ return String(readme).replace(/(['"])(?:\.\/)?(readme-images\/[^'"]+)\1/g, (_, quote, imagePath) => {
105
+ return `${quote}https://raw.githubusercontent.com/${repoSlug}/${localSha}/${imagePath}${quote}`;
106
+ });
107
+ }
108
+
109
+ function prepareSourceTree(repoSlug, localSha) {
110
  const sourceDir = mkdtempSync(join(tmpdir(), 'gpt-image-hf-space-'));
111
  const archive = runBinary('git', ['archive', '--format=tar', 'HEAD']);
112
  runText('tar', ['-x', '-C', sourceDir], { input: archive });
113
+ rmSync(join(sourceDir, 'readme-images'), { force: true, recursive: true });
114
+ const readmePath = join(sourceDir, 'README.md');
115
+ writeFileSync(readmePath, rewriteSpaceReadmeImageSources(readFileSync(readmePath, 'utf8'), repoSlug, localSha), 'utf8');
116
  return sourceDir;
117
  }
118
 
 
163
 
164
  function readLocalGitFiles() {
165
  const output = runText('git', ['-c', 'core.quotePath=false', 'ls-tree', '-r', '-z', '--name-only', 'HEAD']);
166
+ return new Set(output.split('\0').filter(isSpaceDeployPath));
167
  }
168
 
169
  function readRemoteFilePaths() {
 
237
  return files;
238
  }
239
 
240
+ function uploadSourceTree(sourceDir, deployMarker, repoSlug) {
241
  writeDeployMarker(sourceDir, deployMarker);
242
  const deletePaths = findRemoteDeletePaths(readLocalGitFilesWithDeployMarker(), readRemoteFilePaths());
243
  try {
244
  const output = runText(
245
  'hf',
246
+ buildUploadArgs({ sourceDir, localSha: deployMarker.local_sha, repoSlug, deletePaths })
247
  );
248
  return { spaceCommitSha: extractUploadCommitSha(output), transport: 'hf_upload' };
249
  } catch (error) {
 
372
  assertCleanGitWorktree();
373
  runText('hf', ['auth', 'whoami']);
374
  const localSha = runText('git', ['rev-parse', 'HEAD']);
375
+ const repoSlug = readRepositorySlug();
376
  const deployMarker = buildDeployMarker(localSha);
377
+ const sourceDir = prepareSourceTree(repoSlug, localSha);
378
  try {
379
+ const { spaceCommitSha, transport } = uploadSourceTree(sourceDir, deployMarker, repoSlug);
380
  const runtime = await waitForRunning(spaceCommitSha, deployMarker);
381
  const verification = await verifyPublicEndpoints();
382
  console.log(
scripts/deploy-hf-space.test.mjs CHANGED
@@ -6,11 +6,13 @@ import {
6
  assertDeployMarkerMatches,
7
  buildDeployMarker,
8
  buildDeployMarkerRouteSource,
 
9
  isHfUploadExistingSpacePolicyError,
10
  buildUploadArgs,
11
  extractUploadCommitSha,
12
  findRemoteDeletePaths,
13
  parseRepositorySlug,
 
14
  waitForRunning
15
  } from './deploy-hf-space.mjs';
16
 
@@ -112,6 +114,23 @@ describe('HF Space deploy script', () => {
112
  assert.ok(GIT_ARCHIVE_MAX_BUFFER_BYTES >= 128 * 1024 * 1024);
113
  });
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  it('adds delete args for remote files that are no longer in git HEAD', () => {
116
  const args = buildUploadArgs({
117
  sourceDir: '/tmp/source',
 
6
  assertDeployMarkerMatches,
7
  buildDeployMarker,
8
  buildDeployMarkerRouteSource,
9
+ isSpaceDeployPath,
10
  isHfUploadExistingSpacePolicyError,
11
  buildUploadArgs,
12
  extractUploadCommitSha,
13
  findRemoteDeletePaths,
14
  parseRepositorySlug,
15
+ rewriteSpaceReadmeImageSources,
16
  waitForRunning
17
  } from './deploy-hf-space.mjs';
18
 
 
114
  assert.ok(GIT_ARCHIVE_MAX_BUFFER_BYTES >= 128 * 1024 * 1024);
115
  });
116
 
117
+ it('excludes README documentation binaries from the Space source tree', () => {
118
+ assert.equal(isSpaceDeployPath('README.md'), true);
119
+ assert.equal(isSpaceDeployPath('src/app/page.tsx'), true);
120
+ assert.equal(isSpaceDeployPath('readme-images/interface.jpg'), false);
121
+ assert.equal(isSpaceDeployPath('readme-images/nested/example.jpg'), false);
122
+ });
123
+
124
+ it('rewrites local README image sources to immutable GitHub sources for the Space', () => {
125
+ const localSha = '1111111111111111111111111111111111111111';
126
+ const readme = '<img src="./readme-images/interface.jpg?v=123" alt="Interface" />';
127
+
128
+ assert.equal(
129
+ rewriteSpaceReadmeImageSources(readme, 'owner/repo', localSha),
130
+ `<img src="https://raw.githubusercontent.com/owner/repo/${localSha}/readme-images/interface.jpg?v=123" alt="Interface" />`
131
+ );
132
+ });
133
+
134
  it('adds delete args for remote files that are no longer in git HEAD', () => {
135
  const args = buildUploadArgs({
136
  sourceDir: '/tmp/source',
src/app/api/deploy-marker/route.ts CHANGED
@@ -1,6 +1,6 @@
1
  import { NextResponse } from 'next/server';
2
 
3
- const deployMarker = {"schema_version":1,"local_sha":"17eadccc647ef019723113dc6cc21af600da3dcd","created_at":"2026-07-20T07:05:18.467Z","deploy_id":"8d1b7635-85e0-4e04-af0c-e1a37b53c0a4"} as const;
4
 
5
  export const dynamic = 'force-dynamic';
6
 
 
1
  import { NextResponse } from 'next/server';
2
 
3
+ const deployMarker = {"schema_version":1,"local_sha":"444b7abc99f5bfa03760ceefb2beb0d790f0aba9","created_at":"2026-07-20T08:14:53.507Z","deploy_id":"a25ce1ac-a4d0-4982-bc6d-796a92ff195f"} as const;
4
 
5
  export const dynamic = 'force-dynamic';
6