malorieiovino commited on
Commit
e0b4ef5
·
verified ·
1 Parent(s): 51b91ea

Upload upload_to_huggingface.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. upload_to_huggingface.py +50 -0
upload_to_huggingface.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi
2
+ import os
3
+ import zipfile
4
+
5
+ def upload_models():
6
+ # Configure these variables
7
+ HUGGING_FACE_USERNAME = 'malorieiovino' # Your Hugging Face username
8
+ REPO_NAME = f'{HUGGING_FACE_USERNAME}/TruthLens'
9
+
10
+ # Path to your models directory
11
+ LOCAL_MODEL_PATH = os.path.expanduser('~/Desktop/TruthLens/TruthLens/models')
12
+
13
+ try:
14
+ # Initialize Hugging Face API
15
+ api = HfApi()
16
+
17
+ # Create repository (if not exists)
18
+ api.create_repo(repo_id=REPO_NAME, exist_ok=True)
19
+
20
+ # List all files in the directory
21
+ print("Files in the directory:")
22
+ print(os.listdir(LOCAL_MODEL_PATH))
23
+
24
+ # Upload model files directly
25
+ for filename in os.listdir(LOCAL_MODEL_PATH):
26
+ file_path = os.path.join(LOCAL_MODEL_PATH, filename)
27
+
28
+ # Skip if it's a directory
29
+ if os.path.isdir(file_path):
30
+ print(f"Skipping directory: {filename}")
31
+ continue
32
+
33
+ try:
34
+ api.upload_file(
35
+ path_or_fileobj=file_path,
36
+ path_in_repo=filename,
37
+ repo_id=REPO_NAME,
38
+ repo_type='model'
39
+ )
40
+ print(f"Uploaded {filename}")
41
+ except Exception as upload_error:
42
+ print(f"Error uploading {filename}: {upload_error}")
43
+
44
+ print(f"Completed upload to {REPO_NAME}")
45
+
46
+ except Exception as e:
47
+ print(f"An error occurred: {e}")
48
+
49
+ if __name__ == '__main__':
50
+ upload_models()