Skip to content

Instantly share code, notes, and snippets.

@pcuenca
Created January 3, 2024 20:28
Show Gist options
  • Save pcuenca/4f4839325e799183bc6b81c668a24161 to your computer and use it in GitHub Desktop.
Save pcuenca/4f4839325e799183bc6b81c668a24161 to your computer and use it in GitHub Desktop.
Upload with model card
def upload_to_hub(path: str, name: str, hf_path: str):
import os
from huggingface_hub import HfApi, logging, ModelCard
repo_id = f"mlx-community/{name}"
card = ModelCard.load(hf_path)
card.data.tags = ["mlx"] if card.data.tags is None else card.data.tags + ["mlx"]
card.text = f"""
# {name}
This model was converted to MLX format from [`{hf_path}`]().
Please, refer to the [original model card](https://huggingface.co/{hf_path}) for more details on the original model.
## Use with mlx
```bash
pip install mlx
git clone https://github.com/ml-explore/mlx-examples.git
cd mlx-examples/llms/hf_llm
python generate.py --model {repo_id} --prompt "My name is"
```
"""
card.save(os.path.join(path, "README.md"))
logging.set_verbosity_info()
api = HfApi()
api.create_repo(repo_id=repo_id, exist_ok=True)
api.upload_folder(
folder_path=path,
repo_id=repo_id,
repo_type="model",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment