chaopro commited on
Commit
24cb15d
·
verified ·
1 Parent(s): 605854f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -22
app.py CHANGED
@@ -1,30 +1,31 @@
1
- import gradio as gr
2
- from PIL import Image, ImageDraw
3
  from run import extract_frame, remove_subtitles
4
 
5
- def get_frame(video, frame_idx):
6
- frame = extract_frame(video, frame_idx)
7
- return Image.fromarray(frame) if frame is not None else None
8
-
9
- def draw_box(image, points):
10
- if image is None or points is None or len(points) < 2:
11
- return image
12
- img = image.copy()
13
- draw = ImageDraw.Draw(img)
14
- (x1, y1), (x2, y2) = points[0], points[1]
15
- draw.rectangle([x1, y1, x2, y2], outline="red", width=3)
16
- return img, (x1, y1, x2, y2)
17
-
18
  with gr.Blocks() as demo:
 
 
 
19
  video_input = gr.Video(label="上传视频")
20
- frame_slider = gr.Slider(minimum=0, maximum=200, step=1, value=10, label="选择参考帧")
21
- frame_output = gr.Image(label="参考帧", type="pil")
22
- box_points = gr.Points(label="点击两点选择区域")
23
- preview = gr.Image(label="区域预览")
 
 
 
 
 
24
  result_video = gr.Video(label="去除字幕后的视频")
25
 
26
- frame_slider.change(fn=get_frame, inputs=[video_input, frame_slider], outputs=frame_output)
27
- box_points.change(fn=draw_box, inputs=[frame_output, box_points], outputs=[preview, gr.State()])
 
 
 
28
 
29
  run_btn = gr.Button("去除字幕")
30
- run_btn.click(fn=remove_subtitles, inputs=[video_input, gr.State()], outputs=result_video)
 
 
 
 
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("### 🎬 三视图字幕去除工具")
7
+
8
+ # 1. 上传视频
9
  video_input = gr.Video(label="上传视频")
10
+
11
+ # 2. 展示参考帧 + 输入矩形区域
12
+ frame_output = gr.Image(label="参考帧")
13
+ x1 = gr.Number(label="左上角 X")
14
+ y1 = gr.Number(label="左上角 Y")
15
+ x2 = gr.Number(label="右下角 X")
16
+ y2 = gr.Number(label="右下角 Y")
17
+
18
+ # 3. 输出视频
19
  result_video = gr.Video(label="去除字幕后的视频")
20
 
21
+ def get_frame(video):
22
+ frame = extract_frame(video, 10) # 默认取第10帧
23
+ return Image.fromarray(frame) if frame is not None else None
24
+
25
+ video_input.change(fn=get_frame, inputs=video_input, outputs=frame_output)
26
 
27
  run_btn = gr.Button("去除字幕")
28
+ run_btn.click(fn=remove_subtitles, inputs=[video_input, x1, y1, x2, y2], outputs=result_video)
29
+
30
+ if __name__ == "__main__":
31
+ demo.launch()