ouob's picture
fix: repo url
b41bf17
raw
history blame
1.12 kB
import os
import git
import subprocess
# from python-dotenv import load_dotenv
from git.exc import GitCommandError
def clone_and_run():
# 設定環境變數中的倉庫地址和憑證
user = os.getenv('HF_USER')
repo_url = os.getenv('HF_REPO_URL')
access_token = os.getenv('HF_ACCESS_TOKEN')
if not repo_url or not access_token:
raise EnvironmentError("請設定環境變數中的 HUGGING_FACE_REPO_URL 和 HUGGING_FACE_ACCESS_TOKEN")
# 構建帶有憑證的 URL
auth_repo_url = repo_url.replace('https://', f'https://{user}:{access_token}@')
try:
# 克隆倉庫
git.Repo.clone_from(auth_repo_url, 'repo', branch='main')
print("倉庫克隆成功!")
os.chdir(os.path.join(os.getcwd(), 'repo'))
subprocess.run(["python", "app.py"], check=True)
print("app.py 運行成功!")
except GitCommandError as e:
print(f"克隆倉庫時出錯:{e}")
except subprocess.CalledProcessError as e:
print(f"運行 app.py 時出錯:{e}")
if __name__ == "__main__":
# load_dotenv()
clone_and_run()