ArunKr commited on
Commit
0300160
·
verified ·
1 Parent(s): d9f7596

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Here’s a **minimal, working example** showing how you can create a Hugging Face model repo and upload files into it using Python.
2
+
3
+ ---
4
+
5
+ ### 1. Install dependencies
6
+
7
+ ```bash
8
+ uv pip install huggingface_hub
9
+ ```
10
+
11
+ ---
12
+
13
+ ### 2. Example Python script
14
+
15
+ ```python
16
+ from huggingface_hub import HfApi, create_repo, upload_file
17
+ import os
18
+
19
+ # 1. Authenticate (make sure HF_TOKEN is in your environment variables)
20
+ hf_token = os.getenv("HF_TOKEN")
21
+ if not hf_token:
22
+ raise EnvironmentError("Missing HF_TOKEN in environment variables.")
23
+
24
+ # 2. Define repo details
25
+ repo_name = "test-model-repo"
26
+ namespace = "your-username" # replace with your HF username/org
27
+ repo_id = f"{namespace}/{repo_name}"
28
+
29
+ # 3. Create repo (only first time, idempotent)
30
+ create_repo(repo_id, token=hf_token, repo_type="model", exist_ok=True)
31
+ print(f"✅ Repo created: https://huggingface.co/{repo_id}")
32
+
33
+ # 4. Upload files
34
+ api = HfApi()
35
+
36
+ # Example: upload a config.json file
37
+ upload_file(
38
+ path_or_fileobj="config.json", # local file path
39
+ path_in_repo="config.json", # where it will appear in repo
40
+ repo_id=repo_id,
41
+ token=hf_token
42
+ )
43
+
44
+ # Example: upload model weights
45
+ upload_file(
46
+ path_or_fileobj="pytorch_model.bin",
47
+ path_in_repo="pytorch_model.bin",
48
+ repo_id=repo_id,
49
+ token=hf_token
50
+ )
51
+
52
+ print("✅ Files uploaded successfully!")
53
+ ```
54
+
55
+ ---
56
+
57
+ ### 3. Workflow
58
+
59
+ 1. Get your token from [Hugging Face settings → Access Tokens](https://huggingface.co/settings/tokens).
60
+ 2. Save it in environment:
61
+
62
+ ```bash
63
+ export HF_TOKEN=your_token_here
64
+ ```
65
+ 3. Run the script → it will:
66
+
67
+ * Create a model repo if not exists.
68
+ * Upload your files (e.g., `config.json`, `pytorch_model.bin`).
69
+ * You’ll see them in `https://huggingface.co/your-username/test-model-repo`.
70
+
71
+ ---
72
+
73
+ 👉 Do you want me to also show an example of uploading **multiple files/folders at once** (like the whole model directory with tokenizer, config, and weights)?
74
+