ouob commited on
Commit
b41bf17
·
1 Parent(s): ded9ede

fix: repo url

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import git
3
+ import subprocess
4
+ # from python-dotenv import load_dotenv
5
+ from git.exc import GitCommandError
6
+
7
+
8
+ def clone_and_run():
9
+ # 設定環境變數中的倉庫地址和憑證
10
+ user = os.getenv('HF_USER')
11
+ repo_url = os.getenv('HF_REPO_URL')
12
+ access_token = os.getenv('HF_ACCESS_TOKEN')
13
+
14
+ if not repo_url or not access_token:
15
+ raise EnvironmentError("請設定環境變數中的 HUGGING_FACE_REPO_URL 和 HUGGING_FACE_ACCESS_TOKEN")
16
+
17
+ # 構建帶有憑證的 URL
18
+ auth_repo_url = repo_url.replace('https://', f'https://{user}:{access_token}@')
19
+
20
+ try:
21
+ # 克隆倉庫
22
+ git.Repo.clone_from(auth_repo_url, 'repo', branch='main')
23
+ print("倉庫克隆成功!")
24
+
25
+ os.chdir(os.path.join(os.getcwd(), 'repo'))
26
+ subprocess.run(["python", "app.py"], check=True)
27
+
28
+ print("app.py 運行成功!")
29
+
30
+ except GitCommandError as e:
31
+ print(f"克隆倉庫時出錯:{e}")
32
+ except subprocess.CalledProcessError as e:
33
+ print(f"運行 app.py 時出錯:{e}")
34
+
35
+ if __name__ == "__main__":
36
+ # load_dotenv()
37
+ clone_and_run()