File size: 1,405 Bytes
f5a718e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import subprocess
import os 
import sys 
import logging

# 设置日志记录器
# logging.basicConfig(level=logging.INFO)
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger(__name__)

def clone_repo():
    # 从环境变量中获取 GitHub Token
    github_token = os.getenv('GH_TOKEN')

    if github_token is None:
        logger.error("GitHub token is not set. Please set the GH_TOKEN secret in your Space settings.")
        return False
    
    # 使用 GitHub Token 进行身份验证并克隆仓库
    clone_command = f'git clone https://{github_token}@github.com/mamba-ai/voiceai.git'
    repo_dir = 'voiceai'
    if os.path.exists(repo_dir):
        logger.warning("Repository already exists.")
        return True
    else:
        logger.info("Cloning repository...")
        result = subprocess.run(clone_command, shell=True, capture_output=True, text=True)
    
    if result.returncode == 0:
        logger.warning("Repository cloned successfully.")
        repo_dir = 'invoice_agent'
        
        # 将仓库路径添加到 Python 模块搜索路径中
        sys.path.append(os.path.abspath(repo_dir))
        logger.warning(f"Adding {os.path.abspath(repo_dir)} to sys.path")
        return True
    else:
        logger.error(f"Failed to clone repository: {result.stderr}")
        return False


if clone_repo():
    subprocess.run(['python', 'voiceai/main.py'])