#!/usr/bin/env python3 """ Script to push the entire Brain Tumor AI project to Hugging Face Includes all source code, datasets, and models """ import os import subprocess from pathlib import Path from huggingface_hub import Repository, login # Configuration HF_USERNAME = "Ujjwalathub" # Update this with your HF username REPO_NAME = "Brain-Tumor-AI" LOCAL_PATH = r"e:\Brain" HF_REPO_ID = f"{HF_USERNAME}/{REPO_NAME}" def main(): print("๐Ÿš€ Starting push to Hugging Face...") print(f"๐Ÿ“ฆ Repository: {HF_REPO_ID}") # Initialize or clone the HF repo hf_repo_url = f"https://huggingface.co/datasets/{HF_REPO_ID}" if True else f"https://huggingface.co/{HF_REPO_ID}" try: print("\n๐Ÿ“ Creating/accessing Hugging Face repository...") # Create a repo on HF using the API from huggingface_hub import create_repo try: create_repo( repo_id=REPO_NAME, repo_type="dataset", exist_ok=True, private=False ) print(f"โœ… Repository created/accessed: {REPO_NAME}") except Exception as e: print(f"โš ๏ธ Repository creation: {e}") # Clone the HF repo temp_dir = rf"{LOCAL_PATH}_hf_temp" if os.path.exists(temp_dir): import shutil shutil.rmtree(temp_dir) print(f"\n๐Ÿ“ฅ Cloning HF repository to {temp_dir}...") repo = Repository( local_dir=temp_dir, clone_from=HF_REPO_ID, repo_type="dataset", use_auth_token=True ) # Copy all files from local Brain directory to temp HF directory print(f"\n๐Ÿ“‹ Copying files from {LOCAL_PATH} to HF repository...") import shutil for item in os.listdir(LOCAL_PATH): src_path = os.path.join(LOCAL_PATH, item) dst_path = os.path.join(temp_dir, item) # Skip .git and other HF-specific folders if item in ['.git', '.gitignore', '.gitattributes', '.hf_temp', 'push_to_hf.py']: continue if os.path.isdir(src_path): if os.path.exists(dst_path): shutil.rmtree(dst_path) print(f" ๐Ÿ“ Copying directory: {item}") shutil.copytree(src_path, dst_path) else: print(f" ๐Ÿ“„ Copying file: {item}") shutil.copy2(src_path, dst_path) # Add all files to the repo print("\nโž• Adding files to repository...") repo.git_add() # Commit and push print("\n๐Ÿ’พ Committing changes...") repo.git_commit("Initial commit: Brain Tumor MRI Classifier with full dataset and models") print("\nโฌ†๏ธ Pushing to Hugging Face...") repo.git_push() print("\nโœ… Successfully pushed to Hugging Face!") print(f"๐Ÿ”— Repository URL: https://huggingface.co/datasets/{HF_REPO_ID}") # Cleanup print("\n๐Ÿงน Cleaning up temporary files...") shutil.rmtree(temp_dir) except Exception as e: print(f"\nโŒ Error: {e}") import traceback traceback.print_exc() if __name__ == "__main__": main()