# Mount Google Drive (Optional) | |
from google.colab import drive | |
drive.mount('/content/drive') | |
# Define path to your project | |
repo_path = "/content/your-project" | |
#repo_path = "/content/drive/MyDrive/your-project" | |
import os | |
# Clone the repo | |
if not os.path.exists(repo_path): | |
!git clone https://huggingface.co/spaces/<your_username>/<your_repo_name> {repo_path} | |
else: | |
print("Project already in Drive") | |
os.chdir(repo_path) | |
os.chdir(repo_path) | |
# Setup Git | |
!git config --global user.email "your-email@example.com" | |
!git config --global user.name "Your Username" | |
# Add all the changes | |
!git add . | |
# Commit | |
!git commit -m "Updating code in Colab" | |
# Push changes | |
!git push origin main | |
# Alternative way to push with huggingface hub: | |
# from huggingface_hub import HfApi | |
# from huggingface_hub import login | |
# login() # this will prompt you to write your API token | |
# api = HfApi() | |
# api.upload_folder( | |
# repo_id="<your_username>/<your_repo_name>", | |
# folder_path=repo_path, | |
# ) |