HF 通过API重启和重建容器

HuggingFace 根据下述地址,可以包装成容器执行,其抽离出来,主要包括两个功能

HF 通过API重启和重建容器

重启容器

from huggingface_hub import HfApi
import os

def restart_space():
    # Please navigate to Settings > Secrets and variables > Actions and define "HF_TOKEN".
    token = 'hf_xxxxxxxxxxxxxxxxxxx'
    # Please replace this value with the name of your own Hugging Face Space.
    repo_id = "<OWNER>/<SPACE_NAME>"
    # open-webui/open-webui
    
    try:
        HfApi().restart_space(repo_id=repo_id, token=token)
        print(f"Successfully restarted Space: {repo_id}")
    except Exception as e:
        print(f"Failed to restart Space {repo_id}: {e}")

if __name__ == "__main__":
    restart_space()

重建容器

from huggingface_hub import HfApi
import os

def rebuild_space():
    # Please navigate to Settings > Secrets and variables > Actions and define "HF_TOKEN".
    token = 'hf_xxxxxxxxxxxxxxxxxxx'
    # Please replace this value with the name of your own Hugging Face Space.
    repo_id = "<OWNER>/<SPACE_NAME>"
    # open-webui/open-webui
    
    try:
        HfApi().restart_space(repo_id=repo_id, token=token, factory_reboot=True)
        print(f"Successfully rebuild Space: {repo_id}")
    except Exception as e:
        print(f"Failed to rebuild Space {repo_id}: {e}")

if __name__ == "__main__":
    rebuild_space()

推荐部署OpenWebUI的全教程:

部署教程:

PS:开始的开始,感谢佬友的教程和HF大善人

备份数据库:

https://linux.do/t/topic/291087
PS:不知道为啥使用postgre远程连接,速度慢到令人无法接受

直连Gemini:

https://linux.do/t/topic/292141
PS:不需要的模型可以在管理员面板手动关闭

反代加速:

PS:佬友很厉害,效果很明显
关于OpenWebUI更新0.5.x版本之后强制WebSocket支持,反代加速参考该网址代码

推荐的函数:

功能名称 版本 代码标识 简要描述
Run Code - run_code 在开放webui上运行Python代码
Visualize Data v0.0.2 visualize_data 将对话中的数据制作成图表并在聊天中渲染
Artifacts V2 v2.0.0 artifacts_v2 受Claude Artifacts启发的功能,原代码来自atgehrhardt
Chat Metrics v0.0.4 chat_metrics 聊天指标:已用时间、令牌计数(草稿估算)等
DeepLX Translate v1.0 deeplx_translate 使用DeepLX翻译API进行语言转换
Gemini Pipe v0.0.1 gemini_models Google Gemini搜索
HunyuanVideo - hunyuanvideo 使用腾讯混元视频模型

再次感谢上述的佬友,有些函数也是出自他们之手

14 个赞

有点厉害支持~~

2 个赞

感谢分享,在用自己包装的 :tieba_087:

3 个赞

俺写了个快速部署工具 :yum:

3 个赞

huggingface space compose 吗 :tieba_025:

2 个赞

通过在网页上填写表单快速复制部署 :yum: 关键是各种环境变量一网打尽

5 个赞

爱了爱了,务必增加上传 .env文件或 粘贴多行环境变量 :tieba_087:

2 个赞

太强了!大佬

1 个赞

谢谢大佬分享,有没有API可以直接重启的啊

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。