OzoneAsai commited on
Commit
0e63074
·
verified ·
1 Parent(s): 7bedc30

Upload upl.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. upl.py +8 -23
upl.py CHANGED
@@ -1,31 +1,20 @@
1
- from huggingface_hub import HfApi, HfFolder
2
  import os
 
3
 
4
  def upload_to_hf_space(repo_id, folder_path, token=None):
5
- """
6
- Uploads files from a local folder to a Hugging Face Space.
7
-
8
- Args:
9
- repo_id (str): The Hugging Face Space repository ID (e.g., "username/space_name").
10
- folder_path (str): The local folder path to upload.
11
- token (str, optional): Your Hugging Face API token. Defaults to the token in HfFolder.
12
-
13
- Returns:
14
- None
15
- """
16
  api = HfApi()
17
  token = token or HfFolder.get_token()
18
 
19
  if not token:
20
- raise ValueError("Hugging Face token is not found. Log in or provide a token.")
21
 
22
- # List all files in the folder
23
- for root, dirs, files in os.walk(folder_path):
24
  for file in files:
 
 
25
  local_path = os.path.join(root, file)
26
  remote_path = os.path.relpath(local_path, folder_path)
27
 
28
- # Upload each file
29
  print(f"Uploading {local_path} to {repo_id}/{remote_path}...")
30
  api.upload_file(
31
  path_or_fileobj=local_path,
@@ -34,12 +23,8 @@ def upload_to_hf_space(repo_id, folder_path, token=None):
34
  repo_type="space",
35
  token=token
36
  )
37
- print("Upload completed successfully!")
38
-
39
- # Replace these with your actual values
40
- repo_id = "OzoneAsai/CnJaFlashC-1" # e.g., "your_username/your_space"
41
- folder_path = "./" # Path to the folder you want to upload
42
- token = os.getenv("HF_Token") # Optional: Provide your Hugging Face token here
43
 
44
- # Call the function to upload
 
 
45
  upload_to_hf_space(repo_id, folder_path, token)
 
 
1
  import os
2
+ from huggingface_hub import HfApi, HfFolder
3
 
4
  def upload_to_hf_space(repo_id, folder_path, token=None):
 
 
 
 
 
 
 
 
 
 
 
5
  api = HfApi()
6
  token = token or HfFolder.get_token()
7
 
8
  if not token:
9
+ raise ValueError("Hugging Face token is not found.")
10
 
11
+ for root, _, files in os.walk(folder_path):
 
12
  for file in files:
13
+ if file.startswith(".git") or file.startswith(".DS_Store"):
14
+ continue # Skip unnecessary files
15
  local_path = os.path.join(root, file)
16
  remote_path = os.path.relpath(local_path, folder_path)
17
 
 
18
  print(f"Uploading {local_path} to {repo_id}/{remote_path}...")
19
  api.upload_file(
20
  path_or_fileobj=local_path,
 
23
  repo_type="space",
24
  token=token
25
  )
 
 
 
 
 
 
26
 
27
+ repo_id = "OzoneAsai/CnJaFlashC-1"
28
+ folder_path = "./"
29
+ token = os.getenv("HF_Token") # Ensure this environment variable is set
30
  upload_to_hf_space(repo_id, folder_path, token)