| import os |
| from huggingface_hub import HfApi, create_repo, Repository |
| from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
| |
| USERNAME = "your-username" |
| TOKEN = "hf_xxxxx" |
|
|
| REPO_ID = f"{USERNAME}/code-review-agent" |
| LOCAL_DIR = "./code-review-agent" |
|
|
| |
| try: |
| create_repo(REPO_ID, token=TOKEN, private=False, exist_ok=True) |
| print(f"Created/verified repo: {REPO_ID}") |
| except Exception as e: |
| print(e) |
|
|
| |
| if not os.path.exists(LOCAL_DIR): |
| repo = Repository(local_dir=LOCAL_DIR, clone_from=REPO_ID, use_auth_token=TOKEN) |
| else: |
| |
| repo = Repository(local_dir=LOCAL_DIR, clone_from=REPO_ID, use_auth_token=TOKEN) |
| repo.git_pull() |
|
|
| |
| print("Downloading distilgpt2 ...") |
| model = AutoModelForCausalLM.from_pretrained("distilgpt2") |
| tokenizer = AutoTokenizer.from_pretrained("distilgpt2") |
|
|
| |
| model.save_pretrained(LOCAL_DIR) |
| tokenizer.save_pretrained(LOCAL_DIR) |
|
|
| |
| readme = """--- |
| language: en |
| license: mit |
| tags: |
| - code-review |
| - agent |
| - text-generation |
| --- |
| |
| # Code Review Agent Model |
| |
| This is a small language model (distilgpt2) that can be fine‑tuned to generate helpful code review comments. |
| It is a starting point for building an AI that reviews pull requests. |
| """ |
| with open(os.path.join(LOCAL_DIR, "README.md"), "w") as f: |
| f.write(readme) |
|
|
| |
| |
| import subprocess |
| subprocess.run(["git", "lfs", "install"], cwd=LOCAL_DIR) |
| subprocess.run(["git", "lfs", "track", "*.bin", "*.safetensors"], cwd=LOCAL_DIR) |
| subprocess.run(["git", "add", ".gitattributes"], cwd=LOCAL_DIR) |
|
|
| |
| repo.git_add() |
| repo.git_commit("Initial upload of distilgpt2 model") |
| repo.git_push() |
| print("Model pushed to:", f"https://huggingface.co/{REPO_ID}") |