|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { HfApi } = require("@huggingface/hub"); |
|
|
const fs = require("fs-extra"); |
|
|
const path = require("path"); |
|
|
|
|
|
|
|
|
const CONFIG = { |
|
|
|
|
|
token: "hf_YOUR_TOKEN_HERE", |
|
|
|
|
|
|
|
|
repoId: "Trouter-Library/Trouter-20B", |
|
|
|
|
|
|
|
|
localModelPath: "./model_files", |
|
|
|
|
|
|
|
|
filesToUpload: [ |
|
|
"model-00001-of-00008.safetensors", |
|
|
"model-00002-of-00008.safetensors", |
|
|
"model-00003-of-00008.safetensors", |
|
|
"model-00004-of-00008.safetensors", |
|
|
"model-00005-of-00008.safetensors", |
|
|
"model-00006-of-00008.safetensors", |
|
|
"model-00007-of-00008.safetensors", |
|
|
"model-00008-of-00008.safetensors", |
|
|
"model.safetensors.index.json" |
|
|
] |
|
|
}; |
|
|
|
|
|
async function uploadFile(hf, filePath, repoPath) { |
|
|
try { |
|
|
console.log(`Uploading ${repoPath}...`); |
|
|
|
|
|
const fileContent = await fs.readFile(filePath); |
|
|
|
|
|
await hf.uploadFile({ |
|
|
repo: CONFIG.repoId, |
|
|
path: repoPath, |
|
|
file: fileContent, |
|
|
}); |
|
|
|
|
|
console.log(`β Successfully uploaded ${repoPath}`); |
|
|
return true; |
|
|
} catch (error) { |
|
|
console.error(`β Failed to upload ${repoPath}:`, error.message); |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
async function main() { |
|
|
console.log("=".repeat(60)); |
|
|
console.log("Trouter-20B Model Upload Script"); |
|
|
console.log("=".repeat(60)); |
|
|
|
|
|
|
|
|
const hf = new HfApi(CONFIG.token); |
|
|
|
|
|
console.log(`\nRepository: ${CONFIG.repoId}`); |
|
|
console.log(`Local path: ${CONFIG.localModelPath}\n`); |
|
|
|
|
|
|
|
|
try { |
|
|
await hf.whoami(); |
|
|
console.log("β Authentication successful\n"); |
|
|
} catch (error) { |
|
|
console.error("β Authentication failed. Check your token!"); |
|
|
process.exit(1); |
|
|
} |
|
|
|
|
|
|
|
|
let successCount = 0; |
|
|
let failCount = 0; |
|
|
|
|
|
for (const fileName of CONFIG.filesToUpload) { |
|
|
const localPath = path.join(CONFIG.localModelPath, fileName); |
|
|
|
|
|
|
|
|
if (!await fs.pathExists(localPath)) { |
|
|
console.log(`β File not found: ${localPath}`); |
|
|
failCount++; |
|
|
continue; |
|
|
} |
|
|
|
|
|
|
|
|
const stats = await fs.stat(localPath); |
|
|
const fileSizeGB = (stats.size / (1024 * 1024 * 1024)).toFixed(2); |
|
|
console.log(`File size: ${fileSizeGB} GB`); |
|
|
|
|
|
|
|
|
const success = await uploadFile(hf, localPath, fileName); |
|
|
|
|
|
if (success) { |
|
|
successCount++; |
|
|
} else { |
|
|
failCount++; |
|
|
} |
|
|
|
|
|
console.log(""); |
|
|
} |
|
|
|
|
|
|
|
|
console.log("=".repeat(60)); |
|
|
console.log("Upload Summary"); |
|
|
console.log("=".repeat(60)); |
|
|
console.log(`β Successful: ${successCount}`); |
|
|
console.log(`β Failed: ${failCount}`); |
|
|
console.log(`Total: ${CONFIG.filesToUpload.length}`); |
|
|
console.log("\nModel repository:", `https://huggingface.co/${CONFIG.repoId}`); |
|
|
} |
|
|
|
|
|
|
|
|
main().catch(console.error); |