diff --git a/docs/backend.md b/docs/backend.md index 058ab1a11..9bc6607c3 100644 --- a/docs/backend.md +++ b/docs/backend.md @@ -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 证书。 | @@ -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。 diff --git a/docs/static/hugging-7.png b/docs/static/hugging-7.png new file mode 100644 index 000000000..038200128 Binary files /dev/null and b/docs/static/hugging-7.png differ diff --git a/docs/static/hugging-8.png b/docs/static/hugging-8.png new file mode 100644 index 000000000..4007d2bec Binary files /dev/null and b/docs/static/hugging-8.png differ diff --git a/docs/static/hugging-9.png b/docs/static/hugging-9.png new file mode 100644 index 000000000..50d410009 Binary files /dev/null and b/docs/static/hugging-9.png differ diff --git a/src/server/hf-space/.gitattributes b/src/server/hf-space/.gitattributes new file mode 100644 index 000000000..a6344aac8 --- /dev/null +++ b/src/server/hf-space/.gitattributes @@ -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 diff --git a/src/server/hf-space/Dockerfile b/src/server/hf-space/Dockerfile new file mode 100644 index 000000000..389ee34ca --- /dev/null +++ b/src/server/hf-space/Dockerfile @@ -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"] diff --git a/src/server/hf-space/README.md b/src/server/hf-space/README.md new file mode 100644 index 000000000..f81e4ea77 --- /dev/null +++ b/src/server/hf-space/README.md @@ -0,0 +1,9 @@ +--- +title: Twikoo Huggingface Space +emoji: 📚 +colorFrom: yellow +colorTo: indigo +sdk: docker +pinned: false +app_port: 8080 +--- \ No newline at end of file diff --git a/src/server/hf-space/src/start.sh b/src/server/hf-space/src/start.sh new file mode 100644 index 000000000..80997626e --- /dev/null +++ b/src/server/hf-space/src/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +nohup /usr/local/bin/cloudflared tunnel --no-autoupdate run --token $CF_ZERO_TRUST_TOKEN & +tkserver \ No newline at end of file