import os import shutil from pathlib import Path from urllib.parse import urlparse os.system("pip install GitPython") from git import Repo token = os.getenv('GH_TOKEN') repo_url = os.getenv('REPO') REPO_URL, BRANCH_NAME = repo_url.split('@') OWNER_REPO_NAME = urlparse(REPO_URL).path.lstrip("/") REPO_DIR_NAME = Path(urlparse(REPO_URL).path).stem Repo.clone_from(f"https://{token}@github.com/{OWNER_REPO_NAME}", REPO_DIR_NAME, branch=BRANCH_NAME) for item in Path(REPO_DIR_NAME).iterdir(): shutil.copytree(item, Path.cwd() / item.name, dirs_exist_ok=True) if item.is_dir() else shutil.copy2(item, Path.cwd()) def del_error_handler(func, path, exc_info): if not os.access(path, os.W_OK): os.chmod(path, 0o600) func(path) else: raise shutil.rmtree(REPO_DIR_NAME, onerror=del_error_handler) os.system("pip install -r requirements.txt") from gradio_app import demo demo.queue(concurrency_limit=1, max_size=1).launch()