Last active
March 22, 2025 18:08
-
-
Save fakerybakery/4d6bf6b0377f594cf0abedd3f9d73e5a to your computer and use it in GitHub Desktop.
HF Zipper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
import tempfile | |
import click | |
import subprocess | |
from huggingface_hub import snapshot_download | |
@click.command() | |
@click.argument('repo_id') | |
@click.argument('zip_path') | |
@click.option('--type', type=click.Choice(['model', 'dataset', 'space']), default='model', help='Type of Hugging Face repo') | |
def create_zip_from_repo(repo_id, zip_path, type): | |
"""Download a Hugging Face repo and zip it using a fast compression tool.""" | |
try: | |
# Create a temporary directory | |
with tempfile.TemporaryDirectory() as temp_dir: | |
click.echo(f"Downloading {type} repo: {repo_id}...") | |
repo_dir = snapshot_download(repo_id=repo_id, repo_type=type, local_dir=temp_dir, local_dir_use_symlinks=False) | |
click.echo(f"Creating zip file: {zip_path} using a fast compression tool...") | |
subprocess.run(['zip', '-r', zip_path, '.'], cwd=repo_dir, check=True) | |
click.echo("Zip file created successfully.") | |
except subprocess.CalledProcessError as e: | |
click.echo(f"Compression error: {e}") | |
except Exception as e: | |
click.echo(f"Error: {e}") | |
if __name__ == '__main__': | |
create_zip_from_repo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment