File size: 3,088 Bytes
ae466a1
73e28bf
 
 
ae466a1
 
 
73e28bf
 
ae466a1
 
73e28bf
 
 
ae466a1
73e28bf
 
 
 
 
851026b
 
73e28bf
 
 
 
 
 
 
 
 
 
 
 
851026b
73e28bf
 
 
 
 
 
 
 
ae466a1
 
73e28bf
 
 
 
 
3e62f87
73e28bf
 
 
 
 
 
 
 
 
 
ae466a1
73e28bf
3e62f87
73e28bf
 
 
 
 
 
 
 
 
 
ae466a1
73e28bf
 
ae466a1
73e28bf
567c6df
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import logging 
import sys
import subprocess
import gradio as gr


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/transcribe_agent.git'
    repo_dir = 'transcribe_agent'
    if os.path.exists(repo_dir):
        logger.warning("Repository already exists.")
        # 将仓库路径添加到 Python 模块搜索路径中
        # logger.warning(f"Adding {os.path.abspath(repo_dir)} to sys.path")
        # sys.path.append(os.path.abspath(repo_dir))
        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 = 'transcribe_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():
    # 克隆成功后导入模块    
    import transcribe_agent.agent as ta
    demo = gr.Blocks()
    mf_transcribe = gr.Interface(
        fn=ta.transcribe_v2,
        inputs=[
            gr.Audio(sources=["microphone"], type="filepath"),
        ],
        outputs=["text"],
        # layout="horizontal",
        theme="huggingface",
        title=f"オーディオをMambaVoice-v1で文字起こしする",
        description=f"ボタンをクリックするだけで、長時間のマイク入力やオーディオ入力を文字起こしできます!デモではMambaVoice-v1モデルを使用しており、任意の長さの音声ファイルを文字起こしすることができます。",
        allow_flagging="never",
    )

    file_transcribe = gr.Interface(
        fn=ta.transcribe_v2,
        inputs=[
            gr.Audio(sources=["upload"], type="filepath", label="Audio file"),
        ],
        outputs=["text"],
        # layout="horizontal",
        theme="huggingface",
        title=f"オーディオをMambaVoice-v1で文字起こしする",
        description=f"ボタンをクリックするだけで、長時間のマイク入力やオーディオ入力を文字起こしできます!デモではMambaVoice-v1モデルを使用しており、任意の長さの音声ファイルを文字起こしすることができます。",
        allow_flagging="never",
    )

    with demo:
        gr.TabbedInterface([mf_transcribe, file_transcribe], ["Microphone", "Audio file"])

    demo.queue(max_size=10)
    demo.launch()