Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,8 +80,17 @@ class MigrationTool:
|
|
| 80 |
Tuple of (success, message)
|
| 81 |
"""
|
| 82 |
try:
|
| 83 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
api = HubApi()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# Determine visibility
|
| 87 |
vis = ModelVisibility.PUBLIC if visibility == "public" else ModelVisibility.PRIVATE
|
|
@@ -90,8 +99,13 @@ class MigrationTool:
|
|
| 90 |
license_map = {
|
| 91 |
"apache-2.0": Licenses.APACHE_V2,
|
| 92 |
"mit": Licenses.MIT,
|
|
|
|
| 93 |
"gpl-3.0": Licenses.GPL_V3,
|
| 94 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
lic = license_map.get(license_type.lower(), Licenses.APACHE_V2)
|
| 97 |
|
|
@@ -105,23 +119,32 @@ class MigrationTool:
|
|
| 105 |
chinese_name=chinese_name,
|
| 106 |
token=token,
|
| 107 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
except Exception as create_error:
|
| 109 |
# Repository might already exist, continue to push
|
| 110 |
pass
|
| 111 |
|
| 112 |
# Push the model/dataset
|
| 113 |
if repo_type == "model":
|
| 114 |
-
api.
|
| 115 |
-
|
| 116 |
-
|
| 117 |
token=token,
|
| 118 |
)
|
| 119 |
else:
|
| 120 |
-
# For datasets, use
|
| 121 |
-
api.
|
| 122 |
-
|
| 123 |
-
|
| 124 |
token=token,
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
return True, f"β Successfully uploaded {repo_type} to ModelScope"
|
|
@@ -155,13 +178,21 @@ class MigrationTool:
|
|
| 155 |
"""
|
| 156 |
output = []
|
| 157 |
|
| 158 |
-
# Validate inputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
if not hf_token or not ms_token:
|
| 160 |
return "β Error: Both HuggingFace and ModelScope tokens are required"
|
| 161 |
|
| 162 |
if not hf_repo_id or not ms_repo_id:
|
| 163 |
return "β Error: Both source and destination repository IDs are required"
|
| 164 |
|
|
|
|
|
|
|
|
|
|
| 165 |
# Download from HuggingFace
|
| 166 |
output.append(f"β¬οΈ Downloading {repo_type} from HuggingFace: {hf_repo_id}...")
|
| 167 |
success, msg, local_path = self.download_from_hf(hf_repo_id, repo_type, hf_token)
|
|
@@ -227,8 +258,8 @@ def create_interface():
|
|
| 227 |
ms_token = gr.Textbox(
|
| 228 |
label="ModelScope Token",
|
| 229 |
type="password",
|
| 230 |
-
placeholder="
|
| 231 |
-
info="Your ModelScope SDK token"
|
| 232 |
)
|
| 233 |
|
| 234 |
with gr.Column():
|
|
@@ -264,7 +295,17 @@ def create_interface():
|
|
| 264 |
with gr.Row():
|
| 265 |
with gr.Column():
|
| 266 |
license_type = gr.Dropdown(
|
| 267 |
-
choices=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
label="License",
|
| 269 |
value="apache-2.0",
|
| 270 |
info="License for the repository"
|
|
|
|
| 80 |
Tuple of (success, message)
|
| 81 |
"""
|
| 82 |
try:
|
| 83 |
+
# Clean and validate token
|
| 84 |
+
token = token.strip()
|
| 85 |
+
if not token:
|
| 86 |
+
return False, "β ModelScope token is empty"
|
| 87 |
+
|
| 88 |
+
# Create HubApi instance and login explicitly
|
| 89 |
api = HubApi()
|
| 90 |
+
try:
|
| 91 |
+
api.login(token)
|
| 92 |
+
except Exception as login_error:
|
| 93 |
+
return False, f"β ModelScope Login failed: {str(login_error)}\n\nπ‘ Tip: Ensure you are using an 'SDK Token' (starts with 'ms-') from https://www.modelscope.cn/my/myaccesstoken, NOT a 'Git Token'."
|
| 94 |
|
| 95 |
# Determine visibility
|
| 96 |
vis = ModelVisibility.PUBLIC if visibility == "public" else ModelVisibility.PRIVATE
|
|
|
|
| 99 |
license_map = {
|
| 100 |
"apache-2.0": Licenses.APACHE_V2,
|
| 101 |
"mit": Licenses.MIT,
|
| 102 |
+
"gpl-2.0": Licenses.GPL_V2,
|
| 103 |
"gpl-3.0": Licenses.GPL_V3,
|
| 104 |
+
"lgpl-2.1": Licenses.LGPL_V2_1,
|
| 105 |
+
"lgpl-3.0": Licenses.LGPL_V3,
|
| 106 |
+
"afl-3.0": Licenses.AFL_V3,
|
| 107 |
+
"ecl-2.0": Licenses.ECL_V2,
|
| 108 |
+
"other": None,
|
| 109 |
}
|
| 110 |
lic = license_map.get(license_type.lower(), Licenses.APACHE_V2)
|
| 111 |
|
|
|
|
| 119 |
chinese_name=chinese_name,
|
| 120 |
token=token,
|
| 121 |
)
|
| 122 |
+
else:
|
| 123 |
+
api.create_dataset(
|
| 124 |
+
dataset_id=repo_id,
|
| 125 |
+
visibility=vis,
|
| 126 |
+
license=lic,
|
| 127 |
+
chinese_name=chinese_name,
|
| 128 |
+
token=token,
|
| 129 |
+
)
|
| 130 |
except Exception as create_error:
|
| 131 |
# Repository might already exist, continue to push
|
| 132 |
pass
|
| 133 |
|
| 134 |
# Push the model/dataset
|
| 135 |
if repo_type == "model":
|
| 136 |
+
api.upload_folder(
|
| 137 |
+
repo_id=repo_id,
|
| 138 |
+
folder_path=local_path,
|
| 139 |
token=token,
|
| 140 |
)
|
| 141 |
else:
|
| 142 |
+
# For datasets, use upload_folder with repo_type='dataset'
|
| 143 |
+
api.upload_folder(
|
| 144 |
+
repo_id=repo_id,
|
| 145 |
+
folder_path=local_path,
|
| 146 |
token=token,
|
| 147 |
+
repo_type="dataset"
|
| 148 |
)
|
| 149 |
|
| 150 |
return True, f"β Successfully uploaded {repo_type} to ModelScope"
|
|
|
|
| 178 |
"""
|
| 179 |
output = []
|
| 180 |
|
| 181 |
+
# Validate and clean inputs
|
| 182 |
+
hf_token = hf_token.strip() if hf_token else ""
|
| 183 |
+
ms_token = ms_token.strip() if ms_token else ""
|
| 184 |
+
hf_repo_id = hf_repo_id.strip() if hf_repo_id else ""
|
| 185 |
+
ms_repo_id = ms_repo_id.strip() if ms_repo_id else ""
|
| 186 |
+
|
| 187 |
if not hf_token or not ms_token:
|
| 188 |
return "β Error: Both HuggingFace and ModelScope tokens are required"
|
| 189 |
|
| 190 |
if not hf_repo_id or not ms_repo_id:
|
| 191 |
return "β Error: Both source and destination repository IDs are required"
|
| 192 |
|
| 193 |
+
if "/" not in ms_repo_id:
|
| 194 |
+
return "β Error: Destination ModelScope Repo ID must be in 'username/repo-name' format"
|
| 195 |
+
|
| 196 |
# Download from HuggingFace
|
| 197 |
output.append(f"β¬οΈ Downloading {repo_type} from HuggingFace: {hf_repo_id}...")
|
| 198 |
success, msg, local_path = self.download_from_hf(hf_repo_id, repo_type, hf_token)
|
|
|
|
| 258 |
ms_token = gr.Textbox(
|
| 259 |
label="ModelScope Token",
|
| 260 |
type="password",
|
| 261 |
+
placeholder="ms-...",
|
| 262 |
+
info="Your ModelScope SDK token (must start with 'ms-')"
|
| 263 |
)
|
| 264 |
|
| 265 |
with gr.Column():
|
|
|
|
| 295 |
with gr.Row():
|
| 296 |
with gr.Column():
|
| 297 |
license_type = gr.Dropdown(
|
| 298 |
+
choices=[
|
| 299 |
+
"apache-2.0",
|
| 300 |
+
"mit",
|
| 301 |
+
"gpl-2.0",
|
| 302 |
+
"gpl-3.0",
|
| 303 |
+
"lgpl-2.1",
|
| 304 |
+
"lgpl-3.0",
|
| 305 |
+
"afl-3.0",
|
| 306 |
+
"ecl-2.0",
|
| 307 |
+
"other"
|
| 308 |
+
],
|
| 309 |
label="License",
|
| 310 |
value="apache-2.0",
|
| 311 |
info="License for the repository"
|