TruthLens / upload_to_huggingface.py
malorieiovino's picture
Upload upload_to_huggingface.py with huggingface_hub
e0b4ef5 verified
from huggingface_hub import HfApi
import os
import zipfile
def upload_models():
# Configure these variables
HUGGING_FACE_USERNAME = 'malorieiovino' # Your Hugging Face username
REPO_NAME = f'{HUGGING_FACE_USERNAME}/TruthLens'
# Path to your models directory
LOCAL_MODEL_PATH = os.path.expanduser('~/Desktop/TruthLens/TruthLens/models')
try:
# Initialize Hugging Face API
api = HfApi()
# Create repository (if not exists)
api.create_repo(repo_id=REPO_NAME, exist_ok=True)
# List all files in the directory
print("Files in the directory:")
print(os.listdir(LOCAL_MODEL_PATH))
# Upload model files directly
for filename in os.listdir(LOCAL_MODEL_PATH):
file_path = os.path.join(LOCAL_MODEL_PATH, filename)
# Skip if it's a directory
if os.path.isdir(file_path):
print(f"Skipping directory: {filename}")
continue
try:
api.upload_file(
path_or_fileobj=file_path,
path_in_repo=filename,
repo_id=REPO_NAME,
repo_type='model'
)
print(f"Uploaded {filename}")
except Exception as upload_error:
print(f"Error uploading {filename}: {upload_error}")
print(f"Completed upload to {REPO_NAME}")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == '__main__':
upload_models()