xiaoshiai-hub 0.1.3__tar.gz → 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xiaoshiai_hub-1.0.1/PKG-INFO +473 -0
- xiaoshiai_hub-1.0.1/README.md +418 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/pyproject.toml +10 -11
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/setup.py +11 -10
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub/__init__.py +2 -27
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub/client.py +11 -58
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub/download.py +20 -199
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub/exceptions.py +1 -5
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub/types.py +0 -16
- xiaoshiai_hub-1.0.1/xiaoshiai_hub/upload.py +619 -0
- xiaoshiai_hub-1.0.1/xiaoshiai_hub.egg-info/PKG-INFO +473 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub.egg-info/SOURCES.txt +0 -12
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub.egg-info/requires.txt +0 -7
- xiaoshiai_hub-0.1.3/PKG-INFO +0 -560
- xiaoshiai_hub-0.1.3/README.md +0 -498
- xiaoshiai_hub-0.1.3/README_EN.md +0 -348
- xiaoshiai_hub-0.1.3/examples/01_basic_usage.py +0 -168
- xiaoshiai_hub-0.1.3/examples/02_download_file.py +0 -196
- xiaoshiai_hub-0.1.3/examples/03_download_repository.py +0 -260
- xiaoshiai_hub-0.1.3/examples/04_upload_file.py +0 -288
- xiaoshiai_hub-0.1.3/examples/05_upload_folder.py +0 -328
- xiaoshiai_hub-0.1.3/examples/06_encryption.py +0 -317
- xiaoshiai_hub-0.1.3/examples/07_complete_workflow.py +0 -376
- xiaoshiai_hub-0.1.3/examples/README.md +0 -344
- xiaoshiai_hub-0.1.3/requirements-dev.txt +0 -28
- xiaoshiai_hub-0.1.3/requirements-test.txt +0 -12
- xiaoshiai_hub-0.1.3/xiaoshiai_hub/encryption.py +0 -777
- xiaoshiai_hub-0.1.3/xiaoshiai_hub/upload.py +0 -853
- xiaoshiai_hub-0.1.3/xiaoshiai_hub.egg-info/PKG-INFO +0 -560
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/LICENSE +0 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/MANIFEST.in +0 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/requirements.txt +0 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/setup.cfg +0 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub.egg-info/dependency_links.txt +0 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub.egg-info/not-zip-safe +0 -0
- {xiaoshiai_hub-0.1.3 → xiaoshiai_hub-1.0.1}/xiaoshiai_hub.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xiaoshiai-hub
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Python SDK for XiaoShi AI Hub - Upload, download, and manage AI models and datasets with xpai-enc encryption support
|
|
5
|
+
Home-page: https://github.com/poxiaoyun/moha-sdk
|
|
6
|
+
Author: XiaoShi AI
|
|
7
|
+
Author-email: XiaoShi AI <support@xiaoshiai.cn>
|
|
8
|
+
Maintainer: XiaoShi AI Team
|
|
9
|
+
Maintainer-email: XiaoShi AI Team <support@xiaoshiai.cn>
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
Project-URL: Homepage, https://github.com/poxiaoyun/moha-sdk
|
|
12
|
+
Project-URL: Repository, https://github.com/poxiaoyun/moha-sdk
|
|
13
|
+
Project-URL: Issues, https://github.com/poxiaoyun/moha-sdk/issues
|
|
14
|
+
Keywords: xiaoshi,ai-hub,machine-learning,deep-learning,model-hub,dataset,encryption,xpai-enc,sdk,api-client,model-encryption
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
28
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
29
|
+
Requires-Python: >=3.7
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: requests>=2.20.0
|
|
33
|
+
Requires-Dist: tqdm>=4.62.0
|
|
34
|
+
Provides-Extra: upload
|
|
35
|
+
Requires-Dist: gitpython>=3.1.0; extra == "upload"
|
|
36
|
+
Provides-Extra: encryption
|
|
37
|
+
Provides-Extra: dev
|
|
38
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
39
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pytest-mock>=3.6.0; extra == "dev"
|
|
41
|
+
Requires-Dist: black>=22.0; extra == "dev"
|
|
42
|
+
Requires-Dist: flake8>=4.0; extra == "dev"
|
|
43
|
+
Requires-Dist: mypy>=0.950; extra == "dev"
|
|
44
|
+
Requires-Dist: isort>=5.10.0; extra == "dev"
|
|
45
|
+
Requires-Dist: build>=0.8.0; extra == "dev"
|
|
46
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
47
|
+
Requires-Dist: gitpython>=3.1.0; extra == "dev"
|
|
48
|
+
Provides-Extra: all
|
|
49
|
+
Requires-Dist: gitpython>=3.1.0; extra == "all"
|
|
50
|
+
Dynamic: author
|
|
51
|
+
Dynamic: home-page
|
|
52
|
+
Dynamic: license-file
|
|
53
|
+
Dynamic: maintainer
|
|
54
|
+
Dynamic: requires-python
|
|
55
|
+
|
|
56
|
+
# XiaoShi AI Hub Python SDK
|
|
57
|
+
|
|
58
|
+
[](https://badge.fury.io/py/xiaoshiai-hub)
|
|
59
|
+
[](https://pypi.org/project/xiaoshiai-hub/)
|
|
60
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
61
|
+
|
|
62
|
+
XiaoShi AI Hub Python SDK 是一个功能强大的 Python 库,用于与 XiaoShi AI Hub 平台进行交互。它提供了简单易用的 API,支持模型和数据集的上传、下载,并集成了 [xpai-enc](https://github.com/poxiaoyun/xpai-enc) 提供的透明加密功能。
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## ✨ 特性
|
|
66
|
+
|
|
67
|
+
- 🚀 **简单易用** - 类似 Hugging Face Hub 的 API 设计,上手即用
|
|
68
|
+
- 📥 **下载功能** - 支持下载单个文件或整个仓库
|
|
69
|
+
- 📤 **上传功能** - 支持上传文件和文件夹到仓库
|
|
70
|
+
- 🔐 **智能加密** - 集成 xpai-enc,自动加密大型模型文件(≥5MB 的 .safetensors、.bin、.pt、.pth、.ckpt 文件)
|
|
71
|
+
- 🎯 **模式匹配** - 支持使用 allow/ignore 模式过滤文件
|
|
72
|
+
- 📊 **进度显示** - 下载和上传时显示进度条
|
|
73
|
+
- 🔑 **多种认证** - 支持用户名/密码和 Token 认证
|
|
74
|
+
- 🌐 **环境变量配置** - 灵活的 Hub URL 配置
|
|
75
|
+
- 💾 **缓存支持** - 高效的文件缓存机制
|
|
76
|
+
- 🔍 **类型提示** - 完整的类型注解,IDE 友好
|
|
77
|
+
- ✅ **仓库验证** - 上传前自动检查仓库是否存在
|
|
78
|
+
|
|
79
|
+
## 📦 安装
|
|
80
|
+
|
|
81
|
+
### 基础安装
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install xiaoshiai-hub
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 完整安装(包含加密功能)
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# 安装 SDK
|
|
91
|
+
pip install xiaoshiai-hub
|
|
92
|
+
|
|
93
|
+
# 安装 xpai-enc(用于加密功能)
|
|
94
|
+
pip install git+https://github.com/poxiaoyun/xpai-enc.git
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 🚀 快速开始
|
|
98
|
+
|
|
99
|
+
### 下载单个文件
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from xiaoshiai_hub import moha_hub_download
|
|
103
|
+
|
|
104
|
+
# 下载单个文件
|
|
105
|
+
file_path = moha_hub_download(
|
|
106
|
+
repo_id="demo/demo",
|
|
107
|
+
filename="config.yaml",
|
|
108
|
+
repo_type="models", # 或 "datasets"
|
|
109
|
+
username="your-username",
|
|
110
|
+
password="your-password",
|
|
111
|
+
)
|
|
112
|
+
print(f"文件已下载到: {file_path}")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 下载整个仓库
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from xiaoshiai_hub import snapshot_download
|
|
119
|
+
|
|
120
|
+
# 下载整个仓库
|
|
121
|
+
repo_path = snapshot_download(
|
|
122
|
+
repo_id="demo/demo",
|
|
123
|
+
repo_type="models",
|
|
124
|
+
username="your-username",
|
|
125
|
+
password="your-password",
|
|
126
|
+
)
|
|
127
|
+
print(f"仓库已下载到: {repo_path}")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 使用过滤器下载
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from xiaoshiai_hub import snapshot_download
|
|
134
|
+
|
|
135
|
+
# 只下载 YAML 和 Markdown 文件
|
|
136
|
+
repo_path = snapshot_download(
|
|
137
|
+
repo_id="demo/demo",
|
|
138
|
+
allow_patterns=["*.yaml", "*.yml", "*.md"],
|
|
139
|
+
ignore_patterns=[".git*", "*.log"],
|
|
140
|
+
username="your-username",
|
|
141
|
+
password="your-password",
|
|
142
|
+
)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 上传文件
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from xiaoshiai_hub import upload_file
|
|
149
|
+
|
|
150
|
+
# 上传单个文件
|
|
151
|
+
result = upload_file(
|
|
152
|
+
path_file="./config.yaml",
|
|
153
|
+
path_in_repo="config.yaml",
|
|
154
|
+
repo_id="demo/my-model",
|
|
155
|
+
repo_type="models",
|
|
156
|
+
commit_message="Upload config file",
|
|
157
|
+
username="your-username",
|
|
158
|
+
password="your-password",
|
|
159
|
+
)
|
|
160
|
+
print(f"上传成功: {result}")
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 上传文件夹
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from xiaoshiai_hub import upload_folder
|
|
167
|
+
|
|
168
|
+
# 上传整个文件夹
|
|
169
|
+
result = upload_folder(
|
|
170
|
+
folder_path="./my_model",
|
|
171
|
+
repo_id="demo/my-model",
|
|
172
|
+
repo_type="models",
|
|
173
|
+
commit_message="Upload model files",
|
|
174
|
+
ignore_patterns=["*.log", ".git*"], # 忽略这些文件
|
|
175
|
+
username="your-username",
|
|
176
|
+
password="your-password",
|
|
177
|
+
)
|
|
178
|
+
print(f"上传成功: {result}")
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### 加密上传
|
|
182
|
+
|
|
183
|
+
SDK 会自动加密大型模型文件(≥5MB 的 .safetensors、.bin、.pt、.pth、.ckpt 文件):
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from xiaoshiai_hub import upload_file
|
|
187
|
+
|
|
188
|
+
# 上传文件,大型模型文件会自动加密
|
|
189
|
+
result = upload_file(
|
|
190
|
+
path_file="./model.safetensors", # 如果 ≥5MB,会自动加密
|
|
191
|
+
path_in_repo="model.safetensors",
|
|
192
|
+
repo_id="demo/my-model",
|
|
193
|
+
repo_type="models",
|
|
194
|
+
encryption_password="your-secure-password", # 设置加密密码
|
|
195
|
+
username="your-username",
|
|
196
|
+
password="your-password",
|
|
197
|
+
)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### 上传文件夹(自动加密大文件)
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from xiaoshiai_hub import upload_folder
|
|
204
|
+
|
|
205
|
+
# 上传文件夹,大型模型文件会自动加密
|
|
206
|
+
result = upload_folder(
|
|
207
|
+
folder_path="./my_model",
|
|
208
|
+
repo_id="demo/my-model",
|
|
209
|
+
repo_type="models",
|
|
210
|
+
encryption_password="your-secure-password", # 大文件会自动加密
|
|
211
|
+
ignore_patterns=["*.log", ".git*"],
|
|
212
|
+
username="your-username",
|
|
213
|
+
password="your-password",
|
|
214
|
+
)
|
|
215
|
+
# 加密清单文件 xpai_encryption_manifest.enc 会自动上传
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 使用 HubClient API
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
from xiaoshiai_hub import HubClient
|
|
222
|
+
|
|
223
|
+
# 创建客户端
|
|
224
|
+
client = HubClient(
|
|
225
|
+
username="your-username",
|
|
226
|
+
password="your-password",
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
# 获取仓库信息
|
|
230
|
+
repo_info = client.get_repository_info("demo", "models", "my-model")
|
|
231
|
+
print(f"仓库名称: {repo_info.name}")
|
|
232
|
+
print(f"组织: {repo_info.organization}")
|
|
233
|
+
|
|
234
|
+
# 列出分支
|
|
235
|
+
branches = client.list_branches("demo", "models", "my-model")
|
|
236
|
+
for branch in branches:
|
|
237
|
+
print(f"分支: {branch.name} (commit: {branch.commit_sha})")
|
|
238
|
+
|
|
239
|
+
# 浏览仓库内容
|
|
240
|
+
content = client.get_repository_content("demo", "models", "my-model", "main")
|
|
241
|
+
for entry in content.entries:
|
|
242
|
+
print(f"{entry.type}: {entry.name}")
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## 🔐 加密功能
|
|
246
|
+
|
|
247
|
+
SDK 集成了 [xpai-enc](https://github.com/poxiaoyun/xpai-enc) 提供的智能加密功能。
|
|
248
|
+
|
|
249
|
+
### 自动加密规则
|
|
250
|
+
|
|
251
|
+
上传时,SDK 会自动加密符合以下条件的文件:
|
|
252
|
+
|
|
253
|
+
1. **文件大小** ≥ 5MB
|
|
254
|
+
2. **文件扩展名**为:`.safetensors`、`.bin`、`.pt`、`.pth`、`.ckpt`
|
|
255
|
+
|
|
256
|
+
小文件和其他类型的文件(如配置文件、README 等)不会被加密,保持可读性。
|
|
257
|
+
|
|
258
|
+
### 加密清单文件
|
|
259
|
+
|
|
260
|
+
加密后会自动生成 `xpai_encryption_manifest.enc` 清单文件,记录哪些文件被加密了。此文件会自动上传到仓库。
|
|
261
|
+
|
|
262
|
+
### 使用加密功能
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from xiaoshiai_hub import upload_folder
|
|
266
|
+
|
|
267
|
+
# 上传文件夹,自动加密大型模型文件
|
|
268
|
+
result = upload_folder(
|
|
269
|
+
folder_path="./llama-7b",
|
|
270
|
+
repo_id="demo/llama-7b",
|
|
271
|
+
encryption_password="my-secure-password-123", # 设置加密密码
|
|
272
|
+
username="your-username",
|
|
273
|
+
password="your-password",
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
# 文件夹中的大型模型文件(如 model.safetensors)会被自动加密
|
|
277
|
+
# 小文件(如 config.json、README.md)保持原样
|
|
278
|
+
# 加密清单 xpai_encryption_manifest.enc 会自动上传
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### 临时目录管理
|
|
282
|
+
|
|
283
|
+
上传时可以指定临时目录用于存放加密文件:
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
result = upload_folder(
|
|
287
|
+
folder_path="./my_model",
|
|
288
|
+
repo_id="demo/my-model",
|
|
289
|
+
encryption_password="password",
|
|
290
|
+
temp_dir="/tmp/encrypted_files", # 指定临时目录
|
|
291
|
+
username="your-username",
|
|
292
|
+
password="your-password",
|
|
293
|
+
)
|
|
294
|
+
# 如果不指定 temp_dir,会自动创建临时目录并在上传后清理
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## ⚙️ 配置
|
|
298
|
+
|
|
299
|
+
### 环境变量
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Hub 服务端点
|
|
303
|
+
export MOHA_ENDPOINT="https://your-hub-url.com/moha"
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## � 使用场景
|
|
307
|
+
|
|
308
|
+
### 场景 1: 上传开源模型到私有 Hub
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
from xiaoshiai_hub import upload_folder
|
|
312
|
+
|
|
313
|
+
# 上传 Hugging Face 下载的模型到私有 Hub
|
|
314
|
+
result = upload_folder(
|
|
315
|
+
folder_path="~/.cache/huggingface/hub/models--meta-llama--Llama-2-7b-hf",
|
|
316
|
+
repo_id="myorg/llama-2-7b",
|
|
317
|
+
repo_type="models",
|
|
318
|
+
commit_message="Upload Llama 2 7B model",
|
|
319
|
+
username="your-username",
|
|
320
|
+
password="your-password",
|
|
321
|
+
)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 场景 2: 加密上传敏感模型
|
|
325
|
+
|
|
326
|
+
```python
|
|
327
|
+
from xiaoshiai_hub import upload_folder
|
|
328
|
+
|
|
329
|
+
# 上传模型并加密大文件
|
|
330
|
+
result = upload_folder(
|
|
331
|
+
folder_path="./proprietary-model",
|
|
332
|
+
repo_id="myorg/proprietary-model",
|
|
333
|
+
encryption_password="super-secret-password", # 大文件自动加密
|
|
334
|
+
ignore_patterns=["*.log", "checkpoints/"],
|
|
335
|
+
username="your-username",
|
|
336
|
+
password="your-password",
|
|
337
|
+
)
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### 场景 3: 批量下载数据集
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
from xiaoshiai_hub import snapshot_download
|
|
344
|
+
|
|
345
|
+
# 下载整个数据集
|
|
346
|
+
dataset_path = snapshot_download(
|
|
347
|
+
repo_id="myorg/my-dataset",
|
|
348
|
+
repo_type="datasets",
|
|
349
|
+
allow_patterns=["*.parquet", "*.json"], # 只下载数据文件
|
|
350
|
+
ignore_patterns=["*.md"], # 忽略文档
|
|
351
|
+
username="your-username",
|
|
352
|
+
password="your-password",
|
|
353
|
+
)
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### 场景 4: 检查仓库是否存在
|
|
357
|
+
|
|
358
|
+
```python
|
|
359
|
+
from xiaoshiai_hub import HubClient
|
|
360
|
+
from xiaoshiai_hub.exceptions import RepositoryNotFoundError
|
|
361
|
+
|
|
362
|
+
client = HubClient(username="your-username", password="your-password")
|
|
363
|
+
|
|
364
|
+
try:
|
|
365
|
+
repo_info = client.get_repository_info("myorg", "models", "my-model")
|
|
366
|
+
print(f"仓库存在: {repo_info.name}")
|
|
367
|
+
except RepositoryNotFoundError:
|
|
368
|
+
print("仓库不存在,请先创建")
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
## ⚠️ 重要说明
|
|
373
|
+
|
|
374
|
+
### 仓库必须先创建
|
|
375
|
+
|
|
376
|
+
在上传文件或文件夹之前,必须先在 Hub 上创建仓库。SDK 会自动检查仓库是否存在:
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
from xiaoshiai_hub import upload_file
|
|
380
|
+
from xiaoshiai_hub.exceptions import RepositoryNotFoundError
|
|
381
|
+
|
|
382
|
+
try:
|
|
383
|
+
result = upload_file(
|
|
384
|
+
path_file="./model.bin",
|
|
385
|
+
path_in_repo="model.bin",
|
|
386
|
+
repo_id="myorg/my-model",
|
|
387
|
+
username="your-username",
|
|
388
|
+
password="your-password",
|
|
389
|
+
)
|
|
390
|
+
except RepositoryNotFoundError as e:
|
|
391
|
+
print(f"错误: {e}")
|
|
392
|
+
print("请先在 Hub 上创建仓库")
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### 加密文件的大小和类型限制
|
|
396
|
+
|
|
397
|
+
只有满足以下条件的文件才会被加密:
|
|
398
|
+
|
|
399
|
+
1. **文件大小** ≥ 5MB
|
|
400
|
+
2. **文件扩展名**为:`.safetensors`、`.bin`、`.pt`、`.pth`、`.ckpt`
|
|
401
|
+
|
|
402
|
+
其他文件保持原样,不会被加密。
|
|
403
|
+
|
|
404
|
+
### 临时文件清理
|
|
405
|
+
|
|
406
|
+
使用 `encryption_password` 时,SDK 会创建临时目录存放加密文件。上传完成后会自动清理,但如果上传失败,可能需要手动清理临时目录。
|
|
407
|
+
|
|
408
|
+
## 🔧 开发
|
|
409
|
+
|
|
410
|
+
### 设置开发环境
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# 克隆仓库
|
|
414
|
+
git clone https://github.com/poxiaoyun/moha-sdk.git
|
|
415
|
+
cd moha-sdk
|
|
416
|
+
|
|
417
|
+
# 创建虚拟环境
|
|
418
|
+
python -m venv venv
|
|
419
|
+
source venv/bin/activate # Linux/macOS
|
|
420
|
+
# 或
|
|
421
|
+
venv\Scripts\activate # Windows
|
|
422
|
+
|
|
423
|
+
# 安装依赖
|
|
424
|
+
pip install -r requirements.txt
|
|
425
|
+
|
|
426
|
+
# 安装 xpai-enc(用于加密功能)
|
|
427
|
+
pip install git+https://github.com/poxiaoyun/xpai-enc.git
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
## 🔗 相关项目
|
|
431
|
+
|
|
432
|
+
- **[xpai-enc](https://github.com/poxiaoyun/xpai-enc)** - 模型文件加密/解密工具,提供透明的加密支持
|
|
433
|
+
|
|
434
|
+
## 📝 更新日志
|
|
435
|
+
|
|
436
|
+
### v0.1.3 (最新)
|
|
437
|
+
|
|
438
|
+
- ✅ 添加仓库存在性检查(上传前自动验证)
|
|
439
|
+
- ✅ 集成 xpai-enc 加密功能
|
|
440
|
+
- ✅ 自动加密大型模型文件(≥5MB)
|
|
441
|
+
- ✅ 自动生成和上传加密清单文件
|
|
442
|
+
- ✅ 改进错误处理和提示信息
|
|
443
|
+
|
|
444
|
+
### v0.1.0
|
|
445
|
+
|
|
446
|
+
- 🎉 初始版本发布
|
|
447
|
+
- ✅ 基础下载功能
|
|
448
|
+
- ✅ 基础上传功能
|
|
449
|
+
- ✅ HubClient API
|
|
450
|
+
|
|
451
|
+
## 🤝 贡献
|
|
452
|
+
|
|
453
|
+
欢迎贡献!请随时提交 Issue 或 Pull Request。
|
|
454
|
+
|
|
455
|
+
### 贡献指南
|
|
456
|
+
|
|
457
|
+
1. Fork 本仓库
|
|
458
|
+
2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
|
|
459
|
+
3. 提交更改 (`git commit -m 'Add some amazing feature'`)
|
|
460
|
+
4. 推送到分支 (`git push origin feature/amazing-feature`)
|
|
461
|
+
5. 开启 Pull Request
|
|
462
|
+
|
|
463
|
+
## 📄 许可证
|
|
464
|
+
|
|
465
|
+
本项目采用 Apache 2.0 许可证 - 详见 [LICENSE](LICENSE) 文件
|
|
466
|
+
|
|
467
|
+
## 💬 支持
|
|
468
|
+
|
|
469
|
+
如有问题或需要帮助,请:
|
|
470
|
+
|
|
471
|
+
1. 查看文档和示例
|
|
472
|
+
2. 搜索或创建 [Issue](https://github.com/poxiaoyun/moha-sdk/issues)
|
|
473
|
+
3. 联系维护者
|