1#!/usr/bin/env python3
2
3from huggingface_hub import HfApi
4import argparse
5import os
6
7def upload_gguf_file(local_file_path, repo_id, filename_in_repo=None):
8 """
9 Upload a GGUF file to a Hugging Face model repository
10
11 Args:
12 local_file_path: Path to your local GGUF file
13 repo_id: Your repository ID (e.g., "username/model-name")
14 filename_in_repo: Optional custom name for the file in the repo
15 """
16
17 if not os.path.exists(local_file_path):
18 print(f"โ File not found: {local_file_path}")
19 return False
20
21 if filename_in_repo is None:
22 filename_in_repo = os.path.basename(local_file_path)
23
24 if filename_in_repo is None or filename_in_repo == "":
25 filename_in_repo = os.path.basename(local_file_path)
26
27 print(f"๐ค Uploading {local_file_path} to {repo_id}/{filename_in_repo}")
28
29 api = HfApi()
30
31 try:
32 api.upload_file(
33 path_or_fileobj=local_file_path,
34 path_in_repo=filename_in_repo,
35 repo_id=repo_id,
36 repo_type="model",
37 commit_message=f"Upload {filename_in_repo}"
38 )
39
40 print("โ
Upload successful!")
41 print(f"๐ File available at: https://huggingface.co/{repo_id}/blob/main/{filename_in_repo}")
42 return True
43
44 except Exception as e:
45 print(f"โ Upload failed: {e}")
46 return False
47
48# This script requires that the environment variable HF_TOKEN is set with your
49# Hugging Face API token.
50api = HfApi()
51
52parser = argparse.ArgumentParser(description='Upload a GGUF model to a Huggingface model repository')
53parser.add_argument('--gguf-model-path', '-m', help='The GGUF model file to upload', required=True)
54parser.add_argument('--repo-id', '-r', help='The repository to upload to', required=True)
55parser.add_argument('--name', '-o', help='The name in the model repository', required=False)
56args = parser.parse_args()
57
58upload_gguf_file(args.gguf_model_path, args.repo_id, args.name)