Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from run import extract_frame, remove_subtitles
|
| 4 |
-
import cv2
|
| 5 |
|
| 6 |
with gr.Blocks() as demo:
|
| 7 |
-
gr.Markdown("### 🎬 三视图字幕去除工具(
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
frame_output = gr.Image(label="参考帧")
|
| 15 |
-
mask_editor = gr.ImageEditor(label="框选字幕区域", type="pil")
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def get_frame(video, frame_idx):
|
| 21 |
-
frame = extract_frame(video, frame_idx)
|
| 22 |
return Image.fromarray(frame) if frame is not None else None
|
| 23 |
|
| 24 |
-
video_input.change(fn=
|
| 25 |
-
frame_slider.change(fn=get_frame, inputs=[video_input, frame_slider], outputs=frame_output)
|
| 26 |
frame_output.change(lambda img: img, inputs=frame_output, outputs=mask_editor)
|
| 27 |
|
| 28 |
run_btn = gr.Button("去除字幕")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from run import extract_frame, remove_subtitles
|
|
|
|
| 4 |
|
| 5 |
with gr.Blocks() as demo:
|
| 6 |
+
gr.Markdown("### 🎬 三视图字幕去除工具(2+1 布局)")
|
| 7 |
|
| 8 |
+
with gr.Row():
|
| 9 |
+
with gr.Column():
|
| 10 |
+
video_input = gr.Video(label="上传视频")
|
| 11 |
+
with gr.Column():
|
| 12 |
+
frame_output = gr.Image(label="参考帧")
|
| 13 |
+
mask_editor = gr.ImageEditor(label="框选字幕区域", type="pil")
|
| 14 |
|
| 15 |
+
with gr.Row():
|
| 16 |
+
result_video = gr.Video(label="去除字幕后的视频")
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
def get_frame(video):
|
| 19 |
+
frame = extract_frame(video, 10) # 默认取第10帧
|
|
|
|
|
|
|
|
|
|
| 20 |
return Image.fromarray(frame) if frame is not None else None
|
| 21 |
|
| 22 |
+
video_input.change(fn=get_frame, inputs=video_input, outputs=frame_output)
|
|
|
|
| 23 |
frame_output.change(lambda img: img, inputs=frame_output, outputs=mask_editor)
|
| 24 |
|
| 25 |
run_btn = gr.Button("去除字幕")
|