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_EMAIL = os.getenv("GIT_EMAIL") HF_OWNER = os.getenv("HF_OWNER") HF_TOKEN = os.getenv("HF_TOKEN") REPO_NAME = os.getenv("REPO_NAME") REPO_URL = f"https://{HF_OWNER}:{HF_TOKEN}@huggingface.co/spaces/{REPO_NAME}" # Set remote URL before pushing """Automates Git add, commit, and push for updated data.""" try: # Run Git commands subprocess.run(["git", "config", "--global", "user.name", GIT_USER], check=True) subprocess.run(["git", "config", "--global", "user.email", GIT_EMAIL], check=True) subprocess.run(["git", "remote", "set-url", "origin", REPO_URL], check=True) subprocess.run(["git", "add", "--all"], check=True) subprocess.run(["git", "commit", "-m", "Update questions data"], check=True) subprocess.run(["git", "push", "origin", "main"], check=True) print("✅ Data committed and pushed successfully!") except subprocess.CalledProcessError as e: print(f"❌ Git operation failed: {e}")