模型和数据集的平台之在Hugging Face上进行模型下载、上传以及创建专属Space

模型下载

步骤:

注册Hugging Face平台

复制代码
https://huggingface.co/ 

新建一个hf_download_josn.py 文件

bash 复制代码
touch hf_download_josn.py

编写hf_download_josn.py文件

python 复制代码
import os
from huggingface_hub import hf_hub_download

# 指定模型标识符
repo_id = "internlm/internlm2_5-7b"

# 指定要下载的文件列表
files_to_download = [
    {"filename": "config.json"},
    {"filename": "model.safetensors.index.json"}
]

# 创建一个目录来存放下载的文件
local_dir = f"{repo_id.split('/')[1]}"
os.makedirs(local_dir, exist_ok=True)

# 遍历文件列表并下载每个文件
for file_info in files_to_download:
    file_path = hf_hub_download(
        repo_id=repo_id,
        filename=file_info["filename"],
        local_dir=local_dir
    )
    print(f"{file_info['filename']} file downloaded to: {file_path}")

运行模型下载

bash 复制代码
python hf_download_josn.py

从Hugging Face上看下载了相应配置文件

模型上传

通过CLI上传 Hugging Face

bash 复制代码
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
git lfs install # 直接在git环境下配置git LFS
pip install huggingface_hub

在CodeSpace里面,使用

bash 复制代码
git config --global credential.helper store
huggingface-cli login

创建项目

bash 复制代码
cd /workspaces/codespaces-jupyter

#创建项目
huggingface-cli repo create intern_study_L0_4


git clone https://huggingface.co/{your_huggingface_name}/intern_study_L0_4

把要上传的模型上传上去

bash 复制代码
git add .
git commit -m "add:intern_study_L0_4"
git push  origin

Hugging Face的个人profile里面看到这个mode

创建space

Spaces 使得开发者可以快速将我们的模型部署为可交互的 web 应用,且无需担心后端基础设施或部署的复杂性

复制代码
https://huggingface.co/spaces

在右上角点击Create new Space进行创建

在创建页面中,输入项目名为intern_cobuild,并选择Static应用进行创建

复制代码

在修改默认的html

克隆到本地修改默认html

git clone https://huggingface.co/spaces/\<your_username>/intern_cobuild cd /workspaces/codespaces-jupyter/intern_cobuild

bash 复制代码
<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width" />
  <title>My static Space</title>
  <style>
    html, body {
      margin: 0;
      padding: 0;
      height: 100%;
    }
    body {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    iframe {
      width: 430px;
      height: 932px;
      border: none;
    }
  </style>
</head>
<body>
  <iframe src="https://colearn.intern-ai.org.cn/cobuild" title="description"></iframe>
</body>
</html>

推送代码的到HF

git add .

git commit -m "修改默认文件"

git push origin

进入到HF平台查看spaces

相关推荐
濑户川几秒前
Vue3 项目创建指南(Vue-CLI vs Vite 对比)
前端·javascript·vue.js
啊吧怪不啊吧7 分钟前
SQL之表的增删
服务器·数据库·sql·1024程序员节
Mintopia7 分钟前
🚀 Next.js 16 新特性深度解析:当框架开始思考人生
前端·后端·全栈
鼓掌MVP8 分钟前
Rust Web实战:构建高性能并发工具的艺术
开发语言·前端·rust·异步编程·内存安全·actix-web·高性能web服务
Mintopia18 分钟前
🌌 元宇宙 Web 场景中,AIGC 驱动的虚拟内容生成技术
前端·javascript·aigc
excel28 分钟前
一文彻底搞懂 Vue3 中 ref 的源码实现(含详细注释)
前端
鹏多多29 分钟前
react-konva实战指南:Canvas高性能+易维护的组件化图形开发实现教程
前端·javascript·react.js
excel31 分钟前
一文彻底搞懂 Vue 中的 key(含 Vue2 / Vue3 对比)
前端
zhaotiannuo_199836 分钟前
【Linux kali 更换yum源】
linux·运维·服务器
草莓熊Lotso1 小时前
模板进阶:从非类型参数到分离编译,吃透 C++ 泛型编程的核心逻辑
linux·服务器·开发语言·c++·人工智能·笔记·后端