MambaVoice / app.py
Jiang Xiaolan
update
3e62f87
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()