File size: 3,534 Bytes
41b81a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
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
/**
 * Upload .safetensors files directly to HuggingFace using Node.js
 * 
 * Install dependencies first:
 * npm install @huggingface/hub fs-extra
 * 
 * Usage:
 * node upload-model.js
 */

const { HfApi } = require("@huggingface/hub");
const fs = require("fs-extra");
const path = require("path");

// Configuration
const CONFIG = {
    // Your HuggingFace access token (get it from https://huggingface.co/settings/tokens)
    token: "hf_YOUR_TOKEN_HERE",
    
    // Your model repository
    repoId: "Trouter-Library/Trouter-20B",
    
    // Local path where your .safetensors files are located
    localModelPath: "./model_files",
    
    // Files to upload (add all your safetensors files here)
    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));
    
    // Initialize HuggingFace API
    const hf = new HfApi(CONFIG.token);
    
    console.log(`\nRepository: ${CONFIG.repoId}`);
    console.log(`Local path: ${CONFIG.localModelPath}\n`);
    
    // Check if repository exists
    try {
        await hf.whoami();
        console.log("βœ“ Authentication successful\n");
    } catch (error) {
        console.error("βœ— Authentication failed. Check your token!");
        process.exit(1);
    }
    
    // Upload each file
    let successCount = 0;
    let failCount = 0;
    
    for (const fileName of CONFIG.filesToUpload) {
        const localPath = path.join(CONFIG.localModelPath, fileName);
        
        // Check if file exists
        if (!await fs.pathExists(localPath)) {
            console.log(`⚠ File not found: ${localPath}`);
            failCount++;
            continue;
        }
        
        // Get file size
        const stats = await fs.stat(localPath);
        const fileSizeGB = (stats.size / (1024 * 1024 * 1024)).toFixed(2);
        console.log(`File size: ${fileSizeGB} GB`);
        
        // Upload file
        const success = await uploadFile(hf, localPath, fileName);
        
        if (success) {
            successCount++;
        } else {
            failCount++;
        }
        
        console.log("");
    }
    
    // Summary
    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}`);
}

// Run the script
main().catch(console.error);