bpiyush commited on
Commit
41ce9e0
1 Parent(s): c5f65a4

Upload upload_to_hub.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. upload_to_hub.py +33 -0
upload_to_hub.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Uploads files/folders to HF hub for use with Spaces."""
2
+ import os
3
+
4
+ from huggingface_hub import Repository, HfApi
5
+
6
+
7
+ api = HfApi()
8
+
9
+ repo_id = "bpiyush/SoundOfWater"
10
+ repo_type = "space"
11
+
12
+ upload_file = "upload_to_hub.py"
13
+ if upload_file is not None:
14
+ print("Uploading file: ", upload_file)
15
+ assert isinstance(upload_file, str), "Please provide a valid file path."
16
+ api.upload_file(
17
+ path_or_fileobj=f"./{upload_file}",
18
+ path_in_repo=upload_file,
19
+ repo_id=repo_id,
20
+ repo_type=repo_type,
21
+ )
22
+
23
+
24
+ upload_folder = None
25
+ if upload_folder is not None:
26
+ print("Uploading folder: ", upload_folder)
27
+ assert isinstance(upload_folder, str), "Please provide a valid folder path."
28
+ api.upload_folder(
29
+ folder_path=f"./{upload_folder}",
30
+ path_in_repo=upload_folder,
31
+ repo_id=repo_id,
32
+ repo_type=repo_type,
33
+ )