HuggingFace使用指南:下载模型到发布完整教程
🩺 摘要
每次看教程都让你「去HuggingFace下载模型」,但第一次上去完全懵了——几万个模型、几十万个数据集、还有Spaces、Pipelines……到底怎么用?
📝 详情
HuggingFace是什么
HuggingFace是AI界的GitHub。大家在这里: - 上传训练好的模型 - 分享数据集 - 部署AI演示 - 看别人的代码
截至2026年7月,HuggingFace上有超过100万个模型。
下载模型
方法一:网页下载(新手)
去 huggingface.co/models,搜索你要的模型(比如Qwen2.5-7B)。点「Files and versions」,下载GGUF文件。
方法二:Python下载(推荐)
pip install huggingface_hub
from huggingface_hub import snapshot_download
# 下载整个模型
snapshot_download(
repo_id="Qwen/Qwen2.5-7B-Instruct-GGUF",
local_dir="./models/qwen2.5",
ignore_patterns=["*.safetensors"] # 只下GGUF
)
方法三:命令行
# 下载单个文件
huggingface-cli download Qwen/Qwen2.5-7B-Instruct-GGUF qwen2.5-7b-instruct-q4_k_m.gguf --local-dir ./models
使用模型
pip install transformers
from transformers import pipeline
# 一行代码加载模型
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased")
result = classifier("I love HuggingFace!")
print(result)
# [{'label': 'POSITIVE', 'score': 0.9998}]
所有模型都统一接口,换模型名就行。
搜索技巧
- 按任务筛选(text-generation、image-classification)
- 按语言筛选(Chinese、Japanese)
- 按热度排序(Most Downloaded)
- 搜GGUF格式(本地部署专用)
热门搜索词: - Qwen GGUF — 阿里模型本地版 - DeepSeek GGUF — 深度求索模型本地版 - Llama GGUF — Meta模型本地版
发布自己的模型
# 1. 登录
huggingface-cli login
# 2. 创建仓库(网页上点New Model)
# 3. 上传
huggingface-cli upload your-username/your-model ./local-model-folder
Spaces:在线演示
HuggingFace Spaces让你免费部署AI应用演示。用Gradio或Streamlit写个界面,上传就自动部署:
import gradio as gr
def greet(name):
return f"Hello {name}!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()
一句话
HuggingFace = AI模型版的淘宝。搜、下载、用、发布,一条龙。
💬 评论 (0)