magdyks commited on
Commit
36b73c7
·
verified ·
1 Parent(s): 07f3fba

Upload upload.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. upload.py +65 -0
upload.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi
2
+ import os
3
+ from pathlib import Path
4
+
5
+ def upload_to_huggingface(token_path=None):
6
+ """
7
+ Upload all files from current directory to Hugging Face repo magdyk/Qwen2-1.5B-Instruct-turbo-lora
8
+
9
+ Args:
10
+ token_path (str, optional): Path to file containing HF token. If None,
11
+ will look for token in env vars or ~/.huggingface
12
+ """
13
+ # Initialize Hugging Face API
14
+ api = HfApi()
15
+ repo_id = "magdyks/Qwen2-1.5B-Instruct-turbo-lora"
16
+
17
+ # Get token either from file or environment
18
+ if token_path:
19
+ with open(token_path) as f:
20
+ token = f.read().strip()
21
+ else:
22
+ token = os.getenv("HF_TOKEN") # Will also check ~/.huggingface
23
+
24
+ if not token:
25
+ raise ValueError("No token found. Please provide token_path or set HF_TOKEN environment variable")
26
+
27
+ # Create repo if it doesn't exist (will raise error if repo exists)
28
+ try:
29
+ api.create_repo(repo_id, private=False, token=token)
30
+ print(f"Created new repository: {repo_id}")
31
+ except Exception as e:
32
+ print(f"Repository {repo_id} already exists or error occurred: {e}")
33
+
34
+ # Get all files in current directory
35
+ current_dir = Path(".")
36
+ files_to_upload = []
37
+
38
+ # Walk through directory and collect files
39
+ for path in current_dir.rglob("*"):
40
+ if path.is_file() and not path.name.startswith("."): # Skip hidden files
41
+ files_to_upload.append(str(path))
42
+
43
+ # Upload each file
44
+ for file_path in files_to_upload:
45
+ try:
46
+ api.upload_file(
47
+ path_or_fileobj=file_path,
48
+ path_in_repo=file_path,
49
+ repo_id=repo_id,
50
+ token=token
51
+ )
52
+ print(f"Uploaded: {file_path}")
53
+ except Exception as e:
54
+ print(f"Error uploading {file_path}: {e}")
55
+
56
+ print("Upload complete!")
57
+
58
+ if __name__ == "__main__":
59
+ import argparse
60
+
61
+ parser = argparse.ArgumentParser(description='Upload files to Hugging Face')
62
+ parser.add_argument('--token-path', type=str, help='Path to file containing HF token')
63
+
64
+ args = parser.parse_args()
65
+ upload_to_huggingface(args.token_path)