mu-ct commited on
Commit
86fd5b0
1 Parent(s): a5b8b59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -17
app.py CHANGED
@@ -9,24 +9,15 @@ from scenedetect.detectors import ContentDetector
9
 
10
  from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
11
 
12
- # —————————————————————————————————————————————————
13
-
14
- title = "Scene Edit Detection"
15
- description = "<p style='text-align: center'>Copy of @fffiloni's gradio demo of PySceneDetect. <br />Automatically find every shots in a video sequence</p><p style='text-align: center'> 1. gives you timecode in/out for each shot. 2. saves each shot as a splitted mp4 video chunk for you to download. 3. diplays a thumbnail for each shot as a gallery output.<br /> <img id='visitor-badge' alt='visitor badge' src='https://visitor-badge.glitch.me/badge?page_id=gradio-blocks.scene-edit-detection' style='display: inline-block'/></b></p>"
16
- article = "<p style='text-align: center'><a href='http://scenedetect.com/en/latest/' target='_blank'>PySceneDetect website</a> | <a href='https://github.com/Breakthrough/PySceneDetect' target='_blank'>Github Repo</a></p>"
17
-
18
- # —————————————————————————————————————————————————
19
-
20
- # SET INPUTS
21
- video_input = gr.Video(source="upload", format="mp4", label="Video Sequence", mirror_webcam=False)
22
- threshold = gr.Slider(label="Threshold pixel comparison: if exceeded, triggers a scene cut. Default: 27.0", minimum=15.0, maximum=40.0, value=27.0)
23
-
24
- # —————————————————————————————————————————————————
25
 
26
  def convert_to_tuple(list):
27
  return tuple(list);
28
 
29
 
 
 
 
 
30
  def find_scenes(video_path, threshold):
31
  # file name without extension
32
  filename = os.path.splitext(os.path.basename(video_path))[0]
@@ -46,6 +37,8 @@ def find_scenes(video_path, threshold):
46
  #print(scene_list)
47
 
48
  timecodes = []
 
 
49
  timecodes.append({"title": filename + ".mp4", "fps": scene_list[0][0].get_framerate()})
50
 
51
  shots = []
@@ -125,6 +118,7 @@ def find_scenes(video_path, threshold):
125
  # return results
126
  return timecodes, shots, stills
127
 
 
128
  # —————————————————————————————————————————————————
129
 
130
  # SET DATA AND COMPONENTS OUTPUTS
@@ -147,8 +141,30 @@ gradio_components_outputs = []
147
 
148
  # ANOTHER SOLUTION WOULD BE USING A (FUTURE ?) "VIDEO GALLERY" GRADIO COMPONENT FROM LIST :)
149
 
150
- outputs = [gr.JSON(label="Shots detected"), gr.File(label="Downloadable Shots"), gr.Gallery(label="Still Images from each shot").style(grid=3)]
151
 
152
- # —————————————————————————————————————————————————
153
- print('Hello Sylvain')
154
- gr.Interface(fn=find_scenes, inputs=[video_input, threshold], outputs=outputs, title=title, description=description, article=article).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  def convert_to_tuple(list):
14
  return tuple(list);
15
 
16
 
17
+ def clear_app():
18
+ return None, 27, None, None, None
19
+
20
+
21
  def find_scenes(video_path, threshold):
22
  # file name without extension
23
  filename = os.path.splitext(os.path.basename(video_path))[0]
 
37
  #print(scene_list)
38
 
39
  timecodes = []
40
+ if not scene_list:
41
+ raise ValueError("There are no scenes detected in this video.")
42
  timecodes.append({"title": filename + ".mp4", "fps": scene_list[0][0].get_framerate()})
43
 
44
  shots = []
 
118
  # return results
119
  return timecodes, shots, stills
120
 
121
+
122
  # —————————————————————————————————————————————————
123
 
124
  # SET DATA AND COMPONENTS OUTPUTS
 
141
 
142
  # ANOTHER SOLUTION WOULD BE USING A (FUTURE ?) "VIDEO GALLERY" GRADIO COMPONENT FROM LIST :)
143
 
 
144
 
145
+
146
+ with gr.Blocks(gr.themes.Default()) as demo:
147
+ with gr.Column():
148
+ gr.Markdown("""
149
+ # Scene Edit Detection
150
+ Copy of @fffiloni's gradio demo of PySceneDetect.
151
+ Automatically find all the shots in a video sequence.
152
+ """)
153
+ with gr.Row():
154
+ with gr.Column():
155
+ video_input = gr.Video(sources="upload", format="mp4", label="Video Sequence", mirror_webcam = False)
156
+ threshold = gr.Slider(label="Threshold pixel comparison: if exceeded, triggers a scene cut. Default: 27.0", minimum=15.0, maximum=40.0, value=27.0)
157
+ with gr.Row():
158
+ clear_button = gr.Button(value=("Clear"))
159
+ run_button = gr.Button(value = "Submit", variant = "primary")
160
+
161
+
162
+ with gr.Column():
163
+ json_output = gr.JSON(label="Shots detected")
164
+ file_output = gr.File(label="Downloadable Shots")
165
+ gallery_output = gr.Gallery(label="Still Images from each shot")
166
+
167
+ run_button.click(fn=find_scenes, inputs=[video_input, threshold], outputs=[json_output, file_output, gallery_output])
168
+ clear_button.click(fn=clear_app, outputs=[video_input, threshold, json_output, file_output, gallery_output])
169
+ if __name__ == "__main__":
170
+ demo.launch(debug=True)