Create upload-model.js
Browse files- upload-model.js +122 -0
upload-model.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Upload .safetensors files directly to HuggingFace using Node.js
|
| 3 |
+
*
|
| 4 |
+
* Install dependencies first:
|
| 5 |
+
* npm install @huggingface/hub fs-extra
|
| 6 |
+
*
|
| 7 |
+
* Usage:
|
| 8 |
+
* node upload-model.js
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
const { HfApi } = require("@huggingface/hub");
|
| 12 |
+
const fs = require("fs-extra");
|
| 13 |
+
const path = require("path");
|
| 14 |
+
|
| 15 |
+
// Configuration
|
| 16 |
+
const CONFIG = {
|
| 17 |
+
// Your HuggingFace access token (get it from https://huggingface.co/settings/tokens)
|
| 18 |
+
token: "hf_YOUR_TOKEN_HERE",
|
| 19 |
+
|
| 20 |
+
// Your model repository
|
| 21 |
+
repoId: "Trouter-Library/Trouter-20B",
|
| 22 |
+
|
| 23 |
+
// Local path where your .safetensors files are located
|
| 24 |
+
localModelPath: "./model_files",
|
| 25 |
+
|
| 26 |
+
// Files to upload (add all your safetensors files here)
|
| 27 |
+
filesToUpload: [
|
| 28 |
+
"model-00001-of-00008.safetensors",
|
| 29 |
+
"model-00002-of-00008.safetensors",
|
| 30 |
+
"model-00003-of-00008.safetensors",
|
| 31 |
+
"model-00004-of-00008.safetensors",
|
| 32 |
+
"model-00005-of-00008.safetensors",
|
| 33 |
+
"model-00006-of-00008.safetensors",
|
| 34 |
+
"model-00007-of-00008.safetensors",
|
| 35 |
+
"model-00008-of-00008.safetensors",
|
| 36 |
+
"model.safetensors.index.json"
|
| 37 |
+
]
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
async function uploadFile(hf, filePath, repoPath) {
|
| 41 |
+
try {
|
| 42 |
+
console.log(`Uploading ${repoPath}...`);
|
| 43 |
+
|
| 44 |
+
const fileContent = await fs.readFile(filePath);
|
| 45 |
+
|
| 46 |
+
await hf.uploadFile({
|
| 47 |
+
repo: CONFIG.repoId,
|
| 48 |
+
path: repoPath,
|
| 49 |
+
file: fileContent,
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
console.log(`✓ Successfully uploaded ${repoPath}`);
|
| 53 |
+
return true;
|
| 54 |
+
} catch (error) {
|
| 55 |
+
console.error(`✗ Failed to upload ${repoPath}:`, error.message);
|
| 56 |
+
return false;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
async function main() {
|
| 61 |
+
console.log("=".repeat(60));
|
| 62 |
+
console.log("Trouter-20B Model Upload Script");
|
| 63 |
+
console.log("=".repeat(60));
|
| 64 |
+
|
| 65 |
+
// Initialize HuggingFace API
|
| 66 |
+
const hf = new HfApi(CONFIG.token);
|
| 67 |
+
|
| 68 |
+
console.log(`\nRepository: ${CONFIG.repoId}`);
|
| 69 |
+
console.log(`Local path: ${CONFIG.localModelPath}\n`);
|
| 70 |
+
|
| 71 |
+
// Check if repository exists
|
| 72 |
+
try {
|
| 73 |
+
await hf.whoami();
|
| 74 |
+
console.log("✓ Authentication successful\n");
|
| 75 |
+
} catch (error) {
|
| 76 |
+
console.error("✗ Authentication failed. Check your token!");
|
| 77 |
+
process.exit(1);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// Upload each file
|
| 81 |
+
let successCount = 0;
|
| 82 |
+
let failCount = 0;
|
| 83 |
+
|
| 84 |
+
for (const fileName of CONFIG.filesToUpload) {
|
| 85 |
+
const localPath = path.join(CONFIG.localModelPath, fileName);
|
| 86 |
+
|
| 87 |
+
// Check if file exists
|
| 88 |
+
if (!await fs.pathExists(localPath)) {
|
| 89 |
+
console.log(`âš File not found: ${localPath}`);
|
| 90 |
+
failCount++;
|
| 91 |
+
continue;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// Get file size
|
| 95 |
+
const stats = await fs.stat(localPath);
|
| 96 |
+
const fileSizeGB = (stats.size / (1024 * 1024 * 1024)).toFixed(2);
|
| 97 |
+
console.log(`File size: ${fileSizeGB} GB`);
|
| 98 |
+
|
| 99 |
+
// Upload file
|
| 100 |
+
const success = await uploadFile(hf, localPath, fileName);
|
| 101 |
+
|
| 102 |
+
if (success) {
|
| 103 |
+
successCount++;
|
| 104 |
+
} else {
|
| 105 |
+
failCount++;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
console.log("");
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// Summary
|
| 112 |
+
console.log("=".repeat(60));
|
| 113 |
+
console.log("Upload Summary");
|
| 114 |
+
console.log("=".repeat(60));
|
| 115 |
+
console.log(`✓ Successful: ${successCount}`);
|
| 116 |
+
console.log(`✗ Failed: ${failCount}`);
|
| 117 |
+
console.log(`Total: ${CONFIG.filesToUpload.length}`);
|
| 118 |
+
console.log("\nModel repository:", `https://huggingface.co/${CONFIG.repoId}`);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// Run the script
|
| 122 |
+
main().catch(console.error);
|