Spaces:
Runtime error
Runtime error
File size: 4,789 Bytes
cb0791d |
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
import argparse
import os
import gradio as gr
from utils import movie2audio,make_srt,make_tran,merge_sub,make_tran_zh2en,make_tran_ja2zh,make_tran_ko2zh
initial_md = """
作者:刘悦的技术博客 https://space.bilibili.com/3031494
"""
def do_speech(video):
res = movie2audio(video)
return res
def do_trans_video(model_type,video_path):
srt_text = make_srt(video_path,model_type)
return srt_text
def do_trans_audio(model_type):
srt_text = make_srt('./audio.wav',model_type)
return srt_text
def do_trans_en2zh(srt_path):
return make_tran(srt_path)
def do_trans_zh2en(srt_path):
return make_tran_zh2en(srt_path)
def do_trans_ja2zh(srt_path):
return make_tran_ja2zh(srt_path)
def do_trans_ko2zh(srt_path):
return make_tran_ko2zh(srt_path)
def do_srt_sin(video_path):
return merge_sub(video_path,"./video.srt")
def do_srt_two(video_path):
return merge_sub(video_path,"./two.srt")
with gr.Blocks() as app:
gr.Markdown(initial_md)
with gr.Accordion("视频处理(Video)"):
with gr.Row():
ori_video = gr.Textbox(label="请输入视频的路径地址,如:d:/123.mp4")
speech_button = gr.Button("提取人声(如果视频没有背景音也可以不做)Extract human voice (you don't have to do it if the video has no background sound)")
speech_audio = gr.Audio(label="提取的人声(Extract voice)")
speech_button.click(do_speech,inputs=[ori_video],outputs=[speech_audio])
with gr.Accordion("转写字幕"):
with gr.Row():
with gr.Column():
# model_type = gr.Dropdown(choices=["small","medium","large-v3","large-v2"], value="small", label="选择faster_Whisper模型/Select faster_Whisper model",interactive=True)
model_type = gr.Textbox(label="填写faster_Whisper模型/Fill in the faster_Whisper model,也可以填写small,medium,large,large-v2,large-v3,模型越大,速度越慢,但字幕的准确度越高,酌情填写,用文本框是因为你可以填写其他huggingface上的开源模型地址",value="medium")
transcribe_button_whisper = gr.Button("视频直接转写字幕(Video direct rewriting subtitles)")
transcribe_button_audio = gr.Button("提取人声转写字幕(Extract voice transliteration subtitles)")
result1 = gr.Textbox(label="字幕結果(会在项目目录生成video.srt/video.srt is generated in the current directory)")
transcribe_button_whisper.click(do_trans_video,inputs=[model_type,ori_video],outputs=[result1])
transcribe_button_audio.click(do_trans_audio,inputs=[model_type],outputs=[result1])
with gr.Accordion("字幕翻译"):
with gr.Row():
srt_path = gr.Textbox(label="原始字幕地址,默认为项目目录中的video.srt,也可以输入其他路径",value="./video.srt")
trans_button_en2zh = gr.Button("翻译英语字幕为中文/Translate English subtitles into Chinese")
trans_button_zh2en = gr.Button("翻译中文字幕为英文/Translate Chinese subtitles into English")
trans_button_ja2zh = gr.Button("翻译日文字幕为中文/Translate Japanese subtitles into Chinese")
trans_button_ko2zh = gr.Button("翻译韩文字幕为中文/Translate Korea subtitles into Chinese")
result2 = gr.Textbox(label="翻译结果(会在项目目录生成two.srt/two.srt is generated in the current directory)")
trans_button_en2zh.click(do_trans_en2zh,[srt_path],outputs=[result2])
trans_button_zh2en.click(do_trans_zh2en,[srt_path],outputs=[result2])
trans_button_ja2zh.click(do_trans_ja2zh,[srt_path],outputs=[result2])
trans_button_ko2zh.click(do_trans_ko2zh,[srt_path],outputs=[result2])
with gr.Accordion("字幕合并"):
with gr.Row():
srt_button_sin = gr.Button("将单语字幕合并到视频/Merge monolingual subtitles into video")
srt_button_two = gr.Button("将双语字幕合并到视频/Merge bilingual subtitles into video")
result3 = gr.Textbox(label="合成字幕后的视频路径地址")
srt_button_sin.click(do_srt_sin,inputs=[ori_video],outputs=[result3])
srt_button_two.click(do_srt_two,inputs=[ori_video],outputs=[result3])
parser = argparse.ArgumentParser()
parser.add_argument(
"--server-name",
type=str,
default=None,
help="Server name for Gradio app",
)
parser.add_argument(
"--no-autolaunch",
action="store_true",
default=False,
help="Do not launch app automatically",
)
args = parser.parse_args()
app.launch(inbrowser=not args.no_autolaunch, server_name=args.server_name)
|