Pujan Neupane commited on
Commit
0667448
·
1 Parent(s): 40c51f0

feat: added script of for downloading the model and readme.md to tell how to use it

Browse files
Files changed (2) hide show
  1. HuggingFace/main.py +24 -0
  2. HuggingFace/readme.md +51 -3
HuggingFace/main.py CHANGED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import Repository
3
+
4
+
5
+ def download_repo():
6
+ hf_token = os.getenv("HF_TOKEN")
7
+ if not hf_token:
8
+ raise ValueError("HF_TOKEN not found in environment variables.")
9
+
10
+ # Set the repository ID (replace with your own Hugging Face repo name)
11
+ repo_id = "Pujan-Dev/test" # Replace with your repo
12
+
13
+ # Specify the local directory where you want to save the repo
14
+ local_dir = "./Ai-Text-Detector2"
15
+
16
+ # Clone the entire repository to the local directory
17
+ repo = Repository(local_dir, clone_from=repo_id, token=hf_token)
18
+
19
+ # No need for download() method, it's cloned directly
20
+ print(f"✅ Repository downloaded to: {local_dir}")
21
+
22
+
23
+ if __name__ == "__main__":
24
+ download_repo()
HuggingFace/readme.md CHANGED
@@ -1,4 +1,52 @@
1
- ### Hugging face cli
2
 
3
- in this main.py file we have commands to upload the model to the hugging face as well as download it into the local system
4
- it is an cli based tool for this
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Hugging Face CLI Tool
2
 
3
+ This CLI tool allows you to **upload** and **download** models from Hugging Face repositories. It requires an **Hugging Face Access Token (`HF_TOKEN`)** for authentication, especially for private repositories.
4
+
5
+ ### Prerequisites
6
+
7
+ 1. **Install Hugging Face Hub**:
8
+
9
+ ```bash
10
+ pip install huggingface_hub
11
+ ```
12
+
13
+ 2. **Get HF_TOKEN**:
14
+ - Log in to [Hugging Face](https://huggingface.co/).
15
+ - Go to **Settings** → **Access Tokens** → **Create a new token** with `read` and `write` permissions.
16
+ - Save the token.
17
+
18
+ ### Usage
19
+
20
+ 1. **Set the Token**:
21
+
22
+ - **Linux/macOS**:
23
+ ```bash
24
+ export HF_TOKEN=your_token_here
25
+ ```
26
+ - **Windows (CMD)**:
27
+ ```bash
28
+ set HF_TOKEN=your_token_here
29
+ ```
30
+
31
+ 2. **Download Model**:
32
+
33
+ ```bash
34
+ python main.py --download --repo-id <repo_name> --save-dir <local_save_path>
35
+ ```
36
+
37
+ 3. **Upload Model**:
38
+ ```bash
39
+ python main.py --upload --repo-id <repo_name> --model-path <local_model_path>
40
+ ```
41
+
42
+ ### Example
43
+
44
+ To download a model:
45
+
46
+ ```bash
47
+ python main.py
48
+ ```
49
+
50
+ ### Authentication
51
+
52
+ Ensure you set `HF_TOKEN` to access private repositories. If not set, the script will raise an error.