Spaces:
Running
Running
lixiaowww Cursor commited on
Commit ·
429404e
1
Parent(s): 22761ba
Deploy Streamlit on HF Spaces via Docker (Streamlit SDK deprecated).
Browse filesAdd Dockerfile, .dockerignore, and updated setup guide for app_port 8501.
Co-authored-by: Cursor <cursoragent@cursor.com>
- .dockerignore +18 -0
- Dockerfile +26 -0
- README.md +4 -4
- deploy/huggingface/SPACE_README.md +22 -0
- docs/HUGGINGFACE.md +81 -81
.dockerignore
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
.venv/
|
| 3 |
+
.git/
|
| 4 |
+
__pycache__/
|
| 5 |
+
*.py[cod]
|
| 6 |
+
.pytest_cache/
|
| 7 |
+
.mypy_cache/
|
| 8 |
+
.env
|
| 9 |
+
.env.*
|
| 10 |
+
!.env.example
|
| 11 |
+
data/forecaster.db
|
| 12 |
+
data/bls_cache.json
|
| 13 |
+
data/kb_calibration.json
|
| 14 |
+
data/kb_calibration_log.jsonl
|
| 15 |
+
pending/
|
| 16 |
+
=0.9
|
| 17 |
+
nodeids
|
| 18 |
+
CACHEDIR.TAG
|
Dockerfile
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Spaces — Streamlit via Docker (native Streamlit SDK deprecated 2025-04)
|
| 2 |
+
# https://huggingface.co/docs/hub/spaces-changelog
|
| 3 |
+
FROM python:3.12-slim
|
| 4 |
+
|
| 5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends curl \
|
| 6 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 7 |
+
&& useradd -m -u 1000 user
|
| 8 |
+
|
| 9 |
+
USER user
|
| 10 |
+
WORKDIR /home/user/app
|
| 11 |
+
|
| 12 |
+
ENV STREAMLIT_HOME=/tmp/.streamlit
|
| 13 |
+
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
|
| 14 |
+
ENV PYTHONUNBUFFERED=1
|
| 15 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 16 |
+
|
| 17 |
+
COPY --chown=user:user requirements.txt requirements-dashboard.txt ./
|
| 18 |
+
RUN pip install --user --no-cache-dir -r requirements.txt
|
| 19 |
+
|
| 20 |
+
COPY --chown=user:user . .
|
| 21 |
+
|
| 22 |
+
EXPOSE 8501
|
| 23 |
+
|
| 24 |
+
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
|
| 25 |
+
|
| 26 |
+
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
README.md
CHANGED
|
@@ -153,14 +153,14 @@ See **[docs/DEPLOY.md](docs/DEPLOY.md)** for setup (Pages, `GROQ_API_KEY` secret
|
|
| 153 |
|
| 154 |
### Interactive dashboard (Hugging Face Spaces)
|
| 155 |
|
| 156 |
-
|
| 157 |
|
| 158 |
```bash
|
| 159 |
-
streamlit run
|
| 160 |
-
|
| 161 |
```
|
| 162 |
|
| 163 |
-
See **[docs/HUGGINGFACE.md](docs/HUGGINGFACE.md)**
|
| 164 |
|
| 165 |
---
|
| 166 |
|
|
|
|
| 153 |
|
| 154 |
### Interactive dashboard (Hugging Face Spaces)
|
| 155 |
|
| 156 |
+
> HF 已弃用原生 Streamlit SDK(2025-04)→ 创建 Space 时选 **Docker**,仓库内已含 `Dockerfile`。
|
| 157 |
|
| 158 |
```bash
|
| 159 |
+
streamlit run app.py # local
|
| 160 |
+
docker build -t jobforecaster . && docker run -p 8501:8501 jobforecaster # optional
|
| 161 |
```
|
| 162 |
|
| 163 |
+
See **[docs/HUGGINGFACE.md](docs/HUGGINGFACE.md)**.
|
| 164 |
|
| 165 |
---
|
| 166 |
|
deploy/huggingface/SPACE_README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: JobForecaster Agent
|
| 3 |
+
emoji: 🔮
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 8501
|
| 8 |
+
license: other
|
| 9 |
+
pinned: false
|
| 10 |
+
short_description: Streamlit Job Radar & AI economy forecast dashboard
|
| 11 |
+
tags:
|
| 12 |
+
- streamlit
|
| 13 |
+
- docker
|
| 14 |
+
- economics
|
| 15 |
+
- job-market
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# JobForecaster Agent — Interactive Dashboard
|
| 19 |
+
|
| 20 |
+
Copy this file to the **root `README.md`** of your Hugging Face Space repo, or ensure your linked GitHub Space uses **SDK: Docker** with `app_port: 8501`.
|
| 21 |
+
|
| 22 |
+
Static reports: [GitHub Pages](https://lixiaowww.github.io/JobForecaster-Agent/)
|
docs/HUGGINGFACE.md
CHANGED
|
@@ -1,136 +1,136 @@
|
|
| 1 |
# Hugging Face Spaces 部署指南
|
| 2 |
|
| 3 |
-
把 **Streamlit 交互 Dashboard**
|
| 4 |
|
| 5 |
-
> **
|
| 6 |
-
> **
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
##
|
| 15 |
|
| 16 |
1. 打开 [huggingface.co/new-space](https://huggingface.co/new-space)
|
| 17 |
2. 填写:
|
| 18 |
-
| 字段 | 值 |
|
| 19 |
-
|------|-----|
|
| 20 |
-
| Owner | 你的 HF 账号(如 `lixiaowww`) |
|
| 21 |
-
| Space name | `JobForecaster-Agent`(或任意名) |
|
| 22 |
-
| License | 与仓库一致 |
|
| 23 |
-
| Space SDK | **Streamlit** |
|
| 24 |
-
| Space hardware | **CPU basic**(免费) |
|
| 25 |
-
3. **不要**选 Docker;选 **Link to a Git repository**(若界面有)
|
| 26 |
-
4. 创建
|
| 27 |
-
|
| 28 |
-
### 2. 连接 GitHub 仓库
|
| 29 |
-
|
| 30 |
-
1. Space 页面 → **Settings** → **Repository**
|
| 31 |
-
2. **Repository URL**:`https://github.com/lixiaowww/JobForecaster-Agent`
|
| 32 |
-
3. **Branch**:`main`
|
| 33 |
-
4. **App file**:`app.py`
|
| 34 |
-
5. Save → 等待自动构建(约 3–8 分钟)
|
| 35 |
-
|
| 36 |
-
若创建时未出现 Git 连接选项:
|
| 37 |
-
|
| 38 |
-
1. 先创建空白 Streamlit Space
|
| 39 |
-
2. Settings → Repository → 填上述 URL
|
| 40 |
-
3. App file 设为 `app.py`
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|------|-------|------|
|
| 48 |
-
| `GROQ_API_KEY` | 你的 Groq key | [console.groq.com](https://console.groq.com) 免费档 |
|
| 49 |
|
| 50 |
-
|
| 51 |
-
- **无 key**:Radar / BLS / 情景滑块仍可用,仅 AI 生成岗位不可用
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
|
| 59 |
-
`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
---
|
| 64 |
|
| 65 |
-
##
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
3. 用 `git clone` Space 仓库,把本项目代码 push 上去(或 GitHub Action 同步)
|
| 72 |
|
| 73 |
---
|
| 74 |
|
| 75 |
-
##
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
|------|------|
|
| 79 |
-
| `
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
| `.streamlit/config.toml` | 云端 headless + HF 兼容设置 |
|
| 83 |
-
| `data/jobs_kb.json` | 岗位知识库(已入库) |
|
| 84 |
-
| `data/bls_market_seed.json` | 离线 BLS 实证层 |
|
| 85 |
|
| 86 |
---
|
| 87 |
|
| 88 |
-
##
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
| 94 |
|
| 95 |
---
|
| 96 |
|
| 97 |
## 常见问题
|
| 98 |
|
| 99 |
-
###
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
| 104 |
|
| 105 |
-
-
|
| 106 |
-
-
|
| 107 |
-
-
|
| 108 |
|
| 109 |
-
###
|
| 110 |
|
| 111 |
-
|
| 112 |
-
预测数据在 **GitHub Pages 报告** 或本地 `run.py once` 产生;HF 主要展示 **Job Radar**。
|
| 113 |
|
| 114 |
-
###
|
| 115 |
|
| 116 |
-
|
| 117 |
-
- 不适合高并发;个人 demo / donation 项目足够
|
| 118 |
|
| 119 |
---
|
| 120 |
|
| 121 |
-
##
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
```bash
|
| 126 |
-
git
|
| 127 |
-
git commit -m "Add Hugging Face Spaces Streamlit deploy"
|
| 128 |
-
git push origin main
|
| 129 |
```
|
| 130 |
|
| 131 |
---
|
| 132 |
|
| 133 |
-
## 相关
|
| 134 |
|
| 135 |
-
- [docs/DEPLOY.md](DEPLOY.md) — GitHub Pages
|
| 136 |
-
- [
|
|
|
|
| 1 |
# Hugging Face Spaces 部署指南
|
| 2 |
|
| 3 |
+
把 **Streamlit 交互 Dashboard** 部署到 [Hugging Face Spaces](https://huggingface.co/spaces) 免费档。
|
| 4 |
|
| 5 |
+
> **重要(2025 年起)**:Hugging Face **已移除原生 Streamlit SDK**([changelog 2025-04-30](https://huggingface.co/docs/hub/spaces-changelog))。
|
| 6 |
+
> 创建 Space 时请选择 **Docker**,不要找 Streamlit 选项。
|
| 7 |
|
| 8 |
+
| 服务 | 内容 |
|
| 9 |
+
|------|------|
|
| 10 |
+
| [GitHub Pages](https://lixiaowww.github.io/JobForecaster-Agent/) | 静态每日预测报告 |
|
| 11 |
+
| **HF Spaces** | 交互 Streamlit(Job Radar 等) |
|
| 12 |
|
| 13 |
+
---
|
| 14 |
|
| 15 |
+
## 第一步:创建 Space(选 Docker)
|
| 16 |
|
| 17 |
1. 打开 [huggingface.co/new-space](https://huggingface.co/new-space)
|
| 18 |
2. 填写:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
| 字段 | 选择 |
|
| 21 |
+
|------|------|
|
| 22 |
+
| Space name | `JobForecaster-Agent` |
|
| 23 |
+
| **SDK** | **Docker** ← 不是 Streamlit |
|
| 24 |
+
| Hardware | **CPU basic**(免费) |
|
| 25 |
+
| License | 与仓库一致 |
|
| 26 |
|
| 27 |
+
3. 点 **Create Space**
|
| 28 |
|
| 29 |
+
---
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
## 第二步:连接 GitHub 仓库
|
|
|
|
| 32 |
|
| 33 |
+
### 方式 A:Space 设置里连 GitHub(推荐)
|
| 34 |
|
| 35 |
+
1. Space → **Settings** → **Repository**
|
| 36 |
+
2. **Repository URL**:`https://github.com/lixiaowww/JobForecaster-Agent`
|
| 37 |
+
3. **Branch**:`main`
|
| 38 |
+
4. Save → 自动用仓库根目录的 **`Dockerfile`** 构建
|
| 39 |
|
| 40 |
+
### 方式 B:推送到 HF Git 仓库
|
| 41 |
|
| 42 |
+
```bash
|
| 43 |
+
# 在 HF Space 页面复制 git clone 地址后:
|
| 44 |
+
git remote add hf https://huggingface.co/spaces/<你的用户名>/JobForecaster-Agent
|
| 45 |
+
git push hf main
|
| 46 |
+
```
|
| 47 |
|
| 48 |
+
首次 push 若冲突,按 HF 提示 `git push --force`(仅首次)。
|
| 49 |
|
| 50 |
---
|
| 51 |
|
| 52 |
+
## 仓库里已准备好的文件
|
| 53 |
|
| 54 |
+
| 文件 | 作用 |
|
| 55 |
+
|------|------|
|
| 56 |
+
| `Dockerfile` | Streamlit + 依赖,`EXPOSE 8501` |
|
| 57 |
+
| `app.py` | 入口(`import dashboard`) |
|
| 58 |
+
| `.dockerignore` | 排除 `venv/`、`.env` 等 |
|
| 59 |
+
| `requirements.txt` | 含 Streamlit 依赖 |
|
| 60 |
|
| 61 |
+
`README.md` 顶部 **无需** YAML(选 Docker SDK 创建即可)。
|
| 62 |
+
若 HF 要求 metadata,把 `deploy/huggingface/SPACE_README.md` 的 YAML 块合并进 Space 的 README。
|
|
|
|
| 63 |
|
| 64 |
---
|
| 65 |
|
| 66 |
+
## 第三步:Secrets(可选)
|
| 67 |
|
| 68 |
+
Space → **Settings** → **Repository secrets**
|
| 69 |
+
|
| 70 |
+
| Name | 说明 |
|
| 71 |
|------|------|
|
| 72 |
+
| `GROQ_API_KEY` | [Groq 免费 key](https://console.groq.com),用于 LLM 扩岗位 KB |
|
| 73 |
+
|
| 74 |
+
无 key 时 Radar / BLS / 情景滑块仍可用。
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
---
|
| 77 |
|
| 78 |
+
## 构建成功标志
|
| 79 |
|
| 80 |
+
- Logs 出现 `You can now view your Streamlit app`
|
| 81 |
+
- 健康检查:`/_stcore/health` 通过
|
| 82 |
+
- 访问:`https://huggingface.co/spaces/<用户名>/JobForecaster-Agent`
|
| 83 |
+
|
| 84 |
+
首次或休眠唤醒后可能等 1–3 分钟。
|
| 85 |
|
| 86 |
---
|
| 87 |
|
| 88 |
## 常见问题
|
| 89 |
|
| 90 |
+
### 创建页没有 Streamlit?
|
| 91 |
+
|
| 92 |
+
正常。请选 **Docker**,本项目已提供 `Dockerfile`([官方说明](https://huggingface.co/docs/hub/spaces-sdks-docker))。
|
| 93 |
|
| 94 |
+
### 503 / Preparing Space 一直转
|
| 95 |
|
| 96 |
+
检查三处端口一致为 **8501**:
|
| 97 |
|
| 98 |
+
- `Dockerfile` → `EXPOSE 8501` 与 `ENTRYPOINT ... --server.port=8501`
|
| 99 |
+
- Space README YAML(若有)→ `app_port: 8501`
|
| 100 |
+
- 不要用 `app_port: 7860`(那是 Gradio 默认)
|
| 101 |
|
| 102 |
+
### 构建失败 ModuleNotFoundError
|
| 103 |
|
| 104 |
+
确认 `main` 分支已 push 最新 `requirements.txt`(含 `-r requirements-dashboard.txt`)。
|
|
|
|
| 105 |
|
| 106 |
+
### Accuracy 页为空
|
| 107 |
|
| 108 |
+
Space 无 `forecaster.db`(未入库)。预测历史见 GitHub Pages;HF 主要用于 **Job Radar**。
|
|
|
|
| 109 |
|
| 110 |
---
|
| 111 |
|
| 112 |
+
## 本地对比
|
| 113 |
|
| 114 |
+
```bash
|
| 115 |
+
# 本地 Streamlit(与 HF 相同 UI)
|
| 116 |
+
streamlit run app.py
|
| 117 |
+
|
| 118 |
+
# 本地模拟 Docker 构建(可选)
|
| 119 |
+
docker build -t jobforecaster .
|
| 120 |
+
docker run -p 8501:8501 jobforecaster
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
## 推送更新
|
| 126 |
|
| 127 |
```bash
|
| 128 |
+
git push origin main # 若 Space 已连 GitHub,会自动重建
|
|
|
|
|
|
|
| 129 |
```
|
| 130 |
|
| 131 |
---
|
| 132 |
|
| 133 |
+
## 相关
|
| 134 |
|
| 135 |
+
- [docs/DEPLOY.md](DEPLOY.md) — GitHub Pages
|
| 136 |
+
- [Docker Spaces 文档](https://huggingface.co/docs/hub/spaces-sdks-docker)
|