|
import os |
|
import git |
|
import subprocess |
|
|
|
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") |
|
|
|
|
|
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__": |
|
|
|
clone_and_run() |
|
|