Skip to content

Commit

Permalink
feat: ✨ 支持Huggingface Space部署方式使用Cloudflare Tunnels自定义访问域名
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshino-Yumetsuki committed May 25, 2024
1 parent d53739a commit 6a17c74
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| [Railway 部署](#railway-部署) | ★★☆☆☆ | 有免费额度但不足以支持一个月连续运行,部署简单,适合全球访问。 |
| [Zeabur 部署](#zeabur-部署) | ★☆☆☆☆ | 需要绑定支付宝或信用卡,部署简单,适合中国大陆访问,免费计划环境随时可能会被删除。 |
| [Netlify 部署](#netlify-部署) | ★★★★☆ | 有充足的免费额度,中国大陆访问速度不错。 |
| [Hugging Face 部署](#hugging-face-部署) | ★★★★☆ | 免费,中国大陆访问速度不错。 |
| [Hugging Face 部署](#hugging-face-部署) | ★★★★☆ | 免费,中国大陆访问速度不错。允许通过Cloudflare Tunnels自定义域名。 |
| [AWS Lambda 部署](#aws-lambda-部署) | ★★★☆☆ | 全球最大的云平台,适合已经使用 AWS 全家桶的用户。 |
| [Cloudflare workers 部署](#cloudflare-workers-部署) | ★★☆☆☆ | 部署需使用命令行,冷启动时间较短,功能有部分限制。 |
| [私有部署](#私有部署) | ★★☆☆☆ | 适用于有服务器的用户,需要自行申请 HTTPS 证书。 |
Expand Down Expand Up @@ -208,6 +208,27 @@ EXPOSE 7860

![](./static/hugging-6.png)

### 如果你需要自定义域名

> ps:除了`CF_ZERO_TRUST_TOKEN`这个环境变量以外,其他环境变量的配置方式与上一步相同
1. 申请Cloudflare Zero Trust,关于申请方式请自行查找

![](./static/hugging-7.png)

2. 添加一条隧道,连接方式选择Cloudflared,名称任意

![](./static/hugging-8.png)

3.添加一个Public Hostname,回源选择HTTP,端口选择8080
4.Clone Twikoo仓库,找到src\server\hf-space
5.去Huggingface创建一个Space,然后Clone下来,将hf-space文件夹内的所有内容复制进去
6.在Huggingface Space的设置中添加一个环境变量,变量名`CF_ZERO_TRUST_TOKEN`,值是Tunnels给的令牌(删掉`cloudflared.exe service install`,只保留令牌部分)

![](./static/hugging-9.png)

7.Push从Huggingface Space仓库

## AWS Lambda 部署

1. 注册 AWS 账号并配置 Terraform CLI。
Expand Down
Binary file added docs/static/hugging-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/hugging-8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/hugging-9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/server/hf-space/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
20 changes: 20 additions & 0 deletions src/server/hf-space/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine AS build

RUN adduser -D app

USER root
RUN apk --no-cache add curl nodejs npm git

RUN npm i tkserver -g

WORKDIR /home/app
RUN curl -LO https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && \
chmod +x cloudflared-linux-amd64 && \
mv cloudflared-linux-amd64 /usr/local/bin/cloudflared

COPY ./src/start.sh /usr/bin/start.sh

USER app
WORKDIR /home/app/twikoo

CMD ["sh", "/usr/bin/start.sh"]
9 changes: 9 additions & 0 deletions src/server/hf-space/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Twikoo Huggingface Space
emoji: 📚
colorFrom: yellow
colorTo: indigo
sdk: docker
pinned: false
app_port: 8080
---
4 changes: 4 additions & 0 deletions src/server/hf-space/src/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

nohup /usr/local/bin/cloudflared tunnel --no-autoupdate run --token $CF_ZERO_TRUST_TOKEN &
tkserver

0 comments on commit 6a17c74

Please sign in to comment.