|
from huggingface_hub import HfApi |
|
import os |
|
from pathlib import Path |
|
|
|
def upload_to_huggingface(token_path=None): |
|
""" |
|
Upload all files from current directory to Hugging Face repo magdyk/Qwen2-1.5B-Instruct-turbo-lora |
|
|
|
Args: |
|
token_path (str, optional): Path to file containing HF token. If None, |
|
will look for token in env vars or ~/.huggingface |
|
""" |
|
|
|
api = HfApi() |
|
repo_id = "magdyks/Qwen2-1.5B-Instruct-turbo-lora" |
|
|
|
|
|
if token_path: |
|
with open(token_path) as f: |
|
token = f.read().strip() |
|
else: |
|
token = os.getenv("HF_TOKEN") |
|
|
|
if not token: |
|
raise ValueError("No token found. Please provide token_path or set HF_TOKEN environment variable") |
|
|
|
|
|
try: |
|
api.create_repo(repo_id, private=False, token=token) |
|
print(f"Created new repository: {repo_id}") |
|
except Exception as e: |
|
print(f"Repository {repo_id} already exists or error occurred: {e}") |
|
|
|
|
|
current_dir = Path(".") |
|
files_to_upload = [] |
|
|
|
|
|
for path in current_dir.rglob("*"): |
|
if path.is_file() and not path.name.startswith("."): |
|
files_to_upload.append(str(path)) |
|
|
|
|
|
for file_path in files_to_upload: |
|
try: |
|
api.upload_file( |
|
path_or_fileobj=file_path, |
|
path_in_repo=file_path, |
|
repo_id=repo_id, |
|
token=token |
|
) |
|
print(f"Uploaded: {file_path}") |
|
except Exception as e: |
|
print(f"Error uploading {file_path}: {e}") |
|
|
|
print("Upload complete!") |
|
|
|
if __name__ == "__main__": |
|
import argparse |
|
|
|
parser = argparse.ArgumentParser(description='Upload files to Hugging Face') |
|
parser.add_argument('--token-path', type=str, help='Path to file containing HF token') |
|
|
|
args = parser.parse_args() |
|
upload_to_huggingface(args.token_path) |
|
|