Jiang Xiaolan commited on
Commit
f5a718e
1 Parent(s): 237432a
Files changed (1) hide show
  1. app.py +43 -0
app.py CHANGED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import os
3
+ import sys
4
+ import logging
5
+
6
+ # 设置日志记录器
7
+ # logging.basicConfig(level=logging.INFO)
8
+ logging.basicConfig(level=logging.ERROR)
9
+ logger = logging.getLogger(__name__)
10
+
11
+ def clone_repo():
12
+ # 从环境变量中获取 GitHub Token
13
+ github_token = os.getenv('GH_TOKEN')
14
+
15
+ if github_token is None:
16
+ logger.error("GitHub token is not set. Please set the GH_TOKEN secret in your Space settings.")
17
+ return False
18
+
19
+ # 使用 GitHub Token 进行身份验证并克隆仓库
20
+ clone_command = f'git clone https://{github_token}@github.com/mamba-ai/voiceai.git'
21
+ repo_dir = 'voiceai'
22
+ if os.path.exists(repo_dir):
23
+ logger.warning("Repository already exists.")
24
+ return True
25
+ else:
26
+ logger.info("Cloning repository...")
27
+ result = subprocess.run(clone_command, shell=True, capture_output=True, text=True)
28
+
29
+ if result.returncode == 0:
30
+ logger.warning("Repository cloned successfully.")
31
+ repo_dir = 'invoice_agent'
32
+
33
+ # 将仓库路径添加到 Python 模块搜索路径中
34
+ sys.path.append(os.path.abspath(repo_dir))
35
+ logger.warning(f"Adding {os.path.abspath(repo_dir)} to sys.path")
36
+ return True
37
+ else:
38
+ logger.error(f"Failed to clone repository: {result.stderr}")
39
+ return False
40
+
41
+
42
+ if clone_repo():
43
+ subprocess.run(['python', 'voiceai/main.py'])