File size: 4,469 Bytes
a25386c
a2c64e7
 
 
 
 
a25386c
a2c64e7
 
 
 
a25386c
 
 
 
 
 
 
a2c64e7
 
 
 
 
 
7ad9382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a2c64e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a25386c
a2c64e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# Vico - Quick Start Guide (Python)

## 🎯 Setup Cepat (5 Menit)

### 1. Install Dependencies
```bash
pip install -r requirements.txt
```

### 2. Jalankan Server
```bash
# Production mode
python3 server.py

# Development mode
export FLASK_APP=server.py
export FLASK_ENV=development
flask run --reload
```

Server akan berjalan di `http://localhost:3000`

### 3. Test Upload

#### Cara 1: Dengan Environment Variables (Recommended)

**Setup .env:**
```bash
# Copy dari .env.example
cp .env.example .env

# Edit .env dan set:
# HF_TOKEN=hf_your_token_here
# HF_REPO_ID=username/my-dataset
```

**Kemudian upload hanya dengan file:**
```bash
# cURL
curl -X POST http://localhost:3000/api/upload \
  -F "file=@test.csv"

# atau
bash examples/env-upload.sh
```

#### Cara 2: Via cURL (Terminal)
```bash
# Siapkan file test
echo "id,name,value" > test.csv
echo "1,Alice,100" >> test.csv

# Upload
curl -X POST http://localhost:3000/api/upload \
  -F "file=@test.csv" \
  -F "repo_id=username/my-dataset" \
  -F "token=hf_your_token_here"
```

#### Via Browser
1. Buka `http://localhost:3000`
2. Redirect ke file `examples/index.html`
3. Atau buka langsung: `examples/index.html`

#### Via Node.js
```bash
node examples/nodejs-axios.js
```

#### Via Python
```bash
python3 examples/upload-file.py
```

---

## πŸ“Œ Langkah-langkah Detail

### A. Siapkan Hugging Face Token

1. Buka https://huggingface.co/settings/tokens
2. Klik "New token"
3. Beri nama: "Vico Upload"
4. Pilih tipe: "Write"
5. Salin token (format: `hf_...`)

### B. Buat Dataset di Hugging Face

1. Buka https://huggingface.co/datasets/create
2. Isi form:
   - **Name**: `my-dataset`
   - **Organization**: Pilih account Anda
   - **Visibility**: Public (atau Private)
3. Klik "Create dataset"
4. Catat ID: `username/my-dataset`

### C. Upload File

Gunakan salah satu metode di atas dengan:
- `repo_id`: ID dataset yang dibuat
- `token`: Token yang disalin
- `file`: File yang ingin diupload

### D. Cek Hasil

File akan langsung muncul di:
```
https://huggingface.co/datasets/username/my-dataset/tree/main
```

---

## πŸ”§ Konfigurasi Lanjutan

### Setup Environment Variables
```bash
cp .env.example .env
# Edit .env dan set PORT, NODE_ENV, dll
```

### Deploy dengan Docker
```bash
docker build -t vico-api .
docker run -p 3000:3000 vico-api
```

### Deploy dengan PM2
```bash
npm install -g pm2
pm2 start server.js --name "vico"
pm2 save
pm2 startup
```

---

## πŸ“ API Response Format

### βœ… Success (200)
```json
{
  "success": true,
  "message": "File berhasil di-upload ke Hugging Face",
  "data": {
    "file_name": "test.csv",
    "file_size": 123,
    "repo_id": "username/my-dataset",
    "subfolder": "root",
    "url": "https://huggingface.co/datasets/username/my-dataset/blob/main/test.csv",
    "upload_timestamp": "2024-06-24T14:35:00.000Z"
  }
}
```

### ❌ Error (400/500)
```json
{
  "success": false,
  "error": "Error message here",
  "required_fields": ["field1", "field2"]
}
```

---

## πŸ› Troubleshooting

| Error | Solusi |
|-------|--------|
| `Connection refused` | Pastikan server running (`npm start`) |
| `Token tidak valid` | Cek token di https://huggingface.co/settings/tokens |
| `Repository tidak ditemukan` | Cek format: `username/dataset-name` (lowercase) |
| `File too large` | Max 100MB, ubah di server.js jika perlu |
| `Timeout` | File besar, tingkatkan timeout di hfUploader.js |

---

## πŸ“š Contoh Lengkap

### cURL dengan file
```bash
curl -X POST http://localhost:3000/api/upload \
  -F "file=@data.json" \
  -F "repo_id=john/datasets" \
  -F "token=hf_abc123xyz" \
  -F "subfolder=raw-data"
```

### Node.js
```javascript
const FormData = require('form-data');
const axios = require('axios');
const fs = require('fs');

const form = new FormData();
form.append('file', fs.createReadStream('data.json'));
form.append('repo_id', 'john/datasets');
form.append('token', 'hf_abc123xyz');
form.append('subfolder', 'raw-data');

axios.post('http://localhost:3000/api/upload', form, {
  headers: form.getHeaders()
}).then(res => console.log(res.data));
```

### Python
```python
import requests

files = {'file': open('data.json', 'rb')}
data = {
    'repo_id': 'john/datasets',
    'token': 'hf_abc123xyz',
    'subfolder': 'raw-data'
}

r = requests.post('http://localhost:3000/api/upload', files=files, data=data)
print(r.json())
```

---

## πŸ“ž Support

Untuk bantuan lebih lanjut, lihat `README.md` untuk dokumentasi lengkap.

Happy uploading! πŸš€