Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,24 @@ from run import extract_frame, remove_subtitles
|
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
with gr.Blocks() as demo:
|
| 7 |
-
gr.Markdown("### 🎬
|
| 8 |
|
| 9 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
with gr.Column():
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
frame_output = gr.Image(label="参考帧")
|
| 15 |
-
mask_editor = gr.ImageEditor(label="框选字幕区域", type="pil")
|
| 16 |
|
| 17 |
with gr.Row():
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# 获取视频总帧数,动态更新滑块范围
|
| 21 |
def get_total_frames(video):
|
|
@@ -39,9 +45,16 @@ with gr.Blocks() as demo:
|
|
| 39 |
# 将参考帧传给编辑器
|
| 40 |
frame_output.change(lambda img: img, inputs=frame_output, outputs=mask_editor)
|
| 41 |
|
| 42 |
-
# 点击按钮执行去字幕
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
demo.launch()
|
|
|
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
with gr.Blocks() as demo:
|
| 7 |
+
gr.Markdown("### 🎬 简洁字幕去除工具(2+1 布局 + 下载 + 进度提示)")
|
| 8 |
|
| 9 |
with gr.Row():
|
| 10 |
+
# 左边:上传视频
|
| 11 |
+
video_input = gr.Video(label="上传视频", width=320, height=240)
|
| 12 |
+
|
| 13 |
+
# 右边:参考帧 + 滑块 + 框选
|
| 14 |
with gr.Column():
|
| 15 |
+
frame_slider = gr.Slider(minimum=0, maximum=200, step=1, value=10, label="选择参考帧")
|
| 16 |
+
frame_output = gr.Image(label="参考帧", width=320, height=240)
|
| 17 |
+
mask_editor = gr.ImageEditor(label="框选字幕区域", type="pil", width=320, height=240)
|
|
|
|
|
|
|
| 18 |
|
| 19 |
with gr.Row():
|
| 20 |
+
with gr.Column():
|
| 21 |
+
run_btn = gr.Button("去除字幕")
|
| 22 |
+
status = gr.Label(label="状态提示")
|
| 23 |
+
result_video = gr.Video(label="去除字幕后的视频", width=480, height=320)
|
| 24 |
+
download_file = gr.File(label="下载处理后的视频")
|
| 25 |
|
| 26 |
# 获取视频总帧数,动态更新滑块范围
|
| 27 |
def get_total_frames(video):
|
|
|
|
| 45 |
# 将参考帧传给编辑器
|
| 46 |
frame_output.change(lambda img: img, inputs=frame_output, outputs=mask_editor)
|
| 47 |
|
| 48 |
+
# 点击按钮执行去字幕,同时输出视频和下载文件,并显示进度提示
|
| 49 |
+
def process(video, mask):
|
| 50 |
+
return "处理中,请稍候…", None, None # 状态提示 + 清空旧结果
|
| 51 |
+
|
| 52 |
+
def finish(video, mask):
|
| 53 |
+
out_path = remove_subtitles(video, mask)
|
| 54 |
+
return "处理完成 ✅", out_path, out_path
|
| 55 |
+
|
| 56 |
+
run_btn.click(fn=process, inputs=[video_input, mask_editor], outputs=[status, result_video, download_file])\
|
| 57 |
+
.then(fn=finish, inputs=[video_input, mask_editor], outputs=[status, result_video, download_file])
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
demo.launch()
|