# Upload and commit your model into huggingface hub

**URL:** <https://discuss.huggingface.co/t/upload-and-commit-your-model-into-huggingface-hub/136548>\
**Category:** Beginners\
**Created:** [January 20, 2025, 2:46pm UTC](https://discuss.huggingface.co/t/upload-and-commit-your-model-into-huggingface-hub/136548 "2025-01-20T14:46:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alanturner2](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/alanturner2/32/37542_2.png) [@Alanturner2](https://discuss.huggingface.co/u/Alanturner2)\
**Post date:** [January 20, 2025, 2:46pm UTC](https://discuss.huggingface.co/t/upload-and-commit-your-model-into-huggingface-hub/136548/1 "2025-01-20T14:46:28Z")

</div>

Hello!  
I am going to give you one tip to train your model and upload the huggingface hub.  
I think this is very useful to upload the model from online coding sites([kaggle.com](http://kaggle.com), colab and so on) without downloading your local.  
Maybe some others have known this method, but I want to hope my code will be helpful to beginners.

```auto
from huggingface_hub import login
login(token="Your hf token")
tokenizer.save_pretrained("./your path")

from huggingface_hub import HfApi, upload_folder, create_repo

# Replace with your Hugging Face access token and desired model name
hf_token = "Your hf token"
repo_name = "Your repository"

# Step 1: Create a repository on the Hub. If you have the repo don't run this code
create_repo(repo_name, token=hf_token)

# Step 2: Upload the folder to the repository
upload_folder(
    folder_path="./outputmodel", # Path to the model folder
    repo_id=repo_name, # Name of the repository
    token=hf_token, # Your Hugging Face token
    commit_message="Initial model upload",
)

```

I hope your tips about my method.
