4cko
/usr/local/rvm/gems/ruby-3.4.7/bin:/usr/local/rvm/gems/ruby-3.4.7@global/bin:/usr/local/rvm/rubies/ruby-3.4.7/bin:/home/codespace/.vscode-remote/data/User/globalStorage/github.copilot-chat/debugCommand:/home/codespace/.vscode-remote/data/User/globalStorage/github.copilot-chat/copilotCli:/vscode/bin/linux-x64/7e7950df89d055b5a378379db9ee14290772148a/bin/remote-cli:/home/codespace/.local/bin:/home/codespace/.dotnet:/home/codespace/nvm/current/bin:/home/codespace/.php/current/bin:/home/codespace/.python/current/bin:/home/codespace/java/current/bin:/home/codespace/.ruby/current/bin:/home/codespace/.local/bin:/usr/local/python/current/bin:/usr/local/py-utils/bin:/usr/local/jupyter:/usr/local/oryx:/usr/local/go/bin:/go/bin:/usr/local/sdkman/bin:/usr/local/sdkman/candidates/java/current/bin:/usr/local/sdkman/candidates/gradle/current/bin:/usr/local/sdkman/candidates/maven/current/bin:/usr/local/sdkman/candidates/ant/current/bin:/usr/local/rvm/gems/default/bin:/usr/local/rvm/gems/default@global/bin:/usr/local/rvm/rubies/default/bin:/usr/local/share/rbenv/bin:/usr/local/php/current/bin:/opt/conda/bin:/usr/local/nvs:/usr/local/share/nvm/versions/node/v24.14.0/bin:/usr/local/hugo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/share/dotnet:/home/codespace/.dotnet/tools:/usr/local/rvm/bin
a25386c | # 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! π | |