Ray1ee01 commited on
Commit
821e247
·
verified ·
1 Parent(s): cb90fdb

Upload docs/huggingface_download_and_run.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. docs/huggingface_download_and_run.md +158 -0
docs/huggingface_download_and_run.md ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 在新服务器下载并运行 ChartPipeline
2
+
3
+ 本文档说明如何从 Hugging Face Space 下载本项目,并在另一台服务器上运行。
4
+
5
+ ## 1. 下载项目
6
+
7
+ 如果服务器可以直接访问 Hugging Face:
8
+
9
+ ```bash
10
+ pip install -U huggingface_hub
11
+ huggingface-cli download Ray1ee01/ChartPipeline \
12
+ --repo-type space \
13
+ --local-dir ChartPipeline
14
+ cd ChartPipeline
15
+ ```
16
+
17
+ 如果服务器不能直接访问外网,但可以访问 hf-mirror:
18
+
19
+ ```bash
20
+ export HF_ENDPOINT=https://hf-mirror.com
21
+ pip install -U huggingface_hub
22
+ huggingface-cli download Ray1ee01/ChartPipeline \
23
+ --repo-type space \
24
+ --local-dir ChartPipeline
25
+ cd ChartPipeline
26
+ ```
27
+
28
+ 也可以用 Git:
29
+
30
+ ```bash
31
+ git clone https://huggingface.co/spaces/Ray1ee01/ChartPipeline
32
+ cd ChartPipeline
33
+ ```
34
+
35
+ ## 2. 用 Docker 运行 Space Demo
36
+
37
+ 推荐方式。服务器需要已安装 Docker。
38
+
39
+ ```bash
40
+ docker build -t chartpipeline .
41
+ docker run --rm -p 7860:7860 chartpipeline
42
+ ```
43
+
44
+ 然后打开:
45
+
46
+ ```text
47
+ http://服务器IP:7860
48
+ ```
49
+
50
+ 这个 demo 会启动 `app.py`,使用内置示例数据和 chart engine 模板生成 SVG 图表,不需要 API key。
51
+
52
+ ## 3. 不用 Docker 运行 Space Demo
53
+
54
+ 服务器需要 Python 3.10+、Node.js/npm、Chromium 或 Chrome。
55
+
56
+ Ubuntu 示例:
57
+
58
+ ```bash
59
+ sudo apt-get update
60
+ sudo apt-get install -y chromium nodejs npm fonts-dejavu-core fonts-noto-cjk librsvg2-bin
61
+
62
+ python -m venv .venv
63
+ source .venv/bin/activate
64
+ pip install -r requirements-space.txt
65
+
66
+ PUPPETEER_SKIP_DOWNLOAD=1 npm install --omit=dev --no-audit --no-fund puppeteer@24.36.1
67
+ export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
68
+
69
+ python app.py
70
+ ```
71
+
72
+ 访问:
73
+
74
+ ```text
75
+ http://服务器IP:7860
76
+ ```
77
+
78
+ ## 4. 命令行烟测
79
+
80
+ 运行 chart engine,确认浏览器渲染链路正常:
81
+
82
+ ```bash
83
+ PYTHONPATH=. python modules/chart_engine/chart_engine.py \
84
+ --input examples/chart_engine_sample.json \
85
+ --name donut_plain_chart_01 \
86
+ --output /tmp/chartpipeline_sample.svg \
87
+ --html /tmp/chartpipeline_sample.html
88
+ ```
89
+
90
+ 成功时会看到:
91
+
92
+ ```text
93
+ Chart generation succeeded.
94
+ ```
95
+
96
+ 输出文件在:
97
+
98
+ ```text
99
+ /tmp/chartpipeline_sample.svg
100
+ ```
101
+
102
+ ## 5. 运行完整管道
103
+
104
+ 完整管道不只依赖 Space demo 文件,还需要资源目录、模型索引和 API key。
105
+ 当前 Hugging Face 仓库会包含一个 `resources/` 资源包,`config.example.py`
106
+ 默认会从这个目录读取颜色、标题、图像推荐索引和 embedding model。
107
+
108
+ 先复制配置模板:
109
+
110
+ ```bash
111
+ cp config.example.py config.py
112
+ ```
113
+
114
+ 设置环境变量:
115
+
116
+ ```bash
117
+ export OPENAI_API_KEY=你的API_KEY
118
+ export OPENAI_BASE_URL=https://api.openai.com/v1
119
+ export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
120
+ ```
121
+
122
+ 如果你把资源放在其他位置,再额外指定:
123
+
124
+ ```bash
125
+ export CHARTPIPELINE_RESOURCE_PATH=/path/to/resources
126
+ export CHARTPIPELINE_DATA_RESOURCE_DIRS=/path/to/data_pool
127
+ export CHARTPIPELINE_EMBED_MODEL_PATH=/path/to/resources/models/models--sentence-transformers--all-MiniLM-L6-v2/snapshots/fa97f6e7cb1a59073dff9e6b13e2715cf7475ac9
128
+ ```
129
+
130
+ 安装完整依赖:
131
+
132
+ ```bash
133
+ pip install -r requirements.txt
134
+ PUPPETEER_SKIP_DOWNLOAD=1 npm install
135
+ ```
136
+
137
+ 如果只需要验证图表模板,优先使用第 4 节的 chart engine 命令;完整 `pipeline.py` 需要确认 `config.py` 指向的资源目录真实存在。
138
+
139
+ 注意:全量图片素材库很大,原始图标和图片文件可能超过 25GB。仓库内资源包优先保证索引、metadata 和模型可用;如果你的任务需要 image recommender 输出真实图片 base64,需要同时准备完整的 `resources/image/images/` 和 `resources/image/attribute_icons/icons/` 素材目录。
140
+
141
+ ## 6. 常见问题
142
+
143
+ 如果下载失败,先确认是否需要 mirror:
144
+
145
+ ```bash
146
+ export HF_ENDPOINT=https://hf-mirror.com
147
+ ```
148
+
149
+ 如果 Puppeteer 报找不到浏览器:
150
+
151
+ ```bash
152
+ which chromium || which google-chrome
153
+ export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
154
+ ```
155
+
156
+ 如果 Chromium 在容器或服务器上启动失败,确认启动参数里包含 `--no-sandbox`。本项目的渲染脚本已经默认配置该参数。
157
+
158
+ 不要把真实 `config.py`、API key、`node_modules/`、`tmp/`、`output/` 上传到公开仓库。