bingjie commited on
Commit
1de6491
·
verified ·
1 Parent(s): 74095fe

Upload DiffAM model files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ shape_predictor_68_face_landmarks.dat filter=lfs diff=lfs merge=lfs -text
celeba_hq.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6cbb630eb856ff3ebe4854fe87af3c21a052765678955999db97ea15b5eeb8a5
3
+ size 454777119
makeup.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7282b71d4abc9ceaf54084dd9a01ed191ff5baf7e39782648b56065c4f673e51
3
+ size 374409069
model_ir_se50.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a035c768259b98ab1ce0e646312f48b9e1e218197a0f80ac6765e88f8b6ddf28
3
+ size 175367323
shape_predictor_68_face_landmarks.dat ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fbdc2cb80eb9aa7a758672cbfdda32ba6300efe9b6e6c7a299ff7e736b11b92f
3
+ size 99693937
up_loade.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 将本地 DiffAM 文件夹中的所有内容上传到 Hugging Face Model Repository:
6
+
7
+ 本地目录:
8
+ /Users/gaobj/Downloads/DiffAM
9
+
10
+ 目标仓库:
11
+ https://huggingface.co/bingjie/DiffAM
12
+
13
+ 安装依赖:
14
+ pip install -U huggingface_hub
15
+
16
+ 运行前设置 Token:
17
+ export HF_TOKEN="你的新HuggingFaceToken"
18
+
19
+ 运行:
20
+ python upload_diffam_to_huggingface.py
21
+ """
22
+
23
+ import os
24
+ import sys
25
+ from pathlib import Path
26
+
27
+ from huggingface_hub import HfApi
28
+ from huggingface_hub.errors import HfHubHTTPError
29
+
30
+
31
+ # ============================================================
32
+ # 配置
33
+ # ============================================================
34
+
35
+ LOCAL_FOLDER = Path("/Users/gaobj/Downloads/DiffAM")
36
+
37
+ # Hugging Face 模型仓库格式为:用户名/仓库名
38
+ REPO_ID = "bingjie/DiffAM"
39
+
40
+ # 可选:
41
+ # False:公开仓库
42
+ # True:私有仓库
43
+ PRIVATE_REPO = False
44
+
45
+ COMMIT_MESSAGE = "Upload DiffAM model files"
46
+
47
+
48
+ def get_hf_token() -> str:
49
+ """
50
+ 从环境变量读取 Hugging Face Access Token。
51
+ """
52
+ token = os.environ.get("HF_TOKEN")
53
+
54
+ if not token:
55
+ raise RuntimeError(
56
+ "没有找到环境变量 HF_TOKEN。\n\n"
57
+ "请先在终端执行:\n"
58
+ 'export HF_TOKEN="你的HuggingFaceAccessToken"\n\n'
59
+ "然后重新运行此脚本。"
60
+ )
61
+
62
+ return token.strip()
63
+
64
+
65
+ def check_local_folder(folder: Path) -> None:
66
+ """
67
+ 检查本地目录是否存在且不为空。
68
+ """
69
+ if not folder.exists():
70
+ raise FileNotFoundError(f"本地目录不存在:{folder}")
71
+
72
+ if not folder.is_dir():
73
+ raise NotADirectoryError(f"该路径不是文件夹:{folder}")
74
+
75
+ files = [path for path in folder.rglob("*") if path.is_file()]
76
+
77
+ if not files:
78
+ raise RuntimeError(f"本地目录为空,没有可上传的文件:{folder}")
79
+
80
+ total_size = sum(path.stat().st_size for path in files)
81
+
82
+ print(f"本地目录:{folder}")
83
+ print(f"文件数量:{len(files)}")
84
+ print(f"文件总大小:{format_size(total_size)}")
85
+
86
+
87
+ def format_size(size_bytes: int) -> str:
88
+ """
89
+ 将字节数转换为便于阅读的格式。
90
+ """
91
+ size = float(size_bytes)
92
+
93
+ for unit in ["B", "KB", "MB", "GB", "TB"]:
94
+ if size < 1024 or unit == "TB":
95
+ return f"{size:.2f} {unit}"
96
+ size /= 1024
97
+
98
+ return f"{size_bytes} B"
99
+
100
+
101
+ def upload_folder() -> None:
102
+ """
103
+ 创建 Hugging Face 模型仓库,并上传整个本地文件夹。
104
+ """
105
+ check_local_folder(LOCAL_FOLDER)
106
+
107
+ token = get_hf_token()
108
+ api = HfApi(token=token)
109
+
110
+ try:
111
+ # 验证 Token,并获取当前账户信息
112
+ user_info = api.whoami()
113
+ username = user_info.get("name", "unknown")
114
+
115
+ print(f"当前 Hugging Face 账户:{username}")
116
+
117
+ if username != "bingjie":
118
+ print(
119
+ f"警告:当前 Token 所属账户是 {username},"
120
+ f"但目标仓库位于 bingjie 名下。"
121
+ )
122
+
123
+ # 创建仓库;exist_ok=True 表示仓库已存在时不会报错
124
+ repo_url = api.create_repo(
125
+ repo_id=REPO_ID,
126
+ repo_type="model",
127
+ private=PRIVATE_REPO,
128
+ exist_ok=True,
129
+ )
130
+
131
+ print(f"目标仓库:{repo_url}")
132
+ print("开始上传文件……")
133
+
134
+ # 上传文件夹内的全部内容
135
+ # path_in_repo="" 表示上传到仓库根目录
136
+ commit_info = api.upload_folder(
137
+ folder_path=str(LOCAL_FOLDER),
138
+ repo_id=REPO_ID,
139
+ repo_type="model",
140
+ path_in_repo="",
141
+ commit_message=COMMIT_MESSAGE,
142
+
143
+ # 忽略常见的本地缓存和系统文件
144
+ ignore_patterns=[
145
+ ".git/**",
146
+ ".DS_Store",
147
+ "**/.DS_Store",
148
+ "__pycache__/**",
149
+ "**/__pycache__/**",
150
+ "*.pyc",
151
+ "**/*.pyc",
152
+ ],
153
+ )
154
+
155
+ print("\n上传完成。")
156
+ print(f"模型仓库:https://huggingface.co/{REPO_ID}")
157
+
158
+ commit_url = getattr(commit_info, "commit_url", None)
159
+ if commit_url:
160
+ print(f"本次提交:{commit_url}")
161
+
162
+ except HfHubHTTPError as exc:
163
+ print("\nHugging Face 请求失败:", file=sys.stderr)
164
+ print(str(exc), file=sys.stderr)
165
+
166
+ if exc.response is not None:
167
+ if exc.response.status_code == 401:
168
+ print(
169
+ "\n可能原因:Token 无效、已过期或没有登录权限。",
170
+ file=sys.stderr,
171
+ )
172
+ elif exc.response.status_code == 403:
173
+ print(
174
+ "\n可能原因:Token 没有写入权限,"
175
+ "或者当前账户无权写入 bingjie/DiffAM。",
176
+ file=sys.stderr,
177
+ )
178
+
179
+ raise
180
+
181
+ except KeyboardInterrupt:
182
+ print("\n上传已由用户中断。", file=sys.stderr)
183
+ sys.exit(130)
184
+
185
+
186
+ if __name__ == "__main__":
187
+ upload_folder()