Spaces:
Running
Running
Upload 6 files
Browse files- README.md +212 -210
- app.py +15 -53
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,210 +1,212 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
title: Modelscope Migration
|
| 4 |
-
sdk: gradio
|
| 5 |
-
emoji: π
|
| 6 |
-
colorFrom: red
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
- **
|
| 19 |
-
- **
|
| 20 |
-
- **
|
| 21 |
-
- **
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
-
|
| 28 |
-
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
```
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
```
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
- **
|
| 61 |
-
- **
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
##
|
| 68 |
-
|
| 69 |
-
###
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
| 85 |
-
|
|
| 86 |
-
| **
|
| 87 |
-
| **
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
- `
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
##
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
-
|
| 116 |
-
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
-
|
| 131 |
-
-
|
| 132 |
-
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
- **
|
| 139 |
-
- **
|
| 140 |
-
- **
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
-
|
| 147 |
-
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
##
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
##
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
- [
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
title: Modelscope Migration
|
| 4 |
+
sdk: gradio
|
| 5 |
+
emoji: π
|
| 6 |
+
colorFrom: red
|
| 7 |
+
colorTo: blue
|
| 8 |
+
short_description: Migrate your models to modelscope
|
| 9 |
+
sdk_version: 6.2.0
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# π HuggingFace to ModelScope Migration Tool
|
| 13 |
+
|
| 14 |
+
A user-friendly Gradio application for migrating models and datasets from [HuggingFace](https://huggingface.co/) to [ModelScope](https://www.modelscope.cn/).
|
| 15 |
+
|
| 16 |
+
## β¨ Features
|
| 17 |
+
|
| 18 |
+
- **Easy Migration**: Migrate models and datasets with a simple web interface
|
| 19 |
+
- **Secure Authentication**: Supports token-based authentication for both platforms
|
| 20 |
+
- **Progress Tracking**: Real-time status updates during migration
|
| 21 |
+
- **Flexible Configuration**: Customize repository visibility, license, and metadata
|
| 22 |
+
- **Error Handling**: Comprehensive error messages and validation
|
| 23 |
+
- **Automatic Cleanup**: Temporary files are automatically cleaned up after migration
|
| 24 |
+
|
| 25 |
+
## π Prerequisites
|
| 26 |
+
|
| 27 |
+
- Python 3.8 or higher
|
| 28 |
+
- Internet connection
|
| 29 |
+
- HuggingFace account and access token
|
| 30 |
+
- ModelScope account and SDK token
|
| 31 |
+
|
| 32 |
+
## π§ Installation
|
| 33 |
+
|
| 34 |
+
1. Clone this repository:
|
| 35 |
+
```bash
|
| 36 |
+
git clone <repository-url>
|
| 37 |
+
cd modelscope-migration
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
2. Install dependencies:
|
| 41 |
+
```bash
|
| 42 |
+
pip install -r requirements.txt
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Or install manually:
|
| 46 |
+
```bash
|
| 47 |
+
pip install gradio huggingface-hub modelscope
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## π Quick Start
|
| 51 |
+
|
| 52 |
+
1. Run the application:
|
| 53 |
+
```bash
|
| 54 |
+
python app.py
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
2. Open your browser and navigate to the provided URL (usually `http://localhost:7860`)
|
| 58 |
+
|
| 59 |
+
3. Fill in the required information:
|
| 60 |
+
- **HuggingFace Token**: Get from https://huggingface.co/settings/tokens
|
| 61 |
+
- **ModelScope Token**: Get from https://www.modelscope.cn/my/myaccesstoken
|
| 62 |
+
- **Source Repository**: The HuggingFace repository ID (e.g., `bert-base-uncased`)
|
| 63 |
+
- **Destination Repository**: Your desired ModelScope repository ID (e.g., `username/my-model`)
|
| 64 |
+
|
| 65 |
+
4. Click "Start Migration" and wait for completion
|
| 66 |
+
|
| 67 |
+
## π Usage Guide
|
| 68 |
+
|
| 69 |
+
### Getting Your Tokens
|
| 70 |
+
|
| 71 |
+
#### HuggingFace Token:
|
| 72 |
+
1. Go to https://huggingface.co/settings/tokens
|
| 73 |
+
2. Click "New token"
|
| 74 |
+
3. Give it a name and select appropriate permissions
|
| 75 |
+
4. Copy the token (starts with `hf_`)
|
| 76 |
+
|
| 77 |
+
#### ModelScope Token:
|
| 78 |
+
1. Go to https://www.modelscope.cn/my/myaccesstoken
|
| 79 |
+
2. Log in to your account
|
| 80 |
+
3. Copy your SDK token
|
| 81 |
+
|
| 82 |
+
### Migration Options
|
| 83 |
+
|
| 84 |
+
| Option | Description | Default |
|
| 85 |
+
|--------|-------------|---------|
|
| 86 |
+
| **Repository Type** | Choose between `model` or `dataset` | `model` |
|
| 87 |
+
| **Visibility** | Set repository as `public` or `private` | `public` |
|
| 88 |
+
| **License** | Choose from Apache 2.0, MIT, GPL-3.0, or Other | `apache-2.0` |
|
| 89 |
+
| **Chinese Name** | Optional Chinese name for the repository | None |
|
| 90 |
+
|
| 91 |
+
### Example Repository IDs
|
| 92 |
+
|
| 93 |
+
**HuggingFace:**
|
| 94 |
+
- `bert-base-uncased` (official model)
|
| 95 |
+
- `username/my-custom-model` (user model)
|
| 96 |
+
- `datasets/squad` (dataset)
|
| 97 |
+
|
| 98 |
+
**ModelScope:**
|
| 99 |
+
- `username/repo-name` (always requires username prefix)
|
| 100 |
+
|
| 101 |
+
## π οΈ How It Works
|
| 102 |
+
|
| 103 |
+
The migration process follows these steps:
|
| 104 |
+
|
| 105 |
+
1. **Authentication**: Validates tokens for both HuggingFace and ModelScope
|
| 106 |
+
2. **Download**: Uses `snapshot_download` to download the entire repository from HuggingFace
|
| 107 |
+
3. **Upload**: Creates repository on ModelScope (if needed) and uploads all files
|
| 108 |
+
4. **Cleanup**: Removes temporary files from local storage
|
| 109 |
+
|
| 110 |
+
## π Features in Detail
|
| 111 |
+
|
| 112 |
+
### Model Migration
|
| 113 |
+
|
| 114 |
+
Migrates complete model repositories including:
|
| 115 |
+
- Model weights and configuration files
|
| 116 |
+
- Tokenizer files
|
| 117 |
+
- README and documentation
|
| 118 |
+
- Any additional files in the repository
|
| 119 |
+
|
| 120 |
+
### Dataset Migration
|
| 121 |
+
|
| 122 |
+
Migrates dataset repositories including:
|
| 123 |
+
- Dataset files (all formats)
|
| 124 |
+
- Dataset cards and metadata
|
| 125 |
+
- Scripts and configuration files
|
| 126 |
+
|
| 127 |
+
### Error Handling
|
| 128 |
+
|
| 129 |
+
The tool provides clear error messages for:
|
| 130 |
+
- Invalid tokens
|
| 131 |
+
- Repository not found
|
| 132 |
+
- Permission errors
|
| 133 |
+
- Network issues
|
| 134 |
+
- Disk space problems
|
| 135 |
+
|
| 136 |
+
## β οΈ Important Notes
|
| 137 |
+
|
| 138 |
+
- **Disk Space**: Ensure you have enough disk space for temporary storage of the repository
|
| 139 |
+
- **Large Models**: Migration time depends on repository size and network speed
|
| 140 |
+
- **Permissions**: Your tokens must have appropriate read/write permissions
|
| 141 |
+
- **Private Repos**: To migrate private repositories, ensure your HuggingFace token has access
|
| 142 |
+
- **Repository Creation**: The tool automatically creates the ModelScope repository if it doesn't exist
|
| 143 |
+
|
| 144 |
+
## π Security
|
| 145 |
+
|
| 146 |
+
- Tokens are handled securely and not logged
|
| 147 |
+
- Tokens are entered as password fields (hidden input)
|
| 148 |
+
- Temporary files are cleaned up after migration
|
| 149 |
+
- No data is stored permanently on the server
|
| 150 |
+
|
| 151 |
+
## π Troubleshooting
|
| 152 |
+
|
| 153 |
+
### "Authentication failed"
|
| 154 |
+
- Verify your tokens are correct and not expired
|
| 155 |
+
- Check that you're using the right token for each platform
|
| 156 |
+
|
| 157 |
+
### "Download failed"
|
| 158 |
+
- Ensure the HuggingFace repository exists and is accessible
|
| 159 |
+
- Check your internet connection
|
| 160 |
+
- Verify you have permission to access the repository
|
| 161 |
+
|
| 162 |
+
### "Upload failed"
|
| 163 |
+
- Verify your ModelScope token has write permissions
|
| 164 |
+
- Check that the destination repository name is valid
|
| 165 |
+
- Ensure you're not exceeding ModelScope's quotas
|
| 166 |
+
|
| 167 |
+
### "Disk space error"
|
| 168 |
+
- Free up disk space on your system
|
| 169 |
+
- Large models require significant temporary storage
|
| 170 |
+
|
| 171 |
+
## π API Documentation
|
| 172 |
+
|
| 173 |
+
### HuggingFace Hub
|
| 174 |
+
- Documentation: https://huggingface.co/docs/huggingface_hub
|
| 175 |
+
- PyPI: https://pypi.org/project/huggingface-hub/
|
| 176 |
+
|
| 177 |
+
### ModelScope
|
| 178 |
+
- GitHub: https://github.com/modelscope/modelscope
|
| 179 |
+
- PyPI: https://pypi.org/project/modelscope/
|
| 180 |
+
|
| 181 |
+
## π€ Contributing
|
| 182 |
+
|
| 183 |
+
Contributions are welcome! Please feel free to submit issues or pull requests.
|
| 184 |
+
|
| 185 |
+
## π License
|
| 186 |
+
|
| 187 |
+
This project is open source and available under the Apache 2.0 License.
|
| 188 |
+
|
| 189 |
+
## π Resources
|
| 190 |
+
|
| 191 |
+
- [HuggingFace Hub](https://huggingface.co/)
|
| 192 |
+
- [ModelScope Platform](https://www.modelscope.cn/)
|
| 193 |
+
- [Gradio Documentation](https://gradio.app/docs/)
|
| 194 |
+
|
| 195 |
+
## π‘ Tips
|
| 196 |
+
|
| 197 |
+
1. **Test with small models first**: Before migrating large models, test with a smaller repository
|
| 198 |
+
2. **Check licenses**: Ensure you have the right to migrate and redistribute the model/dataset
|
| 199 |
+
3. **Preserve metadata**: The tool preserves all files, but review the ModelScope repository after migration
|
| 200 |
+
4. **Network stability**: For large repositories, ensure a stable internet connection
|
| 201 |
+
|
| 202 |
+
## π Support
|
| 203 |
+
|
| 204 |
+
If you encounter issues:
|
| 205 |
+
1. Check the troubleshooting section above
|
| 206 |
+
2. Review the error message in the status output
|
| 207 |
+
3. Verify your tokens and repository IDs
|
| 208 |
+
4. Check the official documentation for HuggingFace and ModelScope
|
| 209 |
+
|
| 210 |
+
---
|
| 211 |
+
|
| 212 |
+
Made with β€οΈ using [Gradio](https://gradio.app/), [HuggingFace Hub](https://huggingface.co/), and [ModelScope](https://www.modelscope.cn/)
|
app.py
CHANGED
|
@@ -20,42 +20,20 @@ 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.ms_token = None
|
| 26 |
self.temp_dir = None
|
| 27 |
|
| 28 |
-
def authenticate_hf(self, token: str) -> Tuple[bool, str]:
|
| 29 |
-
"""Authenticate with HuggingFace."""
|
| 30 |
-
try:
|
| 31 |
-
self.hf_api = HfApi(token=token)
|
| 32 |
-
# Test the token
|
| 33 |
-
self.hf_api.whoami(token=token)
|
| 34 |
-
return True, "β HuggingFace authentication successful"
|
| 35 |
-
except Exception as e:
|
| 36 |
-
return False, f"β HuggingFace authentication failed: {str(e)}"
|
| 37 |
-
|
| 38 |
-
def authenticate_ms(self, token: str) -> Tuple[bool, str]:
|
| 39 |
-
"""Authenticate with ModelScope."""
|
| 40 |
-
try:
|
| 41 |
-
# Store the token and create HubApi instance
|
| 42 |
-
# We'll authenticate when actually using the API
|
| 43 |
-
self.ms_token = token
|
| 44 |
-
self.ms_api = HubApi()
|
| 45 |
-
return True, "β ModelScope token stored successfully"
|
| 46 |
-
except Exception as e:
|
| 47 |
-
return False, f"β ModelScope initialization failed: {str(e)}"
|
| 48 |
-
|
| 49 |
def download_from_hf(
|
| 50 |
self,
|
| 51 |
repo_id: str,
|
| 52 |
-
repo_type: str = "model"
|
|
|
|
| 53 |
) -> Tuple[bool, str, Optional[str]]:
|
| 54 |
"""Download a repository from HuggingFace.
|
| 55 |
|
| 56 |
Args:
|
| 57 |
repo_id: HuggingFace repository ID (e.g., 'username/repo-name')
|
| 58 |
repo_type: Type of repository ('model' or 'dataset')
|
|
|
|
| 59 |
|
| 60 |
Returns:
|
| 61 |
Tuple of (success, message, local_path)
|
|
@@ -70,7 +48,7 @@ class MigrationTool:
|
|
| 70 |
repo_type=repo_type,
|
| 71 |
local_dir=self.temp_dir,
|
| 72 |
local_dir_use_symlinks=False,
|
| 73 |
-
token=
|
| 74 |
)
|
| 75 |
|
| 76 |
return True, f"β Successfully downloaded {repo_type} from HuggingFace", local_path
|
|
@@ -81,6 +59,7 @@ class MigrationTool:
|
|
| 81 |
self,
|
| 82 |
local_path: str,
|
| 83 |
repo_id: str,
|
|
|
|
| 84 |
repo_type: str = "model",
|
| 85 |
visibility: str = "public",
|
| 86 |
license_type: str = "apache-2.0",
|
|
@@ -91,6 +70,7 @@ class MigrationTool:
|
|
| 91 |
Args:
|
| 92 |
local_path: Local path to the repository
|
| 93 |
repo_id: ModelScope repository ID (e.g., 'username/repo-name')
|
|
|
|
| 94 |
repo_type: Type of repository ('model' or 'dataset')
|
| 95 |
visibility: Repository visibility ('public' or 'private')
|
| 96 |
license_type: License type
|
|
@@ -100,14 +80,9 @@ class MigrationTool:
|
|
| 100 |
Tuple of (success, message)
|
| 101 |
"""
|
| 102 |
try:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
# Login with the stored token
|
| 107 |
-
try:
|
| 108 |
-
self.ms_api.login(self.ms_token)
|
| 109 |
-
except Exception as login_error:
|
| 110 |
-
return False, f"β ModelScope login failed: {str(login_error)}"
|
| 111 |
|
| 112 |
# Determine visibility
|
| 113 |
vis = ModelVisibility.PUBLIC if visibility == "public" else ModelVisibility.PRIVATE
|
|
@@ -124,7 +99,7 @@ class MigrationTool:
|
|
| 124 |
# Create repository if it doesn't exist
|
| 125 |
try:
|
| 126 |
if repo_type == "model":
|
| 127 |
-
|
| 128 |
model_id=repo_id,
|
| 129 |
visibility=vis,
|
| 130 |
license=lic,
|
|
@@ -136,13 +111,13 @@ class MigrationTool:
|
|
| 136 |
|
| 137 |
# Push the model/dataset
|
| 138 |
if repo_type == "model":
|
| 139 |
-
|
| 140 |
model_id=repo_id,
|
| 141 |
model_dir=local_path
|
| 142 |
)
|
| 143 |
else:
|
| 144 |
# For datasets, use similar approach
|
| 145 |
-
|
| 146 |
model_id=repo_id,
|
| 147 |
model_dir=local_path
|
| 148 |
)
|
|
@@ -185,23 +160,9 @@ class MigrationTool:
|
|
| 185 |
if not hf_repo_id or not ms_repo_id:
|
| 186 |
return "β Error: Both source and destination repository IDs are required"
|
| 187 |
|
| 188 |
-
# Authenticate with HuggingFace
|
| 189 |
-
output.append("π Authenticating with HuggingFace...")
|
| 190 |
-
success, msg = self.authenticate_hf(hf_token)
|
| 191 |
-
output.append(msg)
|
| 192 |
-
if not success:
|
| 193 |
-
return "\n".join(output)
|
| 194 |
-
|
| 195 |
-
# Authenticate with ModelScope
|
| 196 |
-
output.append("\nπ Authenticating with ModelScope...")
|
| 197 |
-
success, msg = self.authenticate_ms(ms_token)
|
| 198 |
-
output.append(msg)
|
| 199 |
-
if not success:
|
| 200 |
-
return "\n".join(output)
|
| 201 |
-
|
| 202 |
# Download from HuggingFace
|
| 203 |
-
output.append(f"
|
| 204 |
-
success, msg, local_path = self.download_from_hf(hf_repo_id, repo_type)
|
| 205 |
output.append(msg)
|
| 206 |
if not success:
|
| 207 |
self.cleanup()
|
|
@@ -212,6 +173,7 @@ class MigrationTool:
|
|
| 212 |
success, msg = self.upload_to_ms(
|
| 213 |
local_path,
|
| 214 |
ms_repo_id,
|
|
|
|
| 215 |
repo_type,
|
| 216 |
visibility,
|
| 217 |
license_type,
|
|
|
|
| 20 |
"""Handles migration of models and datasets between HuggingFace and ModelScope."""
|
| 21 |
|
| 22 |
def __init__(self):
|
|
|
|
|
|
|
|
|
|
| 23 |
self.temp_dir = None
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def download_from_hf(
|
| 26 |
self,
|
| 27 |
repo_id: str,
|
| 28 |
+
repo_type: str = "model",
|
| 29 |
+
token: Optional[str] = None
|
| 30 |
) -> Tuple[bool, str, Optional[str]]:
|
| 31 |
"""Download a repository from HuggingFace.
|
| 32 |
|
| 33 |
Args:
|
| 34 |
repo_id: HuggingFace repository ID (e.g., 'username/repo-name')
|
| 35 |
repo_type: Type of repository ('model' or 'dataset')
|
| 36 |
+
token: HuggingFace authentication token
|
| 37 |
|
| 38 |
Returns:
|
| 39 |
Tuple of (success, message, local_path)
|
|
|
|
| 48 |
repo_type=repo_type,
|
| 49 |
local_dir=self.temp_dir,
|
| 50 |
local_dir_use_symlinks=False,
|
| 51 |
+
token=token
|
| 52 |
)
|
| 53 |
|
| 54 |
return True, f"β Successfully downloaded {repo_type} from HuggingFace", local_path
|
|
|
|
| 59 |
self,
|
| 60 |
local_path: str,
|
| 61 |
repo_id: str,
|
| 62 |
+
token: str,
|
| 63 |
repo_type: str = "model",
|
| 64 |
visibility: str = "public",
|
| 65 |
license_type: str = "apache-2.0",
|
|
|
|
| 70 |
Args:
|
| 71 |
local_path: Local path to the repository
|
| 72 |
repo_id: ModelScope repository ID (e.g., 'username/repo-name')
|
| 73 |
+
token: ModelScope authentication token
|
| 74 |
repo_type: Type of repository ('model' or 'dataset')
|
| 75 |
visibility: Repository visibility ('public' or 'private')
|
| 76 |
license_type: License type
|
|
|
|
| 80 |
Tuple of (success, message)
|
| 81 |
"""
|
| 82 |
try:
|
| 83 |
+
# Create HubApi instance and login
|
| 84 |
+
api = HubApi()
|
| 85 |
+
api.login(token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# Determine visibility
|
| 88 |
vis = ModelVisibility.PUBLIC if visibility == "public" else ModelVisibility.PRIVATE
|
|
|
|
| 99 |
# Create repository if it doesn't exist
|
| 100 |
try:
|
| 101 |
if repo_type == "model":
|
| 102 |
+
api.create_model(
|
| 103 |
model_id=repo_id,
|
| 104 |
visibility=vis,
|
| 105 |
license=lic,
|
|
|
|
| 111 |
|
| 112 |
# Push the model/dataset
|
| 113 |
if repo_type == "model":
|
| 114 |
+
api.push_model(
|
| 115 |
model_id=repo_id,
|
| 116 |
model_dir=local_path
|
| 117 |
)
|
| 118 |
else:
|
| 119 |
# For datasets, use similar approach
|
| 120 |
+
api.push_model(
|
| 121 |
model_id=repo_id,
|
| 122 |
model_dir=local_path
|
| 123 |
)
|
|
|
|
| 160 |
if not hf_repo_id or not ms_repo_id:
|
| 161 |
return "β Error: Both source and destination repository IDs are required"
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# Download from HuggingFace
|
| 164 |
+
output.append(f"β¬οΈ Downloading {repo_type} from HuggingFace: {hf_repo_id}...")
|
| 165 |
+
success, msg, local_path = self.download_from_hf(hf_repo_id, repo_type, hf_token)
|
| 166 |
output.append(msg)
|
| 167 |
if not success:
|
| 168 |
self.cleanup()
|
|
|
|
| 173 |
success, msg = self.upload_to_ms(
|
| 174 |
local_path,
|
| 175 |
ms_repo_id,
|
| 176 |
+
ms_token,
|
| 177 |
repo_type,
|
| 178 |
visibility,
|
| 179 |
license_type,
|
requirements.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
| 1 |
gradio>=4.0.0
|
| 2 |
huggingface-hub>=0.20.0
|
| 3 |
modelscope>=1.11.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
gradio>=4.0.0
|
| 2 |
huggingface-hub>=0.20.0
|
| 3 |
modelscope>=1.11.0
|
| 4 |
+
|
| 5 |
+
# Performance optimization for faster downloads/uploads
|
| 6 |
+
hf_transfer # Faster upload/download with Rust-based backend
|
| 7 |
+
hf_xet # XetHub integration for efficient model transfers
|