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 | #!/usr/bin/env python3 | |
| """ | |
| Contoh: Upload file langsung ke Hugging Face menggunakan huggingface_hub | |
| Cara jalankan: | |
| python3 examples/direct-hf-upload.py | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| from huggingface_hub import login, upload_file, upload_folder | |
| # Konfigurasi | |
| HF_TOKEN = os.getenv('HF_TOKEN', 'your_hf_token_here') | |
| REPO_ID = os.getenv('HF_REPO_ID', 'username/dataset-name') | |
| FILE_PATH = './examples/sample-data.csv' | |
| FOLDER_PATH = './examples' | |
| def upload_single_file(): | |
| """Upload single file""" | |
| print('π Direct Upload - Single File') | |
| print('=' * 50) | |
| # Validasi file | |
| if not Path(FILE_PATH).exists(): | |
| print(f'β File tidak ditemukan: {FILE_PATH}') | |
| print('π Membuat file contoh...') | |
| with open(FILE_PATH, 'w') as f: | |
| f.write('id,name,value\n') | |
| f.write('1,Alice,100\n') | |
| f.write('2,Bob,200\n') | |
| try: | |
| # Authenticate | |
| print('π Authenticating...') | |
| login(token=HF_TOKEN) | |
| # Upload file | |
| print(f'π€ Uploading {FILE_PATH}...') | |
| info = upload_file( | |
| path_or_fileobj=FILE_PATH, | |
| path_in_repo=f'u/{Path(FILE_PATH).name}', | |
| repo_id=REPO_ID, | |
| repo_type='dataset', | |
| commit_message='Upload sample data' | |
| ) | |
| print('β Upload berhasil!') | |
| print(f'π URL: https://huggingface.co/datasets/{REPO_ID}/blob/main/u/{Path(FILE_PATH).name}') | |
| print(f'π Commit: {info}') | |
| except Exception as e: | |
| print(f'β Error: {str(e)}') | |
| sys.exit(1) | |
| def upload_folder_contents(): | |
| """Upload entire folder""" | |
| print('\nπ Direct Upload - Folder') | |
| print('=' * 50) | |
| if not Path(FOLDER_PATH).exists(): | |
| print(f'β Folder tidak ditemukan: {FOLDER_PATH}') | |
| sys.exit(1) | |
| try: | |
| # Authenticate | |
| print('π Authenticating...') | |
| login(token=HF_TOKEN) | |
| # Upload folder | |
| print(f'π€ Uploading folder {FOLDER_PATH}...') | |
| info = upload_folder( | |
| folder_path=FOLDER_PATH, | |
| repo_id=REPO_ID, | |
| repo_type='dataset', | |
| path_in_repo='u/examples', | |
| commit_message='Upload examples folder' | |
| ) | |
| print('β Upload berhasil!') | |
| print(f'π URL: https://huggingface.co/datasets/{REPO_ID}/tree/main/u/examples') | |
| print(f'π Commit: {info}') | |
| except Exception as e: | |
| print(f'β Error: {str(e)}') | |
| sys.exit(1) | |
| if __name__ == '__main__': | |
| print('π Contoh Upload Langsung ke Hugging Face') | |
| print('=' * 50) | |
| print() | |
| if len(sys.argv) > 1 and sys.argv[1] == 'folder': | |
| upload_folder_contents() | |
| else: | |
| upload_single_file() | |
| print('\nπ‘ Tip: Jalankan dengan "folder" untuk upload folder') | |
| print(' python3 examples/direct-hf-upload.py folder') | |