File size: 1,154 Bytes
ad08399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def commit_and_push_changes():
    import os
    import subprocess
    from pathlib import Path

    # Define the paths
    REPO_DIR = Path(".")  # Root directory of your Hugging Face Space repo
    DATA_DIR = REPO_DIR / "data/questions"  # Persistent storage in the repo
    JSONL_FILE = REPO_DIR / "output.jsonl"

    DATA_DIR.mkdir(parents=True, exist_ok=True)  # Ensure directory exists

    GIT_USER = os.getenv("GIT_USER")
    GIT_TOKEN = os.getenv("GIT_TOKEN")
    REPO_URL = f"https://{GIT_USER}:{GIT_TOKEN}@huggingface.co/spaces/VayuBuddy-Question-and-Answer"

    # Set remote URL before pushing
    subprocess.run(["git", "remote", "set-url", "origin", REPO_URL], check=True)

    """Automates Git add, commit, and push for updated data."""
    try:
        # Run Git commands
        subprocess.run(["git", "add", "--all"], check=True)
        subprocess.run(["git", "commit", "-m", "Update questions data"], check=True)
        subprocess.run(["git", "push"], check=True)
        
        print("βœ… Data committed and pushed successfully!")
    
    except subprocess.CalledProcessError as e:
        print(f"❌ Git operation failed: {e}")