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 | 使用腾讯混元视频模型 |