# 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! 🚀