Spaces:
Runtime error
Runtime error
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']) |