Linaqruf commited on
Commit
d5b1a1b
·
verified ·
1 Parent(s): b93a4c3

Upload 6 files

Browse files
Files changed (6) hide show
  1. .gitignore +219 -0
  2. LICENSE +201 -0
  3. README.md +201 -14
  4. app.py +352 -0
  5. example_usage.py +73 -0
  6. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
+ # HuggingFace to ModelScope Migration Tool
210
+ # Temporary download directories
211
+ hf2ms_*/
212
+ tmp_*/
213
+ # Token files (never commit tokens!)
214
+ *.token
215
+ tokens.txt
216
+ .tokens
217
+ # Gradio cache and flagged data
218
+ flagged/
219
+ gradio_queue.db
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,14 +1,201 @@
1
- ---
2
- title: Modelscope Migration
3
- emoji: 😻
4
- colorFrom: indigo
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 6.2.0
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- short_description: Migrating to Modelscope
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 HuggingFace to ModelScope Migration Tool
2
+
3
+ A user-friendly Gradio application for migrating models and datasets from [HuggingFace](https://huggingface.co/) to [ModelScope](https://www.modelscope.cn/).
4
+
5
+ ## ✨ Features
6
+
7
+ - **Easy Migration**: Migrate models and datasets with a simple web interface
8
+ - **Secure Authentication**: Supports token-based authentication for both platforms
9
+ - **Progress Tracking**: Real-time status updates during migration
10
+ - **Flexible Configuration**: Customize repository visibility, license, and metadata
11
+ - **Error Handling**: Comprehensive error messages and validation
12
+ - **Automatic Cleanup**: Temporary files are automatically cleaned up after migration
13
+
14
+ ## 📋 Prerequisites
15
+
16
+ - Python 3.8 or higher
17
+ - Internet connection
18
+ - HuggingFace account and access token
19
+ - ModelScope account and SDK token
20
+
21
+ ## 🔧 Installation
22
+
23
+ 1. Clone this repository:
24
+ ```bash
25
+ git clone <repository-url>
26
+ cd modelscope-migration
27
+ ```
28
+
29
+ 2. Install dependencies:
30
+ ```bash
31
+ pip install -r requirements.txt
32
+ ```
33
+
34
+ Or install manually:
35
+ ```bash
36
+ pip install gradio huggingface-hub modelscope
37
+ ```
38
+
39
+ ## 🚀 Quick Start
40
+
41
+ 1. Run the application:
42
+ ```bash
43
+ python app.py
44
+ ```
45
+
46
+ 2. Open your browser and navigate to the provided URL (usually `http://localhost:7860`)
47
+
48
+ 3. Fill in the required information:
49
+ - **HuggingFace Token**: Get from https://huggingface.co/settings/tokens
50
+ - **ModelScope Token**: Get from https://www.modelscope.cn/my/myaccesstoken
51
+ - **Source Repository**: The HuggingFace repository ID (e.g., `bert-base-uncased`)
52
+ - **Destination Repository**: Your desired ModelScope repository ID (e.g., `username/my-model`)
53
+
54
+ 4. Click "Start Migration" and wait for completion
55
+
56
+ ## 📖 Usage Guide
57
+
58
+ ### Getting Your Tokens
59
+
60
+ #### HuggingFace Token:
61
+ 1. Go to https://huggingface.co/settings/tokens
62
+ 2. Click "New token"
63
+ 3. Give it a name and select appropriate permissions
64
+ 4. Copy the token (starts with `hf_`)
65
+
66
+ #### ModelScope Token:
67
+ 1. Go to https://www.modelscope.cn/my/myaccesstoken
68
+ 2. Log in to your account
69
+ 3. Copy your SDK token
70
+
71
+ ### Migration Options
72
+
73
+ | Option | Description | Default |
74
+ |--------|-------------|---------|
75
+ | **Repository Type** | Choose between `model` or `dataset` | `model` |
76
+ | **Visibility** | Set repository as `public` or `private` | `public` |
77
+ | **License** | Choose from Apache 2.0, MIT, GPL-3.0, or Other | `apache-2.0` |
78
+ | **Chinese Name** | Optional Chinese name for the repository | None |
79
+
80
+ ### Example Repository IDs
81
+
82
+ **HuggingFace:**
83
+ - `bert-base-uncased` (official model)
84
+ - `username/my-custom-model` (user model)
85
+ - `datasets/squad` (dataset)
86
+
87
+ **ModelScope:**
88
+ - `username/repo-name` (always requires username prefix)
89
+
90
+ ## 🛠️ How It Works
91
+
92
+ The migration process follows these steps:
93
+
94
+ 1. **Authentication**: Validates tokens for both HuggingFace and ModelScope
95
+ 2. **Download**: Uses `snapshot_download` to download the entire repository from HuggingFace
96
+ 3. **Upload**: Creates repository on ModelScope (if needed) and uploads all files
97
+ 4. **Cleanup**: Removes temporary files from local storage
98
+
99
+ ## 📝 Features in Detail
100
+
101
+ ### Model Migration
102
+
103
+ Migrates complete model repositories including:
104
+ - Model weights and configuration files
105
+ - Tokenizer files
106
+ - README and documentation
107
+ - Any additional files in the repository
108
+
109
+ ### Dataset Migration
110
+
111
+ Migrates dataset repositories including:
112
+ - Dataset files (all formats)
113
+ - Dataset cards and metadata
114
+ - Scripts and configuration files
115
+
116
+ ### Error Handling
117
+
118
+ The tool provides clear error messages for:
119
+ - Invalid tokens
120
+ - Repository not found
121
+ - Permission errors
122
+ - Network issues
123
+ - Disk space problems
124
+
125
+ ## ⚠️ Important Notes
126
+
127
+ - **Disk Space**: Ensure you have enough disk space for temporary storage of the repository
128
+ - **Large Models**: Migration time depends on repository size and network speed
129
+ - **Permissions**: Your tokens must have appropriate read/write permissions
130
+ - **Private Repos**: To migrate private repositories, ensure your HuggingFace token has access
131
+ - **Repository Creation**: The tool automatically creates the ModelScope repository if it doesn't exist
132
+
133
+ ## 🔒 Security
134
+
135
+ - Tokens are handled securely and not logged
136
+ - Tokens are entered as password fields (hidden input)
137
+ - Temporary files are cleaned up after migration
138
+ - No data is stored permanently on the server
139
+
140
+ ## 🐛 Troubleshooting
141
+
142
+ ### "Authentication failed"
143
+ - Verify your tokens are correct and not expired
144
+ - Check that you're using the right token for each platform
145
+
146
+ ### "Download failed"
147
+ - Ensure the HuggingFace repository exists and is accessible
148
+ - Check your internet connection
149
+ - Verify you have permission to access the repository
150
+
151
+ ### "Upload failed"
152
+ - Verify your ModelScope token has write permissions
153
+ - Check that the destination repository name is valid
154
+ - Ensure you're not exceeding ModelScope's quotas
155
+
156
+ ### "Disk space error"
157
+ - Free up disk space on your system
158
+ - Large models require significant temporary storage
159
+
160
+ ## 📚 API Documentation
161
+
162
+ ### HuggingFace Hub
163
+ - Documentation: https://huggingface.co/docs/huggingface_hub
164
+ - PyPI: https://pypi.org/project/huggingface-hub/
165
+
166
+ ### ModelScope
167
+ - GitHub: https://github.com/modelscope/modelscope
168
+ - PyPI: https://pypi.org/project/modelscope/
169
+
170
+ ## 🤝 Contributing
171
+
172
+ Contributions are welcome! Please feel free to submit issues or pull requests.
173
+
174
+ ## 📄 License
175
+
176
+ This project is open source and available under the Apache 2.0 License.
177
+
178
+ ## 🔗 Resources
179
+
180
+ - [HuggingFace Hub](https://huggingface.co/)
181
+ - [ModelScope Platform](https://www.modelscope.cn/)
182
+ - [Gradio Documentation](https://gradio.app/docs/)
183
+
184
+ ## 💡 Tips
185
+
186
+ 1. **Test with small models first**: Before migrating large models, test with a smaller repository
187
+ 2. **Check licenses**: Ensure you have the right to migrate and redistribute the model/dataset
188
+ 3. **Preserve metadata**: The tool preserves all files, but review the ModelScope repository after migration
189
+ 4. **Network stability**: For large repositories, ensure a stable internet connection
190
+
191
+ ## 🆘 Support
192
+
193
+ If you encounter issues:
194
+ 1. Check the troubleshooting section above
195
+ 2. Review the error message in the status output
196
+ 3. Verify your tokens and repository IDs
197
+ 4. Check the official documentation for HuggingFace and ModelScope
198
+
199
+ ---
200
+
201
+ Made with ❤️ using [Gradio](https://gradio.app/), [HuggingFace Hub](https://huggingface.co/), and [ModelScope](https://www.modelscope.cn/)
app.py ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ HuggingFace to ModelScope Migration Tool
3
+
4
+ This Gradio app enables migration of models and datasets from HuggingFace to ModelScope.
5
+ """
6
+
7
+ import os
8
+ import shutil
9
+ import tempfile
10
+ from pathlib import Path
11
+ from typing import Tuple, Optional
12
+
13
+ import gradio as gr
14
+ from huggingface_hub import snapshot_download, HfApi
15
+ from modelscope.hub.api import HubApi
16
+ from modelscope.hub.constants import Licenses, ModelVisibility
17
+
18
+
19
+ class MigrationTool:
20
+ """Handles migration of models and datasets between HuggingFace and ModelScope."""
21
+
22
+ def __init__(self):
23
+ self.hf_api = None
24
+ self.ms_api = None
25
+ self.temp_dir = None
26
+
27
+ def authenticate_hf(self, token: str) -> Tuple[bool, str]:
28
+ """Authenticate with HuggingFace."""
29
+ try:
30
+ self.hf_api = HfApi(token=token)
31
+ # Test the token
32
+ self.hf_api.whoami(token=token)
33
+ return True, "✓ HuggingFace authentication successful"
34
+ except Exception as e:
35
+ return False, f"✗ HuggingFace authentication failed: {str(e)}"
36
+
37
+ def authenticate_ms(self, token: str) -> Tuple[bool, str]:
38
+ """Authenticate with ModelScope."""
39
+ try:
40
+ self.ms_api = HubApi()
41
+ self.ms_api.login(token)
42
+ return True, "✓ ModelScope authentication successful"
43
+ except Exception as e:
44
+ return False, f"✗ ModelScope authentication failed: {str(e)}"
45
+
46
+ def download_from_hf(
47
+ self,
48
+ repo_id: str,
49
+ repo_type: str = "model"
50
+ ) -> Tuple[bool, str, Optional[str]]:
51
+ """Download a repository from HuggingFace.
52
+
53
+ Args:
54
+ repo_id: HuggingFace repository ID (e.g., 'username/repo-name')
55
+ repo_type: Type of repository ('model' or 'dataset')
56
+
57
+ Returns:
58
+ Tuple of (success, message, local_path)
59
+ """
60
+ try:
61
+ # Create temporary directory
62
+ self.temp_dir = tempfile.mkdtemp(prefix="hf2ms_")
63
+
64
+ # Download the repository
65
+ local_path = snapshot_download(
66
+ repo_id=repo_id,
67
+ repo_type=repo_type,
68
+ local_dir=self.temp_dir,
69
+ local_dir_use_symlinks=False,
70
+ token=self.hf_api.token if self.hf_api else None
71
+ )
72
+
73
+ return True, f"✓ Successfully downloaded {repo_type} from HuggingFace", local_path
74
+ except Exception as e:
75
+ return False, f"✗ Download failed: {str(e)}", None
76
+
77
+ def upload_to_ms(
78
+ self,
79
+ local_path: str,
80
+ repo_id: str,
81
+ repo_type: str = "model",
82
+ visibility: str = "public",
83
+ license_type: str = "apache-2.0",
84
+ chinese_name: Optional[str] = None
85
+ ) -> Tuple[bool, str]:
86
+ """Upload a repository to ModelScope.
87
+
88
+ Args:
89
+ local_path: Local path to the repository
90
+ repo_id: ModelScope repository ID (e.g., 'username/repo-name')
91
+ repo_type: Type of repository ('model' or 'dataset')
92
+ visibility: Repository visibility ('public' or 'private')
93
+ license_type: License type
94
+ chinese_name: Optional Chinese name for the repository
95
+
96
+ Returns:
97
+ Tuple of (success, message)
98
+ """
99
+ try:
100
+ if not self.ms_api:
101
+ return False, "✗ ModelScope not authenticated"
102
+
103
+ # Determine visibility
104
+ vis = ModelVisibility.PUBLIC if visibility == "public" else ModelVisibility.PRIVATE
105
+
106
+ # Map license types
107
+ license_map = {
108
+ "apache-2.0": Licenses.APACHE_V2,
109
+ "mit": Licenses.MIT,
110
+ "gpl-3.0": Licenses.GPL_V3,
111
+ "other": Licenses.OTHER,
112
+ }
113
+ lic = license_map.get(license_type.lower(), Licenses.APACHE_V2)
114
+
115
+ # Create repository if it doesn't exist
116
+ try:
117
+ if repo_type == "model":
118
+ self.ms_api.create_model(
119
+ model_id=repo_id,
120
+ visibility=vis,
121
+ license=lic,
122
+ chinese_name=chinese_name
123
+ )
124
+ except Exception as create_error:
125
+ # Repository might already exist, continue to push
126
+ pass
127
+
128
+ # Push the model/dataset
129
+ if repo_type == "model":
130
+ self.ms_api.push_model(
131
+ model_id=repo_id,
132
+ model_dir=local_path
133
+ )
134
+ else:
135
+ # For datasets, use similar approach
136
+ self.ms_api.push_model(
137
+ model_id=repo_id,
138
+ model_dir=local_path
139
+ )
140
+
141
+ return True, f"✓ Successfully uploaded {repo_type} to ModelScope"
142
+ except Exception as e:
143
+ return False, f"✗ Upload failed: {str(e)}"
144
+
145
+ def cleanup(self):
146
+ """Clean up temporary files."""
147
+ if self.temp_dir and os.path.exists(self.temp_dir):
148
+ try:
149
+ shutil.rmtree(self.temp_dir)
150
+ self.temp_dir = None
151
+ except Exception as e:
152
+ print(f"Warning: Failed to clean up temporary directory: {e}")
153
+
154
+ def migrate(
155
+ self,
156
+ hf_token: str,
157
+ ms_token: str,
158
+ hf_repo_id: str,
159
+ ms_repo_id: str,
160
+ repo_type: str,
161
+ visibility: str,
162
+ license_type: str,
163
+ chinese_name: Optional[str] = None
164
+ ) -> str:
165
+ """Perform the complete migration process.
166
+
167
+ Returns:
168
+ Status message with migration progress
169
+ """
170
+ output = []
171
+
172
+ # Validate inputs
173
+ if not hf_token or not ms_token:
174
+ return "✗ Error: Both HuggingFace and ModelScope tokens are required"
175
+
176
+ if not hf_repo_id or not ms_repo_id:
177
+ return "✗ Error: Both source and destination repository IDs are required"
178
+
179
+ # Authenticate with HuggingFace
180
+ output.append("🔐 Authenticating with HuggingFace...")
181
+ success, msg = self.authenticate_hf(hf_token)
182
+ output.append(msg)
183
+ if not success:
184
+ return "\n".join(output)
185
+
186
+ # Authenticate with ModelScope
187
+ output.append("\n🔐 Authenticating with ModelScope...")
188
+ success, msg = self.authenticate_ms(ms_token)
189
+ output.append(msg)
190
+ if not success:
191
+ return "\n".join(output)
192
+
193
+ # Download from HuggingFace
194
+ output.append(f"\n⬇️ Downloading {repo_type} from HuggingFace: {hf_repo_id}...")
195
+ success, msg, local_path = self.download_from_hf(hf_repo_id, repo_type)
196
+ output.append(msg)
197
+ if not success:
198
+ self.cleanup()
199
+ return "\n".join(output)
200
+
201
+ # Upload to ModelScope
202
+ output.append(f"\n⬆️ Uploading {repo_type} to ModelScope: {ms_repo_id}...")
203
+ success, msg = self.upload_to_ms(
204
+ local_path,
205
+ ms_repo_id,
206
+ repo_type,
207
+ visibility,
208
+ license_type,
209
+ chinese_name
210
+ )
211
+ output.append(msg)
212
+
213
+ # Cleanup
214
+ output.append("\n🧹 Cleaning up temporary files...")
215
+ self.cleanup()
216
+ output.append("✓ Cleanup complete")
217
+
218
+ if success:
219
+ output.append(f"\n✅ Migration completed successfully!")
220
+ output.append(f"Your {repo_type} is now available at: https://www.modelscope.cn/models/{ms_repo_id}")
221
+ else:
222
+ output.append(f"\n❌ Migration failed")
223
+
224
+ return "\n".join(output)
225
+
226
+
227
+ def create_interface():
228
+ """Create the Gradio interface."""
229
+
230
+ migration_tool = MigrationTool()
231
+
232
+ with gr.Blocks(title="HuggingFace to ModelScope Migration Tool") as app:
233
+ gr.Markdown("""
234
+ # 🚀 HuggingFace to ModelScope Migration Tool
235
+
236
+ Easily migrate your models and datasets from HuggingFace to ModelScope.
237
+
238
+ ## 📋 Instructions:
239
+ 1. Get your **HuggingFace token** from: https://huggingface.co/settings/tokens
240
+ 2. Get your **ModelScope token** from: https://www.modelscope.cn/my/myaccesstoken
241
+ 3. Fill in the repository details below
242
+ 4. Click "Start Migration"
243
+ """)
244
+
245
+ with gr.Row():
246
+ with gr.Column():
247
+ gr.Markdown("### 🔑 Authentication")
248
+ hf_token = gr.Textbox(
249
+ label="HuggingFace Token",
250
+ type="password",
251
+ placeholder="hf_...",
252
+ info="Your HuggingFace access token"
253
+ )
254
+ ms_token = gr.Textbox(
255
+ label="ModelScope Token",
256
+ type="password",
257
+ placeholder="Enter your ModelScope token",
258
+ info="Your ModelScope SDK token"
259
+ )
260
+
261
+ with gr.Column():
262
+ gr.Markdown("### 📦 Repository Details")
263
+ repo_type = gr.Radio(
264
+ choices=["model", "dataset"],
265
+ label="Repository Type",
266
+ value="model",
267
+ info="Select what you want to migrate"
268
+ )
269
+ visibility = gr.Radio(
270
+ choices=["public", "private"],
271
+ label="Visibility",
272
+ value="public",
273
+ info="Visibility of the repository on ModelScope"
274
+ )
275
+
276
+ with gr.Row():
277
+ with gr.Column():
278
+ hf_repo_id = gr.Textbox(
279
+ label="Source HuggingFace Repo ID",
280
+ placeholder="username/repo-name",
281
+ info="e.g., bert-base-uncased or username/my-model"
282
+ )
283
+
284
+ with gr.Column():
285
+ ms_repo_id = gr.Textbox(
286
+ label="Destination ModelScope Repo ID",
287
+ placeholder="username/repo-name",
288
+ info="Your ModelScope username/repo-name"
289
+ )
290
+
291
+ with gr.Row():
292
+ with gr.Column():
293
+ license_type = gr.Dropdown(
294
+ choices=["apache-2.0", "mit", "gpl-3.0", "other"],
295
+ label="License",
296
+ value="apache-2.0",
297
+ info="License for the repository"
298
+ )
299
+
300
+ with gr.Column():
301
+ chinese_name = gr.Textbox(
302
+ label="Chinese Name (Optional)",
303
+ placeholder="模型中文名称",
304
+ info="Optional Chinese name for the repository"
305
+ )
306
+
307
+ migrate_btn = gr.Button("🚀 Start Migration", variant="primary", size="lg")
308
+
309
+ output = gr.Textbox(
310
+ label="Migration Status",
311
+ lines=15,
312
+ max_lines=20,
313
+ interactive=False,
314
+ show_copy_button=True
315
+ )
316
+
317
+ migrate_btn.click(
318
+ fn=migration_tool.migrate,
319
+ inputs=[
320
+ hf_token,
321
+ ms_token,
322
+ hf_repo_id,
323
+ ms_repo_id,
324
+ repo_type,
325
+ visibility,
326
+ license_type,
327
+ chinese_name
328
+ ],
329
+ outputs=output
330
+ )
331
+
332
+ gr.Markdown("""
333
+ ---
334
+ ### 📝 Notes:
335
+ - Large models may take some time to download and upload
336
+ - Make sure you have enough disk space for temporary storage
337
+ - Private repositories require appropriate token permissions
338
+ - The tool will create the repository on ModelScope if it doesn't exist
339
+
340
+ ### 🔗 Resources:
341
+ - [HuggingFace Hub](https://huggingface.co/)
342
+ - [ModelScope](https://www.modelscope.cn/)
343
+ - [HuggingFace Token Settings](https://huggingface.co/settings/tokens)
344
+ - [ModelScope Token Settings](https://www.modelscope.cn/my/myaccesstoken)
345
+ """)
346
+
347
+ return app
348
+
349
+
350
+ if __name__ == "__main__":
351
+ app = create_interface()
352
+ app.launch(share=False)
example_usage.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Example script demonstrating programmatic usage of the HuggingFace to ModelScope Migration Tool.
3
+
4
+ This example shows how to use the MigrationTool class directly without the Gradio UI.
5
+ """
6
+
7
+ import os
8
+ from app import MigrationTool
9
+
10
+
11
+ def main():
12
+ """Example migration workflow."""
13
+
14
+ # Initialize the migration tool
15
+ tool = MigrationTool()
16
+
17
+ # Configuration - Replace these with your actual values
18
+ # IMPORTANT: Never hardcode tokens in production code!
19
+ # Use environment variables or secure credential management instead.
20
+ HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN", "")
21
+ MS_TOKEN = os.getenv("MODELSCOPE_TOKEN", "")
22
+
23
+ # Source repository on HuggingFace
24
+ HF_REPO_ID = "sentence-transformers/all-MiniLM-L6-v2" # Example small model
25
+
26
+ # Destination repository on ModelScope
27
+ MS_REPO_ID = "your-username/all-MiniLM-L6-v2" # Replace with your repo
28
+
29
+ # Repository configuration
30
+ REPO_TYPE = "model" # or "dataset"
31
+ VISIBILITY = "public" # or "private"
32
+ LICENSE = "apache-2.0" # apache-2.0, mit, gpl-3.0, other
33
+ CHINESE_NAME = "小型句子转换模型" # Optional
34
+
35
+ # Validate tokens
36
+ if not HF_TOKEN or not MS_TOKEN:
37
+ print("Error: Please set HUGGINGFACE_TOKEN and MODELSCOPE_TOKEN environment variables")
38
+ print("\nExample:")
39
+ print(" export HUGGINGFACE_TOKEN='hf_...'")
40
+ print(" export MODELSCOPE_TOKEN='your-token'")
41
+ print(" python example_usage.py")
42
+ return
43
+
44
+ print("=" * 60)
45
+ print("HuggingFace to ModelScope Migration Tool - Example Usage")
46
+ print("=" * 60)
47
+ print()
48
+ print(f"Source: {HF_REPO_ID}")
49
+ print(f"Destination: {MS_REPO_ID}")
50
+ print(f"Type: {REPO_TYPE}")
51
+ print(f"Visibility: {VISIBILITY}")
52
+ print()
53
+
54
+ # Perform the migration
55
+ result = tool.migrate(
56
+ hf_token=HF_TOKEN,
57
+ ms_token=MS_TOKEN,
58
+ hf_repo_id=HF_REPO_ID,
59
+ ms_repo_id=MS_REPO_ID,
60
+ repo_type=REPO_TYPE,
61
+ visibility=VISIBILITY,
62
+ license_type=LICENSE,
63
+ chinese_name=CHINESE_NAME
64
+ )
65
+
66
+ # Print the result
67
+ print(result)
68
+ print()
69
+ print("=" * 60)
70
+
71
+
72
+ if __name__ == "__main__":
73
+ main()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=4.0.0
2
+ huggingface-hub>=0.20.0
3
+ modelscope>=1.11.0